Skip to content
Browse files

don't reactivate spawn points with living spawns in the area

  • Loading branch information...
1 parent 34ec5fe commit 7f06f2c6667da1b9689066776033d98a69a6fa18 @fizzet fizzet committed May 6, 2013
View
19 gemrb/core/Map.cpp
@@ -1822,6 +1822,20 @@ int Map::GetActorInRect(Actor**& actorlist, Region& rgn, bool onlyparty)
return count;
}
+bool Map::SpawnsAlive() const
+{
+ size_t i = actors.size();
+ while (i--) {
+ Actor* actor = actors[i];
+ if (!actor->ValidTarget(GA_NO_DEAD) )
+ continue;
+ if (actor->Spawned) {
+ return true;
+ }
+ }
+ return false;
+}
+
void Map::PlayAreaSong(int SongType, bool restart, bool hard)
{
//Ok, we use a non constant pointer here, so it is easy to disable
@@ -3040,6 +3054,7 @@ bool Map::SpawnCreature(const Point &pos, const char *creResRef, int radiusx, in
if (level >= cpl || sg || first) {
AddActor(creature, true);
creature->SetPosition(pos, true, radiusx, radiusy);
+ creature->Spawned = true;
creature->RefreshEffects(NULL);
if (difficulty && !sg) *difficulty -= cpl;
if (creCount) (*creCount)++;
@@ -3105,6 +3120,10 @@ void Map::TriggerSpawn(Spawn *spawn)
void Map::UpdateSpawns()
{
+ //don't reactivate if there are spawns left in the area
+ if (SpawnsAlive()) {
+ return;
+ }
ieDword time = core->GetGame()->GameTime;
for (std::vector<Spawn *>::iterator it = spawns.begin() ; it != spawns.end(); ++it) {
Spawn *spawn = *it;
View
1 gemrb/core/Map.h
@@ -367,6 +367,7 @@ class GEM_EXPORT Map : public Scriptable {
Actor* GetActorByResource(const char* resref);
Actor* GetActorByScriptName(const char* name);
bool HasActor(Actor *actor);
+ bool SpawnsAlive() const;
void RemoveActor(Actor* actor);
//returns actors in rect (onlyparty could be more sophisticated)
int GetActorInRect(Actor**& actors, Region& rgn, bool onlyparty);
View
1 gemrb/core/Scriptable/Actor.cpp
@@ -507,6 +507,7 @@ Actor::Actor()
RemovalTime = ~0;
HomeLocation.x = 0;
HomeLocation.y = 0;
+ Spawned = false;
version = 0;
//these are used only in iwd2 so we have to default them
for(i=0;i<7;i++) {
View
1 gemrb/core/Scriptable/Actor.h
@@ -332,6 +332,7 @@ class GEM_EXPORT Actor : public Movable {
int LastDamage;
Point FollowOffset;//follow lastfollowed at this offset
Point HomeLocation;//spawnpoint, return here after rest
+ bool Spawned; //has been created by a spawn point
ieDword TargetDoor;
View
11 gemrb/plugins/AREImporter/AREImporter.cpp
@@ -943,7 +943,7 @@ Map* AREImporter::GetMap(const char *ResRef, bool day_or_night)
ieResRef CreResRef;
ieDword TalkCount;
ieDword Orientation, Schedule, RemovalTime;
- ieWord XPos, YPos, XDes, YDes;
+ ieWord XPos, YPos, XDes, YDes, Spawned;
ieResRef Dialog;
ieResRef Scripts[8]; //the original order
ieDword Flags;
@@ -954,7 +954,8 @@ Map* AREImporter::GetMap(const char *ResRef, bool day_or_night)
str->ReadWord( &XDes );
str->ReadWord( &YDes );
str->ReadDword( &Flags );
- str->Seek( 8, GEM_CURRENT_POS );
+ str->ReadWord( &Spawned );
+ str->Seek( 6, GEM_CURRENT_POS );
str->ReadDword( &Orientation );
str->ReadDword( &RemovalTime );
str->Seek( 4, GEM_CURRENT_POS );
@@ -1004,6 +1005,7 @@ Map* AREImporter::GetMap(const char *ResRef, bool day_or_night)
ab->Destination.y = YPos;
ab->HomeLocation.x = XDes;
ab->HomeLocation.y = YDes;
+ ab->Spawned = Spawned;
//copying the scripting name into the actor
//if the CreatureAreaFlag was set to 8
if ((Flags&AF_NAME_OVERRIDE) || (core->HasFeature(GF_IWD2_SCRIPTNAME)) ) {
@@ -1918,7 +1920,10 @@ int AREImporter::PutActors( DataStream *stream, Map *map)
stream->WriteWord( &tmpWord);
stream->WriteDword( &tmpDword); //used fields flag always 0 for saved areas
- stream->WriteDword( &tmpDword); //unknown2c
+ tmpWord = ac->Spawned;
+ stream->WriteWord( &tmpWord);
+ tmpWord = 0;
+ stream->WriteWord( &tmpWord);
stream->WriteDword( &tmpDword); //actor animation, unused
tmpWord = ac->GetOrientation();
stream->WriteWord( &tmpWord);

0 comments on commit 7f06f2c

Please sign in to comment.
Something went wrong with that request. Please try again.