aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra
diff options
context:
space:
mode:
authorathrxx2012-05-06 01:03:33 +0200
committerathrxx2012-05-06 12:42:10 +0200
commit13876931683778587746c50592656f2b3c2af732 (patch)
tree860c3242a86c48c8d67cd0854ce79de6d809c2e3 /engines/kyra
parente7ba09be63a556236bd19c5e89faa524289aced9 (diff)
downloadscummvm-rg350-13876931683778587746c50592656f2b3c2af732.tar.gz
scummvm-rg350-13876931683778587746c50592656f2b3c2af732.tar.bz2
scummvm-rg350-13876931683778587746c50592656f2b3c2af732.zip
KYRA: fix bug No. X. from http://forums.scummvm.org/viewtopic.php?t=11487
(monsters not getting hit by fireball trap)
Diffstat (limited to 'engines/kyra')
-rw-r--r--engines/kyra/items_lol.cpp53
-rw-r--r--engines/kyra/lol.h10
-rw-r--r--engines/kyra/script_lol.cpp5
-rw-r--r--engines/kyra/sprites_lol.cpp70
4 files changed, 68 insertions, 70 deletions
diff --git a/engines/kyra/items_lol.cpp b/engines/kyra/items_lol.cpp
index ea2acaf64d..409b53f6f0 100644
--- a/engines/kyra/items_lol.cpp
+++ b/engines/kyra/items_lol.cpp
@@ -441,20 +441,20 @@ bool LoLEngine::launchObject(int objectType, Item item, int startX, int startY,
return true;
}
-void LoLEngine::endObjectFlight(FlyingObject *t, int x, int y, int collisionObject) {
+void LoLEngine::endObjectFlight(FlyingObject *t, int x, int y, int collisionType) {
int cx = x;
int cy = y;
uint16 block = calcBlockIndex(t->x, t->y);
removeAssignedObjectFromBlock(&_levelBlockProperties[block], t->item);
removeDrawObjectFromBlock(&_levelBlockProperties[block], t->item);
- if (collisionObject == 1) {
+ if (collisionType == 1) {
cx = t->x;
cy = t->y;
}
if (t->objectType == 0 || t->objectType == 1) {
- objectFlightProcessHits(t, cx, cy, collisionObject);
+ objectFlightProcessHits(t, cx, cy, collisionType);
t->x = (cx & 0xffc0) | 0x40;
t->y = (cy & 0xffc0) | 0x40;
t->flyingHeight = 0;
@@ -488,27 +488,23 @@ void LoLEngine::updateObjectFlightPosition(FlyingObject *t) {
}
}
-void LoLEngine::objectFlightProcessHits(FlyingObject *t, int x, int y, int objectOnNextBlock) {
- uint16 r = 0;
-
- if (objectOnNextBlock == 1) {
+void LoLEngine::objectFlightProcessHits(FlyingObject *t, int x, int y, int collisionType) {
+ if (collisionType == 1) {
runLevelScriptCustom(calcNewBlockPosition(_itemsInPlay[t->item].block, t->direction >> 1), 0x8000, -1, t->item, 0, 0);
- } else if (objectOnNextBlock == 2) {
+ } else if (collisionType == 2) {
if (_itemProperties[_itemsInPlay[t->item].itemPropertyIndex].flags & 0x4000) {
- int o = _levelBlockProperties[_itemsInPlay[t->item].block].assignedObjects;
- while (o & 0x8000) {
- LoLObject *i = findObject(o);
- o = i->nextAssignedObject;
- runItemScript(t->attackerId, t->item, 0x8000, o, 0);
+ uint16 obj = _levelBlockProperties[_itemsInPlay[t->item].block].assignedObjects;
+ while (obj & 0x8000) {
+ runItemScript(t->attackerId, t->item, 0x8000, obj, 0);
+ obj = findObject(obj)->nextAssignedObject;
}
} else {
- r = getNearestMonsterFromPos(x, y);
- runItemScript(t->attackerId, t->item, 0x8000, r, 0);
+ runItemScript(t->attackerId, t->item, 0x8000, getNearestMonsterFromPos(x, y), 0);
}
- } else if (objectOnNextBlock == 4) {
+ } else if (collisionType == 4) {
_partyAwake = true;
if (_itemProperties[_itemsInPlay[t->item].itemPropertyIndex].flags & 0x4000) {
for (int i = 0; i < 4; i++) {
@@ -516,8 +512,7 @@ void LoLEngine::objectFlightProcessHits(FlyingObject *t, int x, int y, int objec
runItemScript(t->attackerId, t->item, 0x8000, i, 0);
}
} else {
- r = getNearestPartyMemberFromPos(x, y);
- runItemScript(t->attackerId, t->item, 0x8000, r, 0);
+ runItemScript(t->attackerId, t->item, 0x8000, getNearestPartyMemberFromPos(x, y), 0);
}
}
}
@@ -543,9 +538,9 @@ void LoLEngine::updateFlyingObject(FlyingObject *t) {
middle of a block (or making the monsters align to the middle before casting them) wouldn't help here
(and wouldn't be faithful to the original either).
*/
- int objectOnNextBlock = checkBlockBeforeObjectPlacement(x, y, /*_itemProperties[_itemsInPlay[t->item].itemPropertyIndex].flags & 0x4000 ? 256 :*/ 63, t->flags, t->wallFlags);
- if (objectOnNextBlock) {
- endObjectFlight(t, x, y, objectOnNextBlock);
+ int collisionType = checkBlockBeforeObjectPlacement(x, y, /*_itemProperties[_itemsInPlay[t->item].itemPropertyIndex].flags & 0x4000 ? 256 :*/ 63, t->flags, t->wallFlags);
+ if (collisionType) {
+ endObjectFlight(t, x, y, collisionType);
} else {
if (--t->distance) {
processObjectFlight(t, x, y);
@@ -567,16 +562,16 @@ void LoLEngine::assignItemToBlock(uint16 *assignedBlockObjects, int id) {
*assignedBlockObjects = id;
}
-int LoLEngine::checkDrawObjectSpace(int itemX, int itemY, int partyX, int partyY) {
- int a = itemX - partyX;
- if (a < 0)
- a = -a;
+int LoLEngine::checkDrawObjectSpace(int x1, int y1, int x2, int y2) {
+ int dx = x1 - x2;
+ if (dx < 0)
+ dx = -dx;
- int b = itemY - partyY;
- if (b < 0)
- b = -b;
+ int dy = y1 - y2;
+ if (dy < 0)
+ dy = -dy;
- return a + b;
+ return dx + dy;
}
int LoLEngine::checkSceneForItems(uint16 *blockDrawObjects, int color) {
diff --git a/engines/kyra/lol.h b/engines/kyra/lol.h
index dbd461267f..dcd13804b3 100644
--- a/engines/kyra/lol.h
+++ b/engines/kyra/lol.h
@@ -1047,14 +1047,14 @@ private:
void setItemPosition(Item item, uint16 x, uint16 y, int flyingHeight, int moveable);
void removeLevelItem(Item item, int block);
bool launchObject(int objectType, Item item, int startX, int startY, int flyingHeight, int direction, int, int attackerId, int c);
- void endObjectFlight(FlyingObject *t, int x, int y, int collisionObject);
+ void endObjectFlight(FlyingObject *t, int x, int y, int collisionType);
void processObjectFlight(FlyingObject *t, int x, int y);
void updateObjectFlightPosition(FlyingObject *t);
- void objectFlightProcessHits(FlyingObject *t, int x, int y, int objectOnNextBlock);
+ void objectFlightProcessHits(FlyingObject *t, int x, int y, int collisionType);
void updateFlyingObject(FlyingObject *t);
void assignItemToBlock(uint16 *assignedBlockObjects, int id);
- int checkDrawObjectSpace(int itemX, int itemY, int partyX, int partyY);
+ int checkDrawObjectSpace(int x1, int y1, int x2, int y2);
int checkSceneForItems(uint16 *blockDrawObjects, int color);
uint8 _moneyColumnHeight[5];
@@ -1095,7 +1095,7 @@ private:
void monsterDropItems(LoLMonster *monster);
void giveItemToMonster(LoLMonster *monster, Item item);
int checkBlockBeforeObjectPlacement(uint16 x, uint16 y, uint16 objectWidth, uint16 testFlag, uint16 wallFlag);
- int checkBlockForWallsAndSufficientSpace(int block, int x, int y, int objectWidth, int testFlag, int wallFlag);
+ int testBlockPassability(int block, int x, int y, int objectWidth, int testFlag, int wallFlag);
int calcMonsterSkillLevel(int id, int a);
int checkBlockOccupiedByParty(int x, int y, int testFlag);
const uint16 *getCharacterOrMonsterStats(int id);
@@ -1122,7 +1122,7 @@ private:
int checkForPossibleDistanceAttack(uint16 monsterBlock, int direction, int distance, uint16 curBlock);
int walkMonsterCheckDest(int x, int y, LoLMonster *monster, int unk);
void getNextStepCoords(int16 monsterX, int16 monsterY, int &newX, int &newY, uint16 direction);
- void rearrangeAttackingMonster(LoLMonster *monster);
+ void alignMonsterToParty(LoLMonster *monster);
void moveStrayingMonster(LoLMonster *monster);
void killMonster(LoLMonster *monster);
diff --git a/engines/kyra/script_lol.cpp b/engines/kyra/script_lol.cpp
index c5d1d49030..9c0fe21ad4 100644
--- a/engines/kyra/script_lol.cpp
+++ b/engines/kyra/script_lol.cpp
@@ -958,10 +958,9 @@ int LoLEngine::olol_loadMonsterProperties(EMCState *script) {
l->hitPoints = stackPos(26);
l->speedTotalWaitTicks = 1;
l->flags = stackPos(27);
- l->unk5 = stackPos(28);
- // FIXME???
+ // This is what the original does here (setting the value first to stackPos(28) and then to stackPos(29):
+ //l->unk5 = stackPos(28);
l->unk5 = stackPos(29);
- //
l->numDistAttacks = stackPos(30);
l->numDistWeapons = stackPos(31);
diff --git a/engines/kyra/sprites_lol.cpp b/engines/kyra/sprites_lol.cpp
index a07abd4580..f4bae113c5 100644
--- a/engines/kyra/sprites_lol.cpp
+++ b/engines/kyra/sprites_lol.cpp
@@ -355,7 +355,7 @@ int LoLEngine::checkBlockBeforeObjectPlacement(uint16 x, uint16 y, uint16 object
int yOffs = 0;
int flag = 0;
- int r = checkBlockForWallsAndSufficientSpace(calcBlockIndex(x, y), x, y, objectWidth, testFlag, wallFlag);
+ int r = testBlockPassability(calcBlockIndex(x, y), x, y, objectWidth, testFlag, wallFlag);
if (r)
return r;
@@ -369,7 +369,7 @@ int LoLEngine::checkBlockBeforeObjectPlacement(uint16 x, uint16 y, uint16 object
_objectLastDirection = 2;
x2 = x + objectWidth;
- r = checkBlockForWallsAndSufficientSpace(calcBlockIndex(x2, y), x, y, objectWidth, testFlag, wallFlag);
+ r = testBlockPassability(calcBlockIndex(x2, y), x, y, objectWidth, testFlag, wallFlag);
if (r)
return r;
@@ -385,7 +385,7 @@ int LoLEngine::checkBlockBeforeObjectPlacement(uint16 x, uint16 y, uint16 object
_objectLastDirection = 6;
x2 = x - objectWidth;
- r = checkBlockForWallsAndSufficientSpace(calcBlockIndex(x2, y), x, y, objectWidth, testFlag, wallFlag);
+ r = testBlockPassability(calcBlockIndex(x2, y), x, y, objectWidth, testFlag, wallFlag);
if (r)
return r;
@@ -403,7 +403,7 @@ int LoLEngine::checkBlockBeforeObjectPlacement(uint16 x, uint16 y, uint16 object
_objectLastDirection = 4;
y2 = y + objectWidth;
- r = checkBlockForWallsAndSufficientSpace(calcBlockIndex(x, y2), x, y, objectWidth, testFlag, wallFlag);
+ r = testBlockPassability(calcBlockIndex(x, y2), x, y, objectWidth, testFlag, wallFlag);
if (r)
return r;
@@ -420,7 +420,7 @@ int LoLEngine::checkBlockBeforeObjectPlacement(uint16 x, uint16 y, uint16 object
_objectLastDirection = 0;
y2 = y - objectWidth;
- r = checkBlockForWallsAndSufficientSpace(calcBlockIndex(x, y2), x, y, objectWidth, testFlag, wallFlag);
+ r = testBlockPassability(calcBlockIndex(x, y2), x, y, objectWidth, testFlag, wallFlag);
if (r)
return r;
@@ -436,7 +436,7 @@ int LoLEngine::checkBlockBeforeObjectPlacement(uint16 x, uint16 y, uint16 object
if (!flag)
return 0;
- r = checkBlockForWallsAndSufficientSpace(calcBlockIndex(x2, y2), x, y, objectWidth, testFlag, wallFlag);
+ r = testBlockPassability(calcBlockIndex(x2, y2), x, y, objectWidth, testFlag, wallFlag);
if (r)
return r;
@@ -447,7 +447,7 @@ int LoLEngine::checkBlockBeforeObjectPlacement(uint16 x, uint16 y, uint16 object
return 0;
}
-int LoLEngine::checkBlockForWallsAndSufficientSpace(int block, int x, int y, int objectWidth, int testFlag, int wallFlag) {
+int LoLEngine::testBlockPassability(int block, int x, int y, int objectWidth, int testFlag, int wallFlag) {
if (block == _currentBlock)
testFlag &= 0xfffe;
@@ -461,9 +461,9 @@ int LoLEngine::checkBlockForWallsAndSufficientSpace(int block, int x, int y, int
if (!(testFlag & 2))
return 0;
- uint16 b = _levelBlockProperties[block].assignedObjects;
- while (b & 0x8000) {
- LoLMonster *monster = &_monsters[b & 0x7fff];
+ uint16 obj = _levelBlockProperties[block].assignedObjects;
+ while (obj & 0x8000) {
+ LoLMonster *monster = &_monsters[obj & 0x7fff];
if (monster->mode < 13) {
int r = checkDrawObjectSpace(x, y, monster->x, monster->y);
@@ -471,7 +471,7 @@ int LoLEngine::checkBlockForWallsAndSufficientSpace(int block, int x, int y, int
return 2;
}
- b = findObject(b)->nextAssignedObject;
+ obj = findObject(obj)->nextAssignedObject;
}
return 0;
@@ -1105,7 +1105,7 @@ void LoLEngine::updateMonster(LoLMonster *monster) {
if ((monster->fightCurTick <= 0) || (checkDrawObjectSpace(_partyPosX, _partyPosY, monster->x, monster->y) > 256) || (monster->flags & 8))
setMonsterMode(monster, 7);
else
- rearrangeAttackingMonster(monster);
+ alignMonsterToParty(monster);
break;
case 6:
@@ -1428,26 +1428,26 @@ int LoLEngine::walkMonsterCheckDest(int x, int y, LoLMonster *monster, int unk)
uint8 m = monster->mode;
monster->mode = 15;
- int res = checkBlockBeforeObjectPlacement(x, y, monster->properties->maxWidth, 7, monster->properties->flags & 0x1000 ? 32 : unk);
+ int objType = checkBlockBeforeObjectPlacement(x, y, monster->properties->maxWidth, 7, monster->properties->flags & 0x1000 ? 32 : unk);
monster->mode = m;
- return res;
+ return objType;
}
void LoLEngine::getNextStepCoords(int16 srcX, int16 srcY, int &newX, int &newY, uint16 direction) {
- static const int8 shiftTableX[] = { 0, 32, 32, 32, 0, -32, -32, -32 };
- static const int8 shiftTableY[] = { -32, -32, 0, 32, 32, 32, 0, -32 };
+ static const int8 stepAdjustX[] = { 0, 32, 32, 32, 0, -32, -32, -32 };
+ static const int8 stepAdjustY[] = { -32, -32, 0, 32, 32, 32, 0, -32 };
- newX = (srcX + shiftTableX[direction]) & 0x1fff;
- newY = (srcY + shiftTableY[direction]) & 0x1fff;
+ newX = (srcX + stepAdjustX[direction]) & 0x1fff;
+ newY = (srcY + stepAdjustY[direction]) & 0x1fff;
}
-void LoLEngine::rearrangeAttackingMonster(LoLMonster *monster) {
- int t = (monster->direction >> 1);
+void LoLEngine::alignMonsterToParty(LoLMonster *monster) {
+ uint8 mdir = monster->direction >> 1;
uint16 mx = monster->x;
uint16 my = monster->y;
- uint16 *c = (t & 1) ? &my : &mx;
- bool centered = (*c & 0x7f) == 0;
+ uint16 *pos = (mdir & 1) ? &my : &mx;
+ bool centered = (*pos & 0x7f) == 0;
bool posFlag = true;
if (monster->properties->maxWidth <= 63) {
@@ -1464,11 +1464,13 @@ void LoLEngine::rearrangeAttackingMonster(LoLMonster *monster) {
r = true;
} else {
for (int i = 0; i < 3; i++) {
- t = (t + 1) & 3;
- id = _levelBlockProperties[calcNewBlockPosition(monster->block, t)].assignedObjects;
+ mdir = (mdir + 1) & 3;
+ id = _levelBlockProperties[calcNewBlockPosition(monster->block, mdir)].assignedObjects;
id = (id & 0x8000) ? (id & 0x7fff) : 0xffff;
- if (id != 0xffff)
+ if (id != 0xffff) {
r = true;
+ break;
+ }
}
}
}
@@ -1484,15 +1486,15 @@ void LoLEngine::rearrangeAttackingMonster(LoLMonster *monster) {
return;
if (posFlag) {
- if (*c & 0x80)
- *c -= 32;
+ if (*pos & 0x80)
+ *pos -= 32;
else
- *c += 32;
+ *pos += 32;
} else {
- if (*c & 0x80)
- *c += 32;
+ if (*pos & 0x80)
+ *pos += 32;
else
- *c -= 32;
+ *pos -= 32;
}
if (walkMonsterCheckDest(mx, my, monster, 4))
@@ -1502,8 +1504,10 @@ void LoLEngine::rearrangeAttackingMonster(LoLMonster *monster) {
int fy = _partyPosY;
calcSpriteRelPosition(mx, my, fx, fy, monster->direction >> 1);
- t = (fx < 0) ? -fx : fx;
- if (fy > 160 || t > 80)
+ if (fx < 0)
+ fx = -fx;
+
+ if (fy > 160 || fx > 80)
return;
placeMonster(monster, mx, my);