public static bool insert(Thing ptr) { //assert(!dbgLockObjects); MapComposite map=ptr.getMap(); //assert(map && map.isActive()); /* Non-visible objects have neither position nor public ID, so their insertion cannot fail. Take care of them first. */ if(!ptr.isVisible()) { map.insert(ptr); ptr.inserted(); return true; } // Check that coordinates are actually valid. Actor obj=(Actor)ptr; Map mp=map.getMap(); Point pos=obj.getPosition(); if((int)pos.x/mp.getTileWidth()>=mp.getWidth()|| (int)pos.y/mp.getTileHeight()>=mp.getHeight()) { Logger.Write(LogLevel.Error, "Tried to insert an actor at position {0}, {1} outside map {2}.", pos.x, pos.y, map.getID()); // Set an arbitrary small position. pos=new Point(100, 100); obj.setPosition(pos); } if(!map.insert(obj)) { // The map is overloaded, no room to add a new actor Logger.Write(LogLevel.Error, "Too many actors on map {0}.", map.getID()); return false; } obj.inserted(); // DEBUG INFO //TODO Implementieren // switch(obj.getType()) // { // case ThingType.OBJECT_ITEM: // Logger.Write(LogLevel.Debug, "Item inserted: " // (Item)(obj).getItemClass().getDatabaseID()); // break; // // case ThingType.OBJECT_NPC: // Logger.Write(LogLevel.Debug, "NPC inserted: "<<static_cast<NPC*>(obj).getNPC()); // break; // // case ThingType.OBJECT_CHARACTER: // Logger.Write(LogLevel.Debug, "Player inserted: " // <<static_cast<Being*>(obj).getName()); // break; // // case ThingType.OBJECT_EFFECT: // Logger.Write(LogLevel.Debug, "Effect inserted: " // <<static_cast<Effect*>(obj).getEffectId()); // break; // // case ThingType.OBJECT_MONSTER: // Logger.Write(LogLevel.Debug, "Monster inserted: " // <<static_cast<Monster*>(obj).getSpecy().getId()); // break; // // case ThingType.OBJECT_ACTOR: // case ThingType.OBJECT_OTHER: // default: // Logger.Write(LogLevel.Debug, "Thing inserted: "<<obj.getType()); // } obj.raiseUpdateFlags((byte)UpdateFlag.UPDATEFLAG_NEW_ON_MAP); if(obj.getType()!=ThingType.OBJECT_CHARACTER) return true; /* Since the player does not know yet where in the world its character is, we send a map-change message, even if it is the first time it connects to this server. */ MessageOut mapChangeMessage=new MessageOut(Protocol.GPMSG_PLAYER_MAP_CHANGE); mapChangeMessage.writeString(map.getName()); mapChangeMessage.writeInt16(pos.x); mapChangeMessage.writeInt16(pos.y); Program.gameHandler.sendTo((Character)(obj), mapChangeMessage); // update the online state of the character Program.accountHandler.updateOnlineStatus(((Character)obj).getDatabaseID(), true); return true; }
public static bool insertOrDelete(Thing ptr) { //if (insert(ptr)) return true; //delete ptr; return false; }
public static void remove(Thing ptr) { //assert(!dbgLockObjects); //MapComposite *map = ptr.getMap(); //int visualRange = Configuration::getValue("game_visualRange", 448); //ptr.removed(); //// DEBUG INFO //switch (ptr.getType()) //{ // case OBJECT_ITEM: // LOG_DEBUG("Item removed: " // << static_cast<Item*>(ptr).getItemClass().getDatabaseID()); // break; // case OBJECT_NPC: // LOG_DEBUG("NPC removed: " << static_cast<NPC*>(ptr).getNPC()); // break; // case OBJECT_CHARACTER: // LOG_DEBUG("Player removed: " // << static_cast<Being*>(ptr).getName()); // break; // case OBJECT_EFFECT: // LOG_DEBUG("Effect removed: " // << static_cast<Effect*>(ptr).getEffectId()); // break; // case OBJECT_MONSTER: // LOG_DEBUG("Monster removed: " // << static_cast<Monster*>(ptr).getSpecy().getId()); // break; // case OBJECT_ACTOR: // case OBJECT_OTHER: // default: // LOG_DEBUG("Thing removed: " << ptr.getType()); //} //if (ptr.canMove()) //{ // if (ptr.getType() == OBJECT_CHARACTER) // { // static_cast< Character * >(ptr).cancelTransaction(); // // remove characters online status // accountHandler.updateOnlineStatus( // static_cast< Character * >(ptr).getDatabaseID(), false); // } // Actor *obj = static_cast< Actor * >(ptr); // MessageOut msg(GPMSG_BEING_LEAVE); // msg.writeInt16(obj.getPublicID()); // Point objectPos = obj.getPosition(); // for (CharacterIterator p(map.getAroundActorIterator(obj, visualRange)); // p; ++p) // { // if (*p != obj && objectPos.inRangeOf((*p).getPosition(), // visualRange)) // { // gameHandler.sendTo(*p, msg); // } // } //} //else if (ptr.getType() == OBJECT_ITEM) //{ // Item *obj = static_cast< Item * >(ptr); // Point pos = obj.getPosition(); // MessageOut msg(GPMSG_ITEMS); // msg.writeInt16(0); // msg.writeInt16(pos.x); // msg.writeInt16(pos.y); // for (CharacterIterator p(map.getAroundActorIterator(obj, visualRange)); p; ++p) // { // if (pos.inRangeOf((*p).getPosition(), visualRange)) // { // gameHandler.sendTo(*p, msg); // } // } //} //map.remove(ptr); }
void remove(Thing ptr) { //for (std::vector<Thing*>::iterator i = mContent.things.begin(), // i_end = mContent.things.end(); i != i_end; ++i) //{ // if ((*i).canFight()) // { // Being *being = static_cast<Being*>(*i); // if (being.getTarget() == ptr) // { // being.setTarget(NULL); // } // } // if (*i == ptr) // { // i = mContent.things.erase(i); // } //} //if (ptr.isVisible()) //{ // Actor *obj = static_cast< Actor * >(ptr); // mContent.getZone(obj.getPosition()).remove(obj); // if (ptr.canMove()) // { // mContent.deallocate(static_cast< Being * >(ptr)); // } //} }
bool insert(Thing ptr) { //if (ptr.isVisible()) //{ // if (ptr.canMove() && !mContent.allocate(static_cast< Being * >(ptr))) // { // return false; // } // Actor *obj = static_cast< Actor * >(ptr); // mContent.getZone(obj.getPosition()).insert(obj); //} //ptr.setMap(this); //mContent.things.push_back(ptr); return true; }
public bool insert(Thing ptr) { if(ptr.isVisible()) { if(ptr.canMove()&&!mContent.allocate((Being)ptr)) { return false; } Actor obj=(Actor)ptr; mContent.getZone(obj.getPosition()).insert(obj); } ptr.setMap(this); mContent.things.Add(ptr); return true; }
public void decrease(Thing t) { // --mNumBeings; // t->removeListener(&mSpawnedListener); }
static bool insert(Thing ptr) { //assert(!dbgLockObjects); //MapComposite *map = ptr.getMap(); //assert(map && map.isActive()); ///* Non-visible objects have neither position nor public ID, so their // insertion cannot fail. Take care of them first. */ //if (!ptr.isVisible()) //{ // map.insert(ptr); // ptr.inserted(); // return true; //} //// Check that coordinates are actually valid. //Actor *obj = static_cast< Actor * >(ptr); //Map *mp = map.getMap(); //Point pos = obj.getPosition(); //if ((int)pos.x / mp.getTileWidth() >= mp.getWidth() || // (int)pos.y / mp.getTileHeight() >= mp.getHeight()) //{ // LOG_ERROR("Tried to insert an actor at position " << pos.x << ',' // << pos.y << " outside map " << map.getID() << '.'); // // Set an arbitrary small position. // pos = Point(100, 100); // obj.setPosition(pos); //} //if (!map.insert(obj)) //{ // // The map is overloaded, no room to add a new actor // LOG_ERROR("Too many actors on map " << map.getID() << '.'); // return false; //} //obj.inserted(); //// DEBUG INFO //switch (obj.getType()) //{ // case OBJECT_ITEM: // LOG_DEBUG("Item inserted: " // << static_cast<Item*>(obj).getItemClass().getDatabaseID()); // break; // case OBJECT_NPC: // LOG_DEBUG("NPC inserted: " << static_cast<NPC*>(obj).getNPC()); // break; // case OBJECT_CHARACTER: // LOG_DEBUG("Player inserted: " // << static_cast<Being*>(obj).getName()); // break; // case OBJECT_EFFECT: // LOG_DEBUG("Effect inserted: " // << static_cast<Effect*>(obj).getEffectId()); // break; // case OBJECT_MONSTER: // LOG_DEBUG("Monster inserted: " // << static_cast<Monster*>(obj).getSpecy().getId()); // break; // case OBJECT_ACTOR: // case OBJECT_OTHER: // default: // LOG_DEBUG("Thing inserted: " << obj.getType()); //} //obj.raiseUpdateFlags(UPDATEFLAG_NEW_ON_MAP); //if (obj.getType() != OBJECT_CHARACTER) // return true; ///* Since the player does not know yet where in the world its character is, // we send a map-change message, even if it is the first time it // connects to this server. */ //MessageOut mapChangeMessage(GPMSG_PLAYER_MAP_CHANGE); //mapChangeMessage.writeString(map.getName()); //mapChangeMessage.writeInt16(pos.x); //mapChangeMessage.writeInt16(pos.y); //gameHandler.sendTo(static_cast< Character * >(obj), mapChangeMessage); //// update the online state of the character //accountHandler.updateOnlineStatus( // static_cast< Character * >(obj).getDatabaseID(), true); return true; }