From ceb4e23edaec3c39f2ac28c55ba6a0e8c0938bdc Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Thu, 28 Aug 2008 19:55:09 +0000 Subject: [PATCH] patch #1096: Improve speed of fireOnLocation, and use it to fix AI bug git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5883 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/effects.c | 43 ++++++++++++++++++++++++++++--------------- src/map.h | 1 + src/scriptfuncs.c | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/effects.c b/src/effects.c index c8295c64b..dcf197d44 100644 --- a/src/effects.c +++ b/src/effects.c @@ -261,6 +261,18 @@ static void positionEffect(EFFECT *psEffect) static void killEffect(EFFECT *e) { + if (e->group == EFFECT_FIRE) + { + const int posX = map_coord(e->position.x); + const int posY = map_coord(e->position.z); + MAPTILE *psTile = mapTile(posX, posY); + + ASSERT(psTile, "Fire effect on non-existing tile (%d, %d)", posX, posY); + if (psTile) + { + psTile->tileInfoBits &= ~BITS_ON_FIRE; // clear fire bit + } + } effectStatus[e-asEffectsList] = ES_INACTIVE; e->control = (UBYTE) 0; } @@ -2326,6 +2338,15 @@ void effectSetupConstruction(EFFECT *psEffect) // ---------------------------------------------------------------------------------------- void effectSetupFire(EFFECT *psEffect) { + const int posX = map_coord(psEffect->position.x); + const int posY = map_coord(psEffect->position.z); + MAPTILE *psTile = mapTile(posX, posY); + + ASSERT(psTile, "Cannot place a fire effect %d, %d - outside map!", posX, posY); + if (psTile) + { + psTile->tileInfoBits |= BITS_ON_FIRE; + } psEffect->frameDelay = 300; // needs to be investigated... psEffect->radius = auxVar; // needs to be investigated psEffect->lifeSpan = (UWORD)auxVarSec; @@ -2709,26 +2730,18 @@ UDWORD i; // ----------------------------------------------------------------------------------- +/// Check if tile contained within the given world coordinates is burning. bool fireOnLocation(unsigned int x, unsigned int y) { - unsigned int i; + const int posX = map_coord(x); + const int posY = map_coord(y); + MAPTILE *psTile = mapTile(posX, posY); - for(i = 0; i < MAX_EFFECTS; ++i) + ASSERT(psTile, "Checking fire on tile outside the map (%d, %d)", posX, posY); + if (psTile) { - if (effectStatus[i] == ES_ACTIVE - && asEffectsList[i].group == EFFECT_FIRE) - { - const unsigned int posX = asEffectsList[i].position.x; - const unsigned int posY = asEffectsList[i].position.z; - - if (posX == x - && posY == y) - { - return true; - } - } + return (psTile->tileInfoBits & BITS_ON_FIRE); } - return false; } diff --git a/src/map.h b/src/map.h index e393d4be1..da9f31068 100644 --- a/src/map.h +++ b/src/map.h @@ -73,6 +73,7 @@ static inline unsigned short TileNumber_texture(unsigned short tilenumber) #define BITS_NOTBLOCKING 0x01 // units can drive on this even if there is a structure or feature on it #define BITS_FPATHBLOCK 0x10 // bit set temporarily by find path to mark a blocking tile +#define BITS_ON_FIRE 0x20 // cache whether tile is burning #define BITS_GATEWAY 0x40 // bit set to show a gateway on the tile #define BITS_TALLSTRUCTURE 0x80 // bit set to show a tall structure which camera needs to avoid. diff --git a/src/scriptfuncs.c b/src/scriptfuncs.c index 42f428271..73f1a5149 100644 --- a/src/scriptfuncs.c +++ b/src/scriptfuncs.c @@ -1777,7 +1777,7 @@ BOOL scrGetFeatureB(void) if( ( psCurrEnumFeature[bucket]->psStats->subType == psFeatureStatToFind[bucket]->subType) &&( psCurrEnumFeature[bucket]->visible[playerToEnum[bucket]] != 0) &&!TileHasStructure(mapTile(map_coord(psCurrEnumFeature[bucket]->pos.x), map_coord(psCurrEnumFeature[bucket]->pos.y))) - /*&&!fireOnLocation(psCurrEnumFeature[bucket]->pos.x,psCurrEnumFeature[bucket]->pos.y )*/ // not burning. + &&!fireOnLocation(psCurrEnumFeature[bucket]->pos.x,psCurrEnumFeature[bucket]->pos.y ) // not burning. ) { scrFunctionResult.v.oval = psCurrEnumFeature[bucket];