Scriptable* GetActorFromObject(Scriptable* Sender, Object* oC, int ga_flags) { Scriptable *aC = NULL; if (!oC) { return NULL; } Targets *tgts = GetAllObjects(Sender->GetCurrentArea(), Sender, oC, ga_flags); if (tgts) { //now this could return other than actor objects aC = tgts->GetTarget(0,-1); delete tgts; /*if (!aC && (ga_flags&GA_GLOBAL) ) { tgts = GetAllObjectsNearby(Sender, oC, ga_flags); if (tgts) { //now this could return other than actor objects aC = tgts->GetTarget(0,-1); delete tgts; } }*/ return aC; } if (oC->objectName[0]) { // if you ActionOverride a global actor, they might not have a map :( // TODO: don't allow this to happen? if (Sender->GetCurrentArea()) { aC = GetActorObject(Sender->GetCurrentArea()->GetTileMap(), oC->objectName ); if (aC) { return aC; } } Game *game = core->GetGame(); //global actors are always found by scripting name! aC = game->FindPC(oC->objectName); if (aC) { return aC; } aC = game->FindNPC(oC->objectName); if (aC) { return aC; } /*if (ga_flags&GA_GLOBAL) { size_t mc = game->GetLoadedMapCount(); while(mc--) { Map *map = game->GetMap(mc); if (map==Sender->GetCurrentArea()) continue; aC = GetActorObject(map->GetTileMap(), oC->objectName); if (aC) { return aC; } } }*/ } return NULL; }
CObject* CObjectManager::GetObjectByRank(unsigned int id) { auto objects = GetAllObjects(); auto it = objects.begin(); for (unsigned int i = 0; i < id && it != objects.end(); i++, ++it); if (it == objects.end()) return nullptr; return *it; }
int CObjectManager::CountObjectsImplementing(ObjectInterfaceType interface) { int count = 0; for (CObject* object : GetAllObjects()) { if (object->Implements(interface)) count++; } return count; }
std::vector<CObject*> CObjectManager::GetObjectsOfTeam(int team) { std::vector<CObject*> result; for (CObject* object : GetAllObjects()) { if (object->GetTeam() == team) { result.push_back(object); } } return result; }
int GetObjectCount(Scriptable* Sender, Object* oC) { if (!oC) { return 0; } // EvaluateObject will return [PC] // GetAllObjects will also return Myself (evaluates object filters) // i believe we need the latter here Targets* tgts = GetAllObjects(Sender->GetCurrentArea(), Sender, oC, 0); int count = tgts->Count(); delete tgts; return count; }
bool CObjectManager::TeamExists(int team) { if(team == 0) return true; for (CObject* object : GetAllObjects()) { if (!object->GetActive()) continue; if (object->GetTeam() == team) return true; } return false; }
Scriptable* GetActorFromObject(Scriptable* Sender, Object* oC, int ga_flags) { Scriptable *aC = NULL; Game *game = core->GetGame(); Targets *tgts = GetAllObjects(Sender->GetCurrentArea(), Sender, oC, ga_flags); if (tgts) { //now this could return other than actor objects aC = tgts->GetTarget(0,-1); delete tgts; if (aC || !oC || oC->objectFields[0]!=-1) { return aC; } //global actors are always found by object ID! return game->GetGlobalActorByGlobalID(oC->objectFields[1]); } if (!oC) { return NULL; } if (oC->objectName[0]) { // if you ActionOverride a global actor, they might not have a map :( // TODO: don't allow this to happen? if (Sender->GetCurrentArea()) { aC = GetActorObject(Sender->GetCurrentArea()->GetTileMap(), oC->objectName ); if (aC) { return aC; } } //global actors are always found by scripting name! aC = game->FindPC(oC->objectName); if (aC) { return aC; } aC = game->FindNPC(oC->objectName); if (aC) { return aC; } } return NULL; }
void CObjectManager::DestroyTeam(int team) { assert(team != 0); for (CObject* object : GetAllObjects()) { if (object->GetTeam() == team) { if (object->Implements(ObjectInterfaceType::Destroyable)) { dynamic_cast<CDestroyableObject*>(object)->DestroyObject(DestructionType::Explosion); } else { DeleteObject(object); } } } }
//TODO: //check numcreaturesatmylevel(myself, 1) //when the actor is alone //it should (obviously) return true if the trigger //evaluates object filters //also check numcreaturesgtmylevel(myself,0) with //actor having at high level int GetObjectLevelCount(Scriptable* Sender, Object* oC) { if (!oC) { return 0; } // EvaluateObject will return [PC] // GetAllObjects will also return Myself (evaluates object filters) // i believe we need the latter here Targets* tgts = GetAllObjects(Sender->GetCurrentArea(), Sender, oC, 0); int count = 0; if (tgts) { targetlist::iterator m; const targettype *tt = tgts->GetFirstTarget(m, ST_ACTOR); while (tt) { count += ((Actor *) tt->actor)->GetXPLevel(true); tt = tgts->GetNextTarget(m, ST_ACTOR); } } delete tgts; return count; }