Example #1
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;
}
void Commands::removeThing(Player* player, const std::string& cmd, const std::string& param)
{
	Position pos = player->getPosition();
	pos = getNextPosition(player->direction, pos);
	Tile* removeTile = g_game.getMap()->getTile(pos);
	if (!removeTile) {
		player->sendTextMessage(MSG_STATUS_SMALL, "Tile not found.");
		g_game.addMagicEffect(pos, NM_ME_POFF);
		return;
	}

	Thing* thing = removeTile->getTopVisibleThing(player);
	if (!thing) {
		player->sendTextMessage(MSG_STATUS_SMALL, "Object not found.");
		g_game.addMagicEffect(pos, NM_ME_POFF);
		return;
	}

	if (Creature* creature = thing->getCreature()) {
		g_game.removeCreature(creature, true);
	} else {
		Item* item = thing->getItem();
		if (item) {
			if (item->isGroundTile()) {
				player->sendTextMessage(MSG_STATUS_SMALL, "You may not remove a ground tile.");
				g_game.addMagicEffect(pos, NM_ME_POFF);
				return;
			}

			g_game.internalRemoveItem(item, std::max<int32_t>(1, std::min<int32_t>(atoi(param.c_str()), item->getItemCount())));
			g_game.addMagicEffect(pos, NM_ME_MAGIC_BLOOD);
		}
	}
}
Example #3
0
int NpcScriptInterface::luagetDistanceTo(lua_State* L)
{
    //getDistanceTo(uid)
    ScriptEnvironment* env = getScriptEnv();

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

    uint32_t uid = getNumber<uint32_t>(L, -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;
}
Example #4
0
void WebThings::collect_garbage()
{
    if (stale_count) {
        // mark all nodes reachable from the roots
        for (Thing *t = things; t; t = (Thing *)t->next)
            t->reachable(gc_phase);
/*
        for (Proxy *proxy = proxies; proxy; proxy = (Proxy *)proxy->next) {
            reachable(proxy->properties);
            reachable(proxy->proxies);
        }
*/

        // now sweep through the nodes reachable from the stale list
        // and delete the ones that aren't reachable from the roots
        for (unsigned int i = 0; i < stale_count; ++i) {
            JSON *json = get_json(stale[i]);
        
            if (!json->marked(gc_phase)) {
                json->sweep(gc_phase);
                for (unsigned int j = i; j < stale_count - 1; ++j)
                    stale[j] = stale[j+1];
                --stale_count;
            }
        }
        
        gc_phase = !gc_phase;
        JSON::set_gc_phase(gc_phase); // to ensure new nodes are marked correctly
    }
}
Example #5
0
// -------------------------------------------------------------
//  Main Program
// -------------------------------------------------------------
int
main(int argc, char **argv)
{
  Thing thing;
  thing.message();
  return 0;
}
Example #6
0
uint32_t MoveEvents::onCreatureMove(Creature* creature, Tile* tile, bool isIn)
{
	MoveEvent_t eventType;
	if(isIn){
		eventType = MOVE_EVENT_STEP_IN;
	}
	else{
		eventType = MOVE_EVENT_STEP_OUT;
	}

	uint32_t ret = 1;
	MoveEvent* moveEvent = getEvent(tile, eventType);
	if(moveEvent){
		ret = ret & moveEvent->fireStepEvent(creature, NULL, tile->getPosition());
	}

	int32_t j = tile->__getLastIndex();
	Item* tileItem = NULL;
	for(int32_t i = tile->__getFirstIndex(); i < j; ++i){
		Thing* thing = tile->__getThing(i);
		if(thing && (tileItem = thing->getItem())){
			moveEvent = getEvent(tileItem, eventType);
			if(moveEvent){
				ret = ret & moveEvent->fireStepEvent(creature, tileItem, tile->getPosition());
			}
		}
	}
	return ret;
}
Example #7
0
void Kernel::handleMotionNotify(XMotionEvent *event) {

    Menu *menu = menuWindow(event->window);
    if (menu) {
        menu->handleMotionNotify(event);
    }

    Bar *bar = barWindow(event->window);
    if (bar) {
        bar->handleMotionNotify(event);
        return;
    }

    Thing *thing = thingWindow(event->window);
    if (thing) {
        if (!thing->isFocused() && isSloppyMode_) {
            Workspace *workspace = focusedMonitor()->focused();
            workspace->focus(thing, false);
        }
        thing->handleMotionNotify(event);
    }

    // focusses the monitor if multihead
    isRootWindow(event->root);
}
Example #8
0
uint32_t MoveEvents::onCreatureMove(Creature* creature, const Tile* tile, bool isIn)
{
	MoveEvent_t eventType;

	if (isIn) {
		eventType = MOVE_EVENT_STEP_IN;
	} else {
		eventType = MOVE_EVENT_STEP_OUT;
	}

	Position pos = tile->getPosition();

	uint32_t ret = 1;

	MoveEvent* moveEvent = getEvent(tile, eventType);
	if (moveEvent) {
		ret = ret & moveEvent->fireStepEvent(creature, nullptr, pos);
	}

	for (int32_t i = tile->__getFirstIndex(), j = tile->__getLastIndex(); i < j; ++i) {
		Thing* thing = tile->__getThing(i);
		if (thing) {
			Item* tileItem = thing->getItem();
			if (tileItem) {
				moveEvent = getEvent(tileItem, eventType);
				if (moveEvent) {
					ret = ret & moveEvent->fireStepEvent(creature, tileItem, pos);
				}
			}
		}
	}

	return ret;
}
Example #9
0
   int LuaThing::getAliases(lua_State *L) {

      int n = lua_gettop(L);

      if (1 != n) {
         return luaL_error(L, "takes no arguments");
      }

      Thing *t = checkThing(L, -1);

      if (0 == t) {
         return luaL_error(L, "not a Thing!");
      }

      LuaArray luaAliases;
      vector<string> aliases = t->getAliases();

      for (vector<string>::const_iterator i = aliases.begin(); i != aliases.end(); i++) {

         LuaValue v;

         v.type = LUA_TYPE_STRING;
         v.value = *i;

         luaAliases.insert(luaAliases.end(), v);
      }

      LuaState::pushArray(L, luaAliases);
      return 1;
   }
Example #10
0
uint32_t MoveEvents::onCreatureMove(Creature* creature, const Tile* tile, const Position& fromPos, MoveEvent_t eventType)
{
	const Position& pos = tile->getPosition();

	uint32_t ret = 1;

	MoveEvent* moveEvent = getEvent(tile, eventType);
	if (moveEvent) {
		ret &= moveEvent->fireStepEvent(creature, nullptr, pos, fromPos);
	}

	for (size_t i = tile->getFirstIndex(), j = tile->getLastIndex(); i < j; ++i) {
		Thing* thing = tile->getThing(i);
		if (!thing) {
			continue;
		}

		Item* tileItem = thing->getItem();
		if (!tileItem) {
			continue;
		}

		moveEvent = getEvent(tileItem, eventType);
		if (moveEvent) {
			ret &= moveEvent->fireStepEvent(creature, tileItem, pos, fromPos);
		}
	}
	return ret;
}
void * MultiLockUnsafeThread( void * p )
{

    const unsigned int value = reinterpret_cast< unsigned int >( p );
    Thing * thing = nullptr;
    unsigned int jj = 0;
    unsigned int tests = 0;
    unsigned int fails = 0;
    unsigned int randomIndex = 0;
    try
    {
        for ( unsigned int ii = 0; ii < thingCount; ++ii )
        {
            for ( jj = 0; jj < thingCount; ++jj )
            {
                thing = const_cast< Thing * >( Thing::GetFromPool( jj ) );
                assert( nullptr != thing );
                thing->SetValue( value );
            }
            ::GoToSleep( 2 );

            if ( WillRedoSingleTests() )
            {
                SingleThreadSimpleTest();
                SingleThreadReentrantTest();
                SingleThreadSimpleMultiLockTest();
                SingleThreadComplexMultiLockTest( false );
                SingleThreadExceptionTest();
            }

            thing = const_cast< Thing * >( Thing::GetFromPool( ii ) );
            assert( nullptr != thing );
            thing->Print( value, ii, 7 );
            randomIndex = ( ::rand() % thingCount );
            thing = const_cast< Thing * >( Thing::GetFromPool( randomIndex ) );
            assert( nullptr != thing );
            thing->Print( value, ii, 7 );

            for ( jj = 0; jj < thingCount; ++jj )
            {
                thing = const_cast< Thing * >( Thing::GetFromPool( jj ) );
                assert( nullptr != thing );
                if ( thing->GetValue() != value )
                    fails++;
                tests++;
            }

            ::GoToSleep( 2 );
        }
    }
    catch ( ... )
    {
        assert( false );
    }

    TestResults::GetIt()->SetResult( value, tests, fails );

    return nullptr;
}
Example #12
0
Container* Container::getParentContainer()
{
	Thing* thing = getParent();
	if (!thing) {
		return nullptr;
	}
	return thing->getContainer();
}
Example #13
0
Container* Container::getParentContainer()
{
	Thing* thing = getParent();
	if (thing) {
		return thing->getContainer();
	}
	return NULL;
}
Example #14
0
Cylinder* Tile::__queryDestination(int32_t& index, const Thing* thing, Item** destItem,
	uint32_t& flags)
{
	Tile* destTile = NULL;
	*destItem = NULL;

	if(floorChangeDown()){
		int dx = getTilePosition().x;
		int dy = getTilePosition().y;
		int dz = getTilePosition().z + 1;
		Tile* downTile = g_game.getTile(dx, dy, dz);

		if(downTile){
			if(downTile->floorChange(NORTH))
				dy += 1;
			if(downTile->floorChange(SOUTH))
				dy -= 1;
			if(downTile->floorChange(EAST))
				dx -= 1;
			if(downTile->floorChange(WEST))
				dx += 1;
			destTile = g_game.getTile(dx, dy, dz);
		}
	}
	else if(floorChange()){
		int dx = getTilePosition().x;
		int dy = getTilePosition().y;
		int dz = getTilePosition().z - 1;

		if(floorChange(NORTH))
			dy -= 1;
		if(floorChange(SOUTH))
			dy += 1;
		if(floorChange(EAST))
			dx += 1;
		if(floorChange(WEST))
			dx -= 1;
		destTile = g_game.getTile(dx, dy, dz);
	}


	if(destTile == NULL){
		destTile = this;
	}
	else{
		flags |= FLAG_NOLIMIT; //Will ignore that there is blocking items/creatures
	}

	if(destTile){
		Thing* destThing = destTile->getTopDownItem();
		if(destThing)
			*destItem = destThing->getItem();
	}

	return destTile;
}
Example #15
0
bool Thing::collidesWith(Thing &thing)
{
	if(this->hp == 0 || thing.hp == 0)
		return false;
	
	return this->_collissionCheck(
		this->x, this->y, this->x + this->width(), this->y + this->height(),
		thing.x, thing.y, thing.x + thing.width(), thing.y + thing.height()
	);
}
void * MultiLockRandomUnsafeThread( void * p )
{
    const unsigned int value = reinterpret_cast< unsigned int >( p );
    unsigned int testCount = 0;
    unsigned int failCount = 0;
    Thing * thing = nullptr;
    UnsafeThingPool pool;

    unsigned int jj = 0;
    unsigned int place = 0;
    try
    {
        for ( unsigned int ii = 0; ii < thingCount; ++ii )
        {

            pool.clear();
            pool.reserve( thingCount );
            for ( place = 0; place < thingCount; ++place )
            {
                place += ::rand() % 3;
                if ( thingCount <= place )
                    break;
                thing = const_cast< Thing * >( Thing::GetFromPool( place ) );
                assert( nullptr != thing );
                pool.push_back( thing );
            }
            const unsigned int poolCount = pool.size();

            for ( jj = 0; jj < poolCount; ++jj )
            {
                thing = pool[ jj ];
                assert( nullptr != thing );
                thing->SetValue( value );
            }
            ::GoToSleep( 3 );

            for ( jj = 0; jj < poolCount; ++jj )
            {
                thing = pool[ jj ];
                assert( nullptr != thing );
                if ( thing->GetValue() != value )
                    failCount++;
                testCount++;
            }
        }
    }
    catch ( ... )
    {
        assert( false );
    }

    TestResults::GetIt()->SetResult( value, testCount, failCount );

    return nullptr;
}
Example #17
0
int Structure::Place(Cell *targ)  {
  int alt=-100000, malt = 0;
  if(stgr[struct_type][material][2][0][0] == NULL)  return 0;
  switch(struct_type)  {
    case(STRUCT_RAMP):
    case(STRUCT_WALL):  {
      if(targ->Terrain() ==TERRAIN_LOWWATER || targ->Terrain() ==TERRAIN_WATER
	|| targ->Terrain() == TERRAIN_OCEAN) return 0;
      }break;
    case(STRUCT_BRIDGE):  {
      int ctr;
      flying = 1;
      for(ctr=0; ctr<12 && alt<=-100000; ctr+=2)  {
	Thing *tmpt = targ->Next(ctr)->Inside(0);
	while(tmpt != NULL)  {
	  if(tmpt->Type() == THING_STRUCT &&
		((Structure*)tmpt)->StructType() == STRUCT_BRIDGE)  {
	    alt = ((Structure*)tmpt)->altitude;
//	    printf("Set relative bridge alt to %d.\r\n", alt);
	    }
	  tmpt = tmpt->Inside(0);
	  }
	}
      if(alt <= -100000 && targ->Terrain() !=TERRAIN_LOWWATER
		&& targ->Terrain() !=TERRAIN_WATER
		&& targ->Terrain() != TERRAIN_OCEAN)  {
	Thing *tmpt = targ;
	while(tmpt->Inside(0) != NULL)  tmpt = tmpt->Inside(0);
	if(tmpt->Type() == THING_CELL || tmpt->Type() == THING_STRUCT)  {
	  alt = tmpt->Height();
	  break;
	  }
	return 0;
	}
      if(alt <= -100000) return 0;
      }break;
    }
  if(alt <= -100000) alt = targ->Height();
  else malt = alt-targ->Height();
  if(malt < 0) return 0;

//  printf("Attempting to claim for struct!\r\n");
  if(!(targ->Claim(this, alt, height, 0, malt)))  return 0;
//  printf("Attempting to enter for struct!\r\n");
  if(!(targ->Enter(this, alt, height, 0, malt)))  {
    targ->UnClaim(this);
    return 0;
    }
//  printf("Success!\r\n");
  targ->UnClaim(this);
  location[0] = targ;
  Changed[thingnum] = 1;
  if(struct_type == STRUCT_BRIDGE)  {
    altitude = alt;
//    printf("Placing Struct at altitude %d\r\n", altitude);
    }
  InitNeighbors();
  return 1;
  }
Example #18
0
Thing* Thing::create(ThingType type)
{
	Thing* thing = new Thing(type);
	if(thing && thing->init())
	{
		thing->autorelease();
		return thing;
	}
	CC_SAFE_DELETE(thing);
	return nullptr;
}
Example #19
0
   void LookAction::execute(Player *player, Command *command, Game *game) {

      string object = command->getDirectObject();

      if (object.length() == 0) {
         object = command->getIndirectObject();
      }

      if (object.length() == 0) {
         player->getLocation()->observe(player, true, true);
      }

      else {

         Place *location = player->getLocation();

         // Note: I can't use list.merge(), because ObjectList and ThingList are
         // of different types :'(
         ThingList items;

         // consider matching inventory items, if there are any
         ObjectListCItPair invItems = player->getInventoryObjectsByName(object);
         for (ObjectListCIt i = invItems.begin; i != invItems.end; i++) {
               items.push_front(*i);
         }

         // also consider matching items in the room, if there are any
         ThingListCItPair roomItems = location->getThingsByName(object);
         for (ThingListCIt i = roomItems.begin; i != roomItems.end; i++) {
            items.push_front(*i);
         }

         if (0 == items.size()) {
            player->out("display") << "There is no " << object << " here!" << endl;
            return;
         }

         ThingListCItPair itemsIt;
         itemsIt.begin = items.begin();
         itemsIt.end   = items.end();

         try {
            Thing *thing =
               Entity::clarifyEntity<ThingListCItPair, ThingListCIt, Thing *>(itemsIt,
               player);
            thing->observe(player, true, true);
         }

         catch (string name) {
            player->out("display") << "There is no " << name << " here!" << endl;
         }
      }
   }
Example #20
0
void Container::RebuildCounts() {

    Thing *t;
    for (unsigned int i = 0 ; i < capacity ; i++ ) {
        containeritemdata_t *c = (containeritemdata_t*)objects[i]->GetCustomData();
        if (c->container->GetItem(c->elementid) && (t = c->container->GetItem(c->elementid))->IsStackable()) {
            char tmp[20];
            sprintf(tmp, "%dx", t->GetCount());
            objects[i]->SetCaption(tmp);
        } else objects[i]->SetCaption("");
    }
}
Example #21
0
void Structure::FigureNeighbors()  {
  int ctr, tmpn = neighbors;
  neighbors = 0;
  for(ctr=0; ctr<12; ctr+=2)  {
    Cell *tmpc = Location(0)->Location(0);
    tmpc = tmpc->Next(ctr);
    if(tmpc != NULL)  {
      Thing *tmpt = tmpc->Inside(0);
      if(tmpt != NULL && tmpt->Type() == THING_STRUCT
	  && ((Structure*)tmpt)->StructType() == STRUCT_WALL)  {
	neighbors += 1<<(ctr>>1);
	}
      }
Example #22
0
int main(int argc) {
  Thing *one = getThing(false);
  Thing *two = getThing(true);

  int x = one->getX() + two->getX();
  assert(x==3);

  delete two;
  delete one;
  
  assert(decon==2);

  return 0;
}
Example #23
0
void Kernel::handleButtonRelease(XButtonEvent *event) {

    event->state &= Binder::instance()->validModMask();

    Bar *bar = barWindow(event->window);
    if (bar) {
        bar->handleButtonRelease(event);
        return;
    }

    Thing *thing = thingWindow(event->window);
    if (thing) {
        thing->handleButtonRelease(event);
    }
}
Example #24
0
ThingView::ThingView(const Thing& thing, QGraphicsItem *parent) :
        QGraphicsPolygonItem(parent)
{
    /* colorize! */
    setAppearanceDependingOnID(thing.id());

    /* we need the body only to connect to it. no reference is stored. */
    connect(&thing, SIGNAL(changedPosition(QTransform)), this, SLOT(bodyChanged(QTransform)));

    /* initially set our location parameters */
    bodyChanged(thing.getWorldMap());

    /* adept our model's shape */
    setPolygon(thing.shape());
}
void AppClass::
list()
{
	Thing *theThing;
	ArrayItr *theItr = new ArrayItr(testArray,testArray->getSize() );
	int i = 0;
	bool result = theItr->getNext(theThing);
	while(result)
	{
		cout << i+1 << ":ID = " << theThing->getID() 
			 <<" Name = " << theThing->getName() << "." <<endl;
		result = theItr->getNext(theThing);
		i++;
	}
}
Example #26
0
Cylinder* Container::__queryDestination(int32_t& index, const Thing* thing, Item** destItem,
	uint32_t& flags)
{
	if(index == 254 /*move up*/){
		index = INDEX_WHEREEVER;
		*destItem = NULL;
		
		Container* parentContainer = dynamic_cast<Container*>(getParent());
		if(parentContainer)
			return parentContainer;
		else
			return this;
	}
	else if(index == 255 /*add wherever*/){
		index = INDEX_WHEREEVER;
		*destItem = NULL;
		return this;
	}
	else{
		if(index >= (int32_t)capacity()){
			/*
			if you have a container, maximize it to show all 20 slots
			then you open a bag that is inside the container you will have a bag with 8 slots
			and a "grey" area where the other 12 slots where from the container
			if you drop the item on that grey area
			the client calculates the slot position as if the bag has 20 slots
			*/

			index = INDEX_WHEREEVER;
		}

		if(index != INDEX_WHEREEVER){
			Thing* destThing = __getThing(index);
			if(destThing)
				*destItem = destThing->getItem();

			Cylinder* subCylinder = dynamic_cast<Cylinder*>(*destItem);

			if(subCylinder){
				index = INDEX_WHEREEVER;
				*destItem = NULL;
				return subCylinder;
			}
		}
	}
	
	return this;
}
Example #27
0
 ~Thing() {
   HAZPTR_DEBUG_PRINT(
       "this: " << this << " val: " << val << " next: " << next);
   if (next) {
     next->retire(*domain);
   }
 }
Example #28
0
ReturnValue DepotChest::queryAdd(int32_t index, const Thing& thing, uint32_t count,
		uint32_t flags, Creature* actor/* = nullptr*/) const
{
	const Item* item = thing.getItem();
	if (item == nullptr) {
		return RETURNVALUE_NOTPOSSIBLE;
	}

	bool skipLimit = hasBitSet(FLAG_NOLIMIT, flags);
	if (!skipLimit) {
		int32_t addCount = 0;

		if ((item->isStackable() && item->getItemCount() != count)) {
			addCount = 1;
		}

		if (item->getTopParent() != this) {
			if (const Container* container = item->getContainer()) {
				addCount = container->getItemHoldingCount() + 1;
			} else {
				addCount = 1;
			}
		}

		if (getItemHoldingCount() + addCount > maxDepotItems) {
			return RETURNVALUE_DEPOTISFULL;
		}
	}

	return Container::queryAdd(index, thing, count, flags, actor);
}
void ThingupdatePropertiestest::setup()
{
    m_name = new Property<std::string>(flag_unsent);
    m_name->data() = testName;

    m_thing = new Thing("1", 1);
    m_thing->setProperty("name", m_name);
}
Example #30
0
   int LuaThing::clearLocation(lua_State *L) {

      int n = lua_gettop(L);

      if (1 != n) {
         return luaL_error(L, "takes no arguments");
      }

      Thing *t = checkThing(L, -1);

      if (0 == t) {
         return luaL_error(L, "not a Thing!");
      }

      t->setLocation(0);
      return 1;
   }