void Editor::placeDoor() { if (choosing) return; if (door) door = NULL; removeThing(); door = new Door(curser->left(), curser->top(), row_w, col_h, m_UI->sprites); }
void Editor::placeHero() { if (choosing) return; if (hero) hero = NULL; removeThing(); hero = new Hero(curser->left(), curser->top(), row_w, col_h, m_UI->sprites); }
void Map::cleanDynamicThings() { for(const auto& pair : m_knownCreatures) { const CreaturePtr& creature = pair.second; removeThing(creature); } m_knownCreatures.clear(); for(int i=0;i<=Otc::MAX_Z;++i) m_floorMissiles[i].clear(); cleanTexts(); }
void Editor::moveCurser() { assert(curser); //place/choose/ delete if (hold_place && !Fl::event_key(' ')) { hold_place = false; } else if (hold_place) { handleSpace(); } else if (hold_del && !Fl::event_key(FL_Shift_L) && !Fl::event_key(FL_Shift_R)) { hold_del = false; } else if (hold_del) removeThing(); // skip some frames if (frame < 0) frame = FRAME_SKIP; else { frame--; return; } bool up, down, left, right; up = down = left = right = false; // move in x-dir if (hold_left && !Fl::event_key(FL_Left)) { hold_left = false; } else if (hold_left){ left = true; } else if (hold_right && !Fl::event_key(FL_Right)) { hold_right = false; } else if (hold_right) { right = true; } // move in y-dir if (hold_up && !Fl::event_key(FL_Up)) { hold_up = false; } else if (hold_up) { up = true; } else if (hold_down && !Fl::event_key(FL_Down)) hold_down = false; else if (hold_down) down = true; // set positions advancePosition(up, down, left, right); }
long Tile::clean() { if (house) return 0L; std::list<Item*> trash; for (int i = 0; i < getThingCount(); i++) { Item* item = dynamic_cast<Item*>(getThingByStackPos(i)); if (item && item->isPickupable() && !item->decoration) trash.push_back(item); } for (std::list<Item*>::iterator iter = trash.begin(); iter != trash.end(); ++iter) { Item* item = *iter; Container* container = dynamic_cast<Container*>(item); if (container) // check if anyone has this container opened and close it { AutoList<Player>::listiterator piter = Player::listPlayer.list.begin(); while (piter != Player::listPlayer.list.end()) // iterate players { Player* player = piter->second; containerLayout::const_iterator citer = player->getContainers(); while (citer != player->getEndContainer()) // iterate containers opened by player { // close container if it is child of the one on the groud if (citer->second->getTopParent() == container) citer = player->closeContainer(citer->first); else ++citer; } ++piter; } } if (removeThing(item)) item->releaseThing(); } return (long)trash.size(); }
void Map::removeUnawareThings() { // remove creatures from tiles that we are not aware of anymore for(const auto& pair : m_knownCreatures) { const CreaturePtr& creature = pair.second; if(!isAwareOfPosition(creature->getPosition())) removeThing(creature); } // remove static texts from tiles that we are not aware anymore for(auto it = m_staticTexts.begin(); it != m_staticTexts.end();) { const StaticTextPtr& staticText = *it; if(staticText->getMessageMode() == Otc::MessageNone && !isAwareOfPosition(staticText->getPosition())) it = m_staticTexts.erase(it); else ++it; } }
void Editor::placeThing() { assert(!choosing); if (selected < 0) return; AbstractThing *item = getThingFromCode(selected, curser->position_x, curser->position_y, row_w, col_h, m_UI->sprites); item->SetBounds(curser->position_x, curser->position_y, row_w, col_h); int type = item->gen_type; if (type == SOLID) { removeThing(); } if (hero && item->Overlaps(hero)) hero = NULL; if (door && item->Overlaps(door)) door = NULL; std::list<AbstractThing *>::iterator it = placed_items->begin(); while (it != placed_items->end()) { if ((type == NONSOLID && (*it)->gen_type == NONSOLID || type == COLLECTABLE && (*it)->gen_type == COLLECTABLE || type == BADDIE && (*it)->gen_type == BADDIE) && curser->Overlaps((*it)->Bounds())) { printf("Replacing! "); placed_items->erase(it++); } else ++it; } printf("Pacing %dth item.\n", placed_items->size() + 1); placed_items->push_back(item); }
void Tile::addThing(int32_t, Thing* thing) { Creature* creature = thing->getCreature(); if (creature) { g_game.map.clearSpectatorCache(); creature->setParent(this); CreatureVector* creatures = makeCreatures(); creatures->insert(creatures->begin(), creature); } else { Item* item = thing->getItem(); if (item == nullptr) { return /*RETURNVALUE_NOTPOSSIBLE*/; } TileItemVector* items = getItemList(); if (items && items->size() >= 0xFFFF) { return /*RETURNVALUE_NOTPOSSIBLE*/; } item->setParent(this); const ItemType& itemType = Item::items[item->getID()]; if (itemType.isGroundTile()) { if (ground == nullptr) { ground = item; onAddTileItem(item); } else { const ItemType& oldType = Item::items[ground->getID()]; Item* oldGround = ground; ground->setParent(nullptr); g_game.ReleaseItem(ground); ground = item; resetTileFlags(oldGround); setTileFlags(item); onUpdateTileItem(oldGround, oldType, item, itemType); postRemoveNotification(oldGround, nullptr, 0); } } else if (itemType.alwaysOnTop) { if (itemType.isSplash() && items) { //remove old splash if exists for (ItemVector::const_iterator it = items->getBeginTopItem(), end = items->getEndTopItem(); it != end; ++it) { Item* oldSplash = *it; if (!Item::items[oldSplash->getID()].isSplash()) { continue; } removeThing(oldSplash, 1); oldSplash->setParent(nullptr); g_game.ReleaseItem(oldSplash); postRemoveNotification(oldSplash, nullptr, 0); break; } } bool isInserted = false; if (items) { for (ItemVector::iterator it = items->getBeginTopItem(), end = items->getEndTopItem(); it != end; ++it) { //Note: this is different from internalAddThing if (itemType.alwaysOnTopOrder <= Item::items[(*it)->getID()].alwaysOnTopOrder) { items->insert(it, item); isInserted = true; break; } } } else { items = makeItemList(); } if (!isInserted) { items->push_back(item); } onAddTileItem(item); } else { if (itemType.isMagicField()) { //remove old field item if exists if (items) { for (ItemVector::const_iterator it = items->getBeginDownItem(), end = items->getEndDownItem(); it != end; ++it) { MagicField* oldField = (*it)->getMagicField(); if (oldField) { if (oldField->isReplaceable()) { removeThing(oldField, 1); oldField->setParent(nullptr); g_game.ReleaseItem(oldField); postRemoveNotification(oldField, nullptr, 0); break; } else { //This magic field cannot be replaced. item->setParent(nullptr); g_game.ReleaseItem(item); return; } } } } } items = makeItemList(); items->insert(items->getBeginDownItem(), item); items->addDownItemCount(1); onAddTileItem(item); } } }
void Tile::removeCreature(Creature* creature) { g_game.map.getQTNode(tilePos.x, tilePos.y)->removeCreature(creature); removeThing(creature, 0); }
bool Map::removeThingByPos(const Position& pos, int stackPos) { if(TilePtr tile = getTile(pos)) return removeThing(tile->getThing(stackPos)); return false; }
void Tile::addThing(const ThingPtr& thing, int stackPos) { if(!thing) return; if(thing->isEffect()) { m_effects.push_back(thing->static_self_cast<Effect>()); } else { // priority 854 // 0 - ground, --> --> // 1 - ground borders --> --> // 2 - bottom (walls), --> --> // 3 - on top (doors) --> --> // 4 - creatures, from top to bottom <-- --> // 5 - items, from top to bottom <-- <-- if(stackPos < 0 || stackPos == 255) { int priority = thing->getStackPriority(); // -1 or 255 => auto detect position // -2 => append bool append; if(stackPos == -2) append = true; else { append = (priority <= 3); // newer protocols does not store creatures in reverse order if(g_game.getProtocolVersion() >= 854 && priority == 4) append = !append; } for(stackPos = 0; stackPos < (int)m_things.size(); ++stackPos) { int otherPriority = m_things[stackPos]->getStackPriority(); if((append && otherPriority > priority) || (!append && otherPriority >= priority)) break; } } else if(stackPos > (int)m_things.size()) stackPos = m_things.size(); m_things.insert(m_things.begin() + stackPos, thing); if(m_things.size() > MAX_THINGS) removeThing(m_things[MAX_THINGS]); /* // check stack priorities // this code exists to find stackpos bugs faster int lastPriority = 0; for(const ThingPtr& thing : m_things) { int priority = thing->getStackPriority(); assert(lastPriority <= priority); lastPriority = priority; } */ } thing->setPosition(m_position); thing->onAppear(); if(thing->isTranslucent()) checkTranslucentLight(); }
void Tile::clean() { while(!m_things.empty()) removeThing(m_things.front()); }
void Tile::removeCreature(Creature* creature) { qt_node->removeCreature(creature); removeThing(creature, 0); }