Esempio n. 1
0
int NpcScriptInterface::luaActionSay(lua_State* L)
{
	//selfSay(words [[, target], send_to_all])
	    // send_to_all defaults to true if there is no target, false otherwise
	uint32_t parameters = lua_gettop(L);
	uint32_t target = 0;
	bool send_to_all = true;
	
	if(parameters == 3)
	{
		send_to_all = (popNumber(L) == LUA_TRUE);
		target = popNumber(L);
	}
	else if(parameters == 2)
	{
		target = popNumber(L);
		send_to_all = false;
	}
	std::string msg(popString(L));
	
	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	Player* focus = env->getPlayerByUID(target);
	if(npc){
		npc->doSay(msg, focus, send_to_all);
	}

	return 0;
}
Esempio n. 2
0
int32_t NpcScriptInterface::luaActionSay(lua_State* L)
{
	//selfSay(words [[, target], publicize])
	// publicize defaults to true if there is no target, false otherwise
	uint32_t parameters = lua_gettop(L);
	uint32_t target = 0;
	bool publicize = true;

	if (parameters >= 3) {
		publicize = (popNumber(L) == 1);
	}

	if (parameters >= 2) {
		target = popNumber(L);
		if (target != 0) {
			publicize = false;
		}
	}

	std::string text = popString(L);

	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		if (publicize) {
			npc->doSay(text);
		} else {
			npc->doSayToPlayer(g_game.getPlayerByID(target), text);
		}
	}

	return 0;
}
Esempio n. 3
0
/* numberRangeCompare: range test for case */
void numberRangeCompare()
{
    Number  high, low, n;

    high = popNumber();
    low = popNumber();
    n = stack[tos].value.number;

    pushNumber( n >= low && n <= high );
}
Esempio n. 4
0
int32_t NpcScriptInterface::luaActionMoveTo(lua_State* L)
{
	//selfMoveTo(x,y,z)
	Position target;
	target.z = (int32_t)popNumber(L);
	target.y = (int32_t)popNumber(L);
	target.x = (int32_t)popNumber(L);

	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		npc->doMoveTo(target);
	}

	return 0;
}
Esempio n. 5
0
int NpcScriptInterface::luaCloseShop(lua_State *L)
{
	//closeShopWindow(cid)
	ScriptEnviroment* env = getScriptEnv();
	Npc* npc = env->getNpc();
	Player* player = env->getPlayerByUID(popNumber(L));

	int32_t buyCallback;
	int32_t sellCallback;

	if(player == NULL) {
		reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
		lua_pushnumber(L, LUA_ERROR);
		return 1;
	}

	player->sendCloseShop();
	player->getShopOwner(buyCallback, sellCallback);
	if(buyCallback != -1)
		luaL_unref(L, LUA_REGISTRYINDEX, buyCallback);
	if(sellCallback != -1)
		luaL_unref(L, LUA_REGISTRYINDEX, sellCallback);
	player->setShopOwner(NULL, -1, -1);

	return 1;
}
Esempio n. 6
0
int NpcScriptInterface::luagetDistanceTo(lua_State *L)
{
	//getDistanceTo(uid)
	uint32_t uid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	Thing* thing = env->getThingByUID(uid);
	if(thing && npc){
		Position thing_pos = thing->getPosition();
		Position npc_pos = npc->getPosition();
		if(npc_pos.z != thing_pos.z){
			lua_pushnumber(L, -1);
		}
		else{
			int32_t dist = std::max(std::abs(npc_pos.x - thing_pos.x), std::abs(npc_pos.y - thing_pos.y));
			lua_pushnumber(L, dist);
		}
	}
	else{
		reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
		lua_pushnil(L);
	}

	return 1;
}
Esempio n. 7
0
int NpcScriptInterface::luaCreatureGetPos(lua_State *L)
{
/*/    
	//creatureGetPosition(cid)
	popNumber(L);
	reportErrorFunc("Deprecated function. Use getCreaturePosition");
/*/
   uint32_t uid = popNumber(L);
   ScriptEnviroment* env = getScriptEnv();
   Creature* creature = env->getCreatureByUID(uid);
   
   if(creature){   
                  Position pos = creature->getPosition();   
                  lua_pushnumber(L, pos.x);   
                  lua_pushnumber(L, pos.y);   
                  lua_pushnumber(L, pos.z);   
          }   
          else{   
        reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); 
		lua_pushnil(L);
		lua_pushnil(L);
		lua_pushnil(L);
    }
	return 3;
}
Esempio n. 8
0
int32_t NpcScriptInterface::luagetDistanceTo(lua_State* L)
{
	//getDistanceTo(uid)
	uint32_t uid = popNumber(L);

	ScriptEnvironment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (!npc) {
		reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
		lua_pushnil(L);
		return 1;
	}

	Thing* thing = env->getThingByUID(uid);
	if (!thing) {
		reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
		lua_pushnil(L);
		return 1;
	}

	const Position& thingPos = thing->getPosition();
	const Position& npcPos = npc->getPosition();
	if (npcPos.z != thingPos.z) {
		lua_pushnumber(L, -1);
	} else {
		int32_t dist = std::max<int32_t>(Position::getDistanceX(npcPos, thingPos), Position::getDistanceY(npcPos, thingPos));
		lua_pushnumber(L, dist);
	}
	return 1;
}
Esempio n. 9
0
int NpcScriptInterface::luaCreatureGetName(lua_State *L)
{
	//creatureGetName(cid)
	popNumber(L);
	reportErrorFunc("Deprecated function. Use getCreatureName");
	lua_pushstring(L, "");
	return 1;
}
Esempio n. 10
0
/* buildKey: build key from stack data */
char *buildKey( Array *array, Symbol *s )
{
    int     args, i, keylen;
    char    *index, *buffer;

/* FIX: should eventually just realloc when size is exceeded */

    /* create a buffer */
    buffer = (char *)eMalloc( 256 );
    buffer[0] = '\0';

    /* check arg count */
    args = (int)popNumber();

    /* there must be at least one index */
    if (args == 0) {
        ePrintf( Runtime, "Array %s[]x expects at least 1 index, not 0" );
    }

    /* build the key backwards, for speed */
    keylen = 0;
    for ( i = 1; i <= args; i++ ) {

        /* get index */
        index = popString();

        /* make sure it fits in the buffer */
        keylen += strlen( index );
        if (keylen >= 256) {
            ePrintf( Runtime, "Array key exceeds 256 characters" );
        }

        /* append to key */
        strcat( buffer, index );

	/*
	ivanixcu: debug
	need free allocated memory of index!
	printf("ivanixdebug: freeing (index) (%d)\n", *index );
	*/
	if (*index != '\0' ){
	    eFree( index );
	}

        if (i < args) {
            /* add delimiter */
            keylen += 1;
            if (keylen >= 256) {
                ePrintf( Runtime, "Array key exceeds 256 characters" );
            }
            /* replace with ASCII 34 eventually */
            strcat( buffer, "," );
        }
    }

    /* resize the buffer */
    return (char *)eRealloc( buffer, keylen+1 );
}
Esempio n. 11
0
//seekmpeg(p)				: Seek 'bytes' bytes in the MPEG stream
void basSeekMpeg()
{
    int p;
    int ret;
    p=popNumber();
    ret=seekmpeg(p);
    if (ret==-1) ePrintf( Runtime, "SDLengine Error \n");
    pushNumber(ret);
}
Esempio n. 12
0
//skipmpeg(s)				: Skip 'seconds' seconds in the MPEG stream
void basSkipMpeg()
{
    double p;
    int ret;
    p=popNumber();
    ret=skipmpeg(p);
    if (ret==-1) ePrintf( Runtime, "SDLengine Error \n");
    pushNumber(ret);
}
Esempio n. 13
0
int32_t NpcScriptInterface::luaActionTurn(lua_State* L)
{
	//selfTurn(direction)
	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		npc->doTurn((Direction)popNumber(L));
	}
	return 0;
}
Esempio n. 14
0
int32_t NpcScriptInterface::luaSetNpcFocus(lua_State* L)
{
	//doNpcSetCreatureFocus(cid)
	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		npc->setCreatureFocus(g_game.getCreatureByID(popNumber(L)));
	}
	return 0;
}
Esempio n. 15
0
int NpcScriptInterface::luaCreatureGetPos(lua_State *L)
{
	//creatureGetPosition(cid)
	popNumber(L);
	reportErrorFunc("Deprecated function. Use getCreaturePosition");
	lua_pushnil(L);
	lua_pushnil(L);
	lua_pushnil(L);
	return 3;
}
Esempio n. 16
0
/* numberCompare: compare two numbers on the stack */
void numberCompare( int op, int popFlag )
{
    Number  n1, n2;

    n2 = popNumber();
    if (popFlag) {
        n1 = popNumber();
    } else {
        n1 = stack[tos].value.number;
    }

    switch (op) {

    case EQ:
        pushNumber( abs(n1 - n2) <= ALLOWABLE_ERROR );
        break;

    case NE:
        pushNumber( n1 != n2 );
        break;

    case GT:
        pushNumber( n1 > n2 );
        break;

    case LT:
        pushNumber( n1 < n2 );
        break;

    case GE:
        pushNumber( n1 >= n2 );
        break;

    case LE:
        pushNumber( n1 <= n2 );
        break;

    default:
        ePrintf( Runtime, "numberCompare: bad operator" );
    }
}
Esempio n. 17
0
int32_t NpcScriptInterface::luaActionMove(lua_State* L)
{
	//selfMove(direction)
	Direction dir = (Direction)popNumber(L);

	Npc* npc = getScriptEnv()->getNpc();
	if (npc) {
		npc->doMove(dir);
	}

	return 0;
}
Esempio n. 18
0
void basLoadMpeg()
{
    char *fname;
    int usesound;
    int ret;

    usesound=popNumber();
    fname=popString();

    ret=loadmpeg(fname,usesound);
    if (ret==-1) ePrintf( Runtime, "SDLengine Error \n");
    pushNumber(ret);
}
Esempio n. 19
0
int NpcScriptInterface::luaSetNpcFocus(lua_State *L)
{
	//doNpcSetCreatureFocus(cid)
	uint32_t cid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if(npc){
		Creature* creature = env->getCreatureByUID(cid);
		npc->setCreatureFocus(creature);
	}
	return 0;
}
Esempio n. 20
0
int32_t NpcScriptInterface::luaActionTurn(lua_State* L)
{
	//selfTurn(direction)
	Direction dir = (Direction)popNumber(L);

	ScriptEnvironment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (npc) {
		npc->doTurn(dir);
	}

	return 0;
}
Esempio n. 21
0
int32_t NpcScriptInterface::luaSetNpcFocus(lua_State* L)
{
	//doNpcSetCreatureFocus(cid)
	uint32_t cid = popNumber(L);

	ScriptEnvironment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (npc) {
		npc->setCreatureFocus(g_game.getCreatureByID(cid));
	}

	return 0;
}
Esempio n. 22
0
//plaympeg(optional loop)		: play a mpeg1 video
void basPlayMpeg()
{
    int loop;
    int ret;

    if (argCount==1)
	loop=popNumber();
    else
	loop=0;

    ret=plaympeg(loop);
    if (ret==-1) ePrintf( Runtime, "SDLengine Error \n");
    pushNumber(ret);
}
Esempio n. 23
0
/* getStaticIndex: get the address of the data element */
int getStaticIndex( Array *array, Symbol *s )
{
    int     offset;
    int     indexes;
    int     i;
    int     index;
    int     base;

    /* paranoia */
    eMemTest( "getStaticIndex: symbol", s );

    /* paranoia */
    eMemTest( "getStaticIndex: array", array );

    indexes = (int)popNumber();
    if (indexes != array->indexes) {
        ePrintf( Runtime, "getStaticIndex: array %s expects %d indexes, not %d",
            s->name, array->indexes, indexes );
    }

    offset = 0;
    for ( i=0; i<indexes; i++ ) {
        index = (int)popNumber();
        if (index > array->upper[i]) {
            ePrintf( Runtime, "getStaticIndex: index %d of array %s above upper bounds (%d>%d)",
                i+1, s->name, index, array->upper[i] );

        } else if (index < array->lower[i]) {
            ePrintf( Runtime, "getStaticIndex: index %d of array %s under lower bounds (%d<%d)",
                i+1, s->name, index, array->lower[i] );
        }

        base = index-(array->lower[i]);
        offset += base * array->offset[i];
    }
    return offset;
}
Esempio n. 24
0
/* setArrayElement: set an item in the array */
void setArrayElement( Symbol *s )
{
    int     offset, type;
    Array   *array;
    Variant *element;

    eMemTest( "setArrayElement: symbol", s );

    array = getArray( s );
    eMemTest( "setArrayElement: array", array );

    if (array->isDynamic) {
        setDynamicValue( array, s );


    } else {

/* this should be implemented as a seperate routine */

        offset = getStaticIndex( array, s );
        element = array->data.item+offset;
        eMemTest( "setArrayElement: array element", element );


        /* need to free string? */
        if (element->datatype == DATA_STRING) {
            eFree( element->value.string );
        }

        /* get the tos */
        type = getStackType( tos );
        switch (type) {
        case DATA_NUMBER:
            element->datatype = DATA_NUMBER;
            element->value.number = popNumber();
            break;

        case DATA_STRING:
            element->datatype = DATA_STRING;
            element->value.string = popString();
            break;

        default:
            ePrintf( Runtime, "setArrayElement: can't store %s %s into Array",
                datumName[type], s->name );
            break;
        }
    }
}
Esempio n. 25
0
static void displayTrace(void)
{
	NumberList	**trace = NULL;
	int			address;
	MemCell		data;
	char		buff[201];

	trace = getTrace();
	while(popNumber(trace, &address) == ERR_None)
	{
		data = readMemory(address);
		sprintf(buff, "  [Memory] %010u:\t%d\n", address, data.getal);
		consoleOut(buff);
	}
}
Esempio n. 26
0
int NpcScriptInterface::luaFaceCreature(lua_State *L)
{
	// facePlayer(cid)
	uint32_t cid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (npc) {
		Creature* creature = env->getCreatureByUID(cid);
		if (creature) {
			g_game.internalCreatureTurn(npc, npc->getDir(creature));
		}
	}

	return 1;
}
Esempio n. 27
0
int NpcScriptInterface::luaUnqueuePlayer(lua_State *L)
{
	// unqueuePlayer(cid)
	uint32_t cid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (npc) {
		Creature* creature = env->getCreatureByUID(cid);
		if (creature) {
			npc->queueList.remove(cid);
		}
	}

	return 1;
}
Esempio n. 28
0
int32_t NpcScriptInterface::luaCloseShopWindow(lua_State* L)
{
	//closeShopWindow(cid)
	ScriptEnvironment* env = getScriptEnv();

	Player* player = g_game.getPlayerByID(popNumber(L));

	if (!player) {
		reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
		pushBoolean(L, false);
		return 1;
	}

	Npc* npc = env->getNpc();

	if (!npc) {
		reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
		pushBoolean(L, false);
		return 1;
	}

	int32_t buyCallback;
	int32_t sellCallback;

	Npc* merchant = player->getShopOwner(buyCallback, sellCallback);

	//Check if we actually have a shop window with this player.
	if (merchant == npc) {
		player->sendCloseShop();

		if (buyCallback != -1) {
			luaL_unref(L, LUA_REGISTRYINDEX, buyCallback);
		}

		if (sellCallback != -1) {
			luaL_unref(L, LUA_REGISTRYINDEX, sellCallback);
		}

		player->setShopOwner(NULL, -1, -1);
		npc->removeShopPlayer(player);
	}

	pushBoolean(L, true);
	return 1;
}
Esempio n. 29
0
int NpcScriptInterface::luaSetNpcFocus(lua_State* L)
{
	//setNpcFocus(cid)
	uint32_t cid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Npc* npc = env->getNpc();
	if (npc) {
		Creature* creature = env->getCreatureByUID(cid);
		if (creature) {
			npc->setCreatureFocus(creature);
		}
		else {
			npc->focusCreature = 0;
			npc->setWalkDelay(std::time(unsigned(NULL)) + 5);
		}
	}

	return 1;
}
Esempio n. 30
0
int32_t NpcScriptInterface::luaActionFollow(lua_State* L)
{
	//selfFollow(cid)
	uint32_t cid = popNumber(L);

	Player* player = g_game.getPlayerByID(cid);
	if (cid != 0 && !player) {
		pushBoolean(L, false);
		return 1;
	}

	Npc* npc = getScriptEnv()->getNpc();
	if (!npc) {
		pushBoolean(L, false);
		return 1;
	}

	bool result = npc->setFollowCreature(player, true);
	pushBoolean(L, result);
	return 1;
}