diff --git a/src/animation.cc b/src/animation.cc index 5663fe6..bc472c7 100644 --- a/src/animation.cc +++ b/src/animation.cc @@ -1939,18 +1939,18 @@ static int _tile_idistance(int tile1, int tile2) } // 0x4163AC -int _make_straight_path(Object* a1, int from, int to, StraightPathNode* straightPathNodeList, Object** obstaclePtr, int a6) +int _make_straight_path(Object* obj, int from, int to, StraightPathNode* straightPathNodeList, Object** obstaclePtr, int a6) { - return _make_straight_path_func(a1, from, to, straightPathNodeList, obstaclePtr, a6, _obj_blocking_at); + return _make_straight_path_func(obj, from, to, straightPathNodeList, obstaclePtr, a6, _obj_blocking_at); } // TODO: Rather complex, but understandable, needs testing. // // 0x4163C8 -int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* straightPathNodeList, Object** obstaclePtr, int a6, PathBuilderCallback* callback) +int _make_straight_path_func(Object* obj, int from, int to, StraightPathNode* straightPathNodeList, Object** obstaclePtr, int a6, PathBuilderCallback* callback) { if (obstaclePtr != NULL) { - Object* obstacle = callback(a1, from, a1->elevation); + Object* obstacle = callback(obj, from, obj->elevation); if (obstacle != NULL) { if (obstacle != *obstaclePtr && (a6 != 32 || (obstacle->flags & OBJECT_SHOOT_THRU) == 0)) { *obstaclePtr = obstacle; @@ -1961,13 +1961,13 @@ int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* str int fromX; int fromY; - tileToScreenXY(from, &fromX, &fromY, a1->elevation); + tileToScreenXY(from, &fromX, &fromY, obj->elevation); fromX += 16; fromY += 8; int toX; int toY; - tileToScreenXY(to, &toX, &toY, a1->elevation); + tileToScreenXY(to, &toX, &toY, obj->elevation); toX += 16; toY += 8; @@ -2005,7 +2005,7 @@ int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* str if (ddx <= ddy) { int middle = ddx - ddy / 2; while (true) { - tile = tileFromScreenXY(tileX, tileY, a1->elevation); + tile = tileFromScreenXY(tileX, tileY, obj->elevation); v22 += 1; if (v22 == a6) { @@ -2016,9 +2016,9 @@ int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* str if (straightPathNodeList != NULL) { StraightPathNode* pathNode = &(straightPathNodeList[pathNodeIndex]); pathNode->tile = tile; - pathNode->elevation = a1->elevation; + pathNode->elevation = obj->elevation; - tileToScreenXY(tile, &fromX, &fromY, a1->elevation); + tileToScreenXY(tile, &fromX, &fromY, obj->elevation); pathNode->x = tileX - fromX - 16; pathNode->y = tileY - fromY - 8; } @@ -2044,7 +2044,7 @@ int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* str if (tile != prevTile) { if (obstaclePtr != NULL) { - Object* obj = callback(a1, tile, a1->elevation); + Object* obj = callback(obj, tile, obj->elevation); if (obj != NULL) { if (obj != *obstaclePtr && (a6 != 32 || (obj->flags & OBJECT_SHOOT_THRU) == 0)) { *obstaclePtr = obj; @@ -2058,7 +2058,7 @@ int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* str } else { int middle = ddy - ddx / 2; while (true) { - tile = tileFromScreenXY(tileX, tileY, a1->elevation); + tile = tileFromScreenXY(tileX, tileY, obj->elevation); v22 += 1; if (v22 == a6) { @@ -2069,9 +2069,9 @@ int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* str if (straightPathNodeList != NULL) { StraightPathNode* pathNode = &(straightPathNodeList[pathNodeIndex]); pathNode->tile = tile; - pathNode->elevation = a1->elevation; + pathNode->elevation = obj->elevation; - tileToScreenXY(tile, &fromX, &fromY, a1->elevation); + tileToScreenXY(tile, &fromX, &fromY, obj->elevation); pathNode->x = tileX - fromX - 16; pathNode->y = tileY - fromY - 8; } @@ -2097,7 +2097,7 @@ int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* str if (tile != prevTile) { if (obstaclePtr != NULL) { - Object* obj = callback(a1, tile, a1->elevation); + Object* obj = callback(obj, tile, obj->elevation); if (obj != NULL) { if (obj != *obstaclePtr && (a6 != 32 || (obj->flags & OBJECT_SHOOT_THRU) == 0)) { *obstaclePtr = obj; @@ -2118,9 +2118,9 @@ int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* str if (straightPathNodeList != NULL) { StraightPathNode* pathNode = &(straightPathNodeList[pathNodeIndex]); pathNode->tile = tile; - pathNode->elevation = a1->elevation; + pathNode->elevation = obj->elevation; - tileToScreenXY(tile, &fromX, &fromY, a1->elevation); + tileToScreenXY(tile, &fromX, &fromY, obj->elevation); pathNode->x = tileX - fromX - 16; pathNode->y = tileY - fromY - 8; } @@ -2128,7 +2128,7 @@ int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* str pathNodeIndex += 1; } else { if (pathNodeIndex > 0 && straightPathNodeList != NULL) { - straightPathNodeList[pathNodeIndex - 1].elevation = a1->elevation; + straightPathNodeList[pathNodeIndex - 1].elevation = obj->elevation; } } diff --git a/src/animation.h b/src/animation.h index 4e146a4..9f0e297 100644 --- a/src/animation.h +++ b/src/animation.h @@ -145,8 +145,8 @@ int animationRegisterAnimateForever(Object* owner, int anim, int delay); int animationRegisterPing(int flags, int delay); int _make_path(Object* object, int from, int to, unsigned char* a4, int a5); int pathfinderFindPath(Object* object, int from, int to, unsigned char* rotations, int a5, PathBuilderCallback* callback); -int _make_straight_path(Object* a1, int from, int to, StraightPathNode* straightPathNodeList, Object** obstaclePtr, int a6); -int _make_straight_path_func(Object* a1, int from, int to, StraightPathNode* straightPathNodeList, Object** obstaclePtr, int a6, PathBuilderCallback* callback); +int _make_straight_path(Object* object, int from, int to, StraightPathNode* straightPathNodeList, Object** obstaclePtr, int a6); +int _make_straight_path_func(Object* object, int from, int to, StraightPathNode* straightPathNodeList, Object** obstaclePtr, int a6, PathBuilderCallback* callback); void _object_animate(); int _check_move(int* actionPointsPtr); int _dude_move(int actionPoints); diff --git a/src/combat.cc b/src/combat.cc index 8548137..4e84fda 100644 --- a/src/combat.cc +++ b/src/combat.cc @@ -3942,17 +3942,17 @@ static int attackCompute(Attack* attack) attack->tile = tile; - Object* v25 = attack->defender; - _make_straight_path_func(v25, attack->defender->tile, attack->tile, NULL, &v25, 32, _obj_shoot_blocking_at); - if (v25 != NULL && v25 != attack->defender) { - attack->tile = v25->tile; + Object* accidentalTarget = attack->defender; + _make_straight_path_func(accidentalTarget, attack->defender->tile, attack->tile, NULL, &accidentalTarget, 32, _obj_shoot_blocking_at); + if (accidentalTarget != NULL && accidentalTarget != attack->defender) { + attack->tile = accidentalTarget->tile; } else { - v25 = _obj_blocking_at(NULL, attack->tile, attack->defender->elevation); + accidentalTarget = _obj_blocking_at(NULL, attack->tile, attack->defender->elevation); } - if (v25 != NULL && (v25->flags & OBJECT_SHOOT_THRU) == 0) { + if (accidentalTarget != NULL && (accidentalTarget->flags & OBJECT_SHOOT_THRU) == 0) { attack->attackerFlags |= DAM_HIT; - attack->defender = v25; + attack->defender = accidentalTarget; attackComputeDamage(attack, 1, 2); } } @@ -3974,75 +3974,75 @@ static int attackCompute(Attack* attack) // compute_explosion_on_extras // 0x423C10 -void _compute_explosion_on_extras(Attack* attack, int a2, bool isGrenade, int a4) +void _compute_explosion_on_extras(Attack* attack, bool isFromAttacker, bool isGrenade, bool noDamage) { - Object* attacker; + Object* targetObj; - if (a2) { - attacker = attack->attacker; + if (isFromAttacker) { + targetObj = attack->attacker; } else { if ((attack->attackerFlags & DAM_HIT) != 0) { - attacker = attack->defender; + targetObj = attack->defender; } else { - attacker = NULL; + targetObj = NULL; } } - int tile; - if (attacker != NULL) { - tile = attacker->tile; + int explosionTile; + if (targetObj != NULL) { + explosionTile = targetObj->tile; } else { - tile = attack->tile; + explosionTile = attack->tile; } - if (tile == -1) { + if (explosionTile == -1) { debugPrint("\nError: compute_explosion_on_extras: Called with bad target/tileNum"); return; } - // TODO: The math in this loop is rather complex and hard to understand. - int v20; - int v22 = 0; + int ringTileIdx; + int radius = 0; int rotation = 0; - int v5 = -1; - int v19 = tile; + int tile = -1; + int ringFirstTile = explosionTile; // SFALL int maxTargets = explosionGetMaxTargets(); + // Check adjacent tiles for possible targets, going ring-by-ring while (attack->extrasLength < maxTargets) { - if (v22 != 0 && (v5 == -1 || (v5 = tileGetTileInDirection(v5, rotation, 1)) != v19)) { - v20++; - if (v20 % v22 == 0) { + if (radius != 0 && (tile == -1 || (tile = tileGetTileInDirection(tile, rotation, 1)) != ringFirstTile)) { + ringTileIdx++; + if (ringTileIdx % radius == 0) { // the larger the radius, the slower we rotate rotation += 1; if (rotation == ROTATION_COUNT) { rotation = ROTATION_NE; } } } else { - v22++; - if (isGrenade && weaponGetGrenadeExplosionRadius(attack->weapon) < v22) { - v5 = -1; - } else if (isGrenade || weaponGetRocketExplosionRadius(attack->weapon) >= v22) { - v5 = tileGetTileInDirection(v19, ROTATION_NE, 1); + radius++; // go to the next ring + if (isGrenade && weaponGetGrenadeExplosionRadius(attack->weapon) < radius) { + tile = -1; + } else if (isGrenade || weaponGetRocketExplosionRadius(attack->weapon) >= radius) { + tile = tileGetTileInDirection(ringFirstTile, ROTATION_NE, 1); } else { - v5 = -1; + tile = -1; } - v19 = v5; + ringFirstTile = tile; rotation = ROTATION_SE; - v20 = 0; + ringTileIdx = 0; } - if (v5 == -1) { + if (tile == -1) { break; } - Object* obstacle = _obj_blocking_at(attacker, v5, attack->attacker->elevation); + Object* obstacle = _obj_blocking_at(targetObj, tile, attack->attacker->elevation); if (obstacle != NULL && FID_TYPE(obstacle->fid) == OBJ_TYPE_CRITTER && (obstacle->data.critter.combat.results & DAM_DEAD) == 0 && (obstacle->flags & OBJECT_SHOOT_THRU) == 0 - && !_combat_is_shot_blocked(obstacle, obstacle->tile, tile, NULL, NULL)) { + && !_combat_is_shot_blocked(obstacle, obstacle->tile, explosionTile, NULL, NULL)) { if (obstacle == attack->attacker) { attack->attackerFlags &= ~DAM_HIT; attackComputeDamage(attack, 1, 2); @@ -4060,7 +4060,7 @@ void _compute_explosion_on_extras(Attack* attack, int a2, bool isGrenade, int a4 attack->extrasHitLocation[index] = HIT_LOCATION_TORSO; attack->extras[index] = obstacle; attackInit(&_explosion_ctd, attack->attacker, obstacle, attack->hitMode, HIT_LOCATION_TORSO); - if (!a4) { + if (!noDamage) { _explosion_ctd.attackerFlags |= DAM_HIT; attackComputeDamage(&_explosion_ctd, 1, 2); } diff --git a/src/combat.h b/src/combat.h index 4dc0430..9ce73d9 100644 --- a/src/combat.h +++ b/src/combat.h @@ -37,7 +37,7 @@ void _combat(STRUCT_664980* attack); void attackInit(Attack* attack, Object* a2, Object* a3, int a4, int a5); int _combat_attack(Object* a1, Object* a2, int a3, int a4); int _combat_bullet_start(const Object* a1, const Object* a2); -void _compute_explosion_on_extras(Attack* attack, int a2, bool isGrenade, int a4); +void _compute_explosion_on_extras(Attack* attack, bool isFromAttacker, bool isGrenade, bool noDamage); int _determine_to_hit(Object* a1, Object* a2, int hitLocation, int hitMode); int _determine_to_hit_no_range(Object* a1, Object* a2, int a3, int a4, unsigned char* a5); int _determine_to_hit_from_tile(Object* a1, int a2, Object* a3, int a4, int a5); diff --git a/src/interpreter.cc b/src/interpreter.cc index ab866ce..6f281ca 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -51,7 +51,7 @@ static void opPush(Program* program); static void opPushBase(Program* program); static void opPopBase(Program* program); static void opPopToBase(Program* program); -static void op802C(Program* program); +static void opSetGlobal(Program* program); static void opDump(Program* program); static void opDelayedCall(Program* program); static void opConditionalCall(Program* program); @@ -712,7 +712,7 @@ static void opPopToBase(Program* program) } // 0x467DE0 -static void op802C(Program* program) +static void opSetGlobal(Program* program) { program->basePointer = program->stackValues->size(); } @@ -2556,7 +2556,7 @@ void interpreterRegisterOpcodeHandlers() interpreterRegisterOpcode(OPCODE_POP_BASE, opPopBase); interpreterRegisterOpcode(OPCODE_POP_TO_BASE, opPopToBase); interpreterRegisterOpcode(OPCODE_PUSH_BASE, opPushBase); - interpreterRegisterOpcode(OPCODE_SET_GLOBAL, op802C); + interpreterRegisterOpcode(OPCODE_SET_GLOBAL, opSetGlobal); interpreterRegisterOpcode(OPCODE_FETCH_PROCEDURE_ADDRESS, opFetchProcedureAddress); interpreterRegisterOpcode(OPCODE_DUMP, opDump); interpreterRegisterOpcode(OPCODE_IF, opIf); diff --git a/src/object.cc b/src/object.cc index a597a76..4c46d21 100644 --- a/src/object.cc +++ b/src/object.cc @@ -2375,10 +2375,10 @@ bool _obj_occupied(int tile, int elevation) } // 0x48B848 -Object* _obj_blocking_at(Object* a1, int tile, int elev) +Object* _obj_blocking_at(Object* excludeObj, int tile, int elev) { ObjectListNode* objectListNode; - Object* v7; + Object* obj; int type; if (!hexGridTileIsValid(tile)) { @@ -2387,14 +2387,14 @@ Object* _obj_blocking_at(Object* a1, int tile, int elev) objectListNode = gObjectListHeadByTile[tile]; while (objectListNode != NULL) { - v7 = objectListNode->obj; - if (v7->elevation == elev) { - if ((v7->flags & OBJECT_HIDDEN) == 0 && (v7->flags & OBJECT_NO_BLOCK) == 0 && v7 != a1) { - type = FID_TYPE(v7->fid); + obj = objectListNode->obj; + if (obj->elevation == elev) { + if ((obj->flags & OBJECT_HIDDEN) == 0 && (obj->flags & OBJECT_NO_BLOCK) == 0 && obj != excludeObj) { + type = FID_TYPE(obj->fid); if (type == OBJ_TYPE_CRITTER || type == OBJ_TYPE_SCENERY || type == OBJ_TYPE_WALL) { - return v7; + return obj; } } } @@ -2406,15 +2406,15 @@ Object* _obj_blocking_at(Object* a1, int tile, int elev) if (hexGridTileIsValid(neighboor)) { objectListNode = gObjectListHeadByTile[neighboor]; while (objectListNode != NULL) { - v7 = objectListNode->obj; - if ((v7->flags & OBJECT_MULTIHEX) != 0) { - if (v7->elevation == elev) { - if ((v7->flags & OBJECT_HIDDEN) == 0 && (v7->flags & OBJECT_NO_BLOCK) == 0 && v7 != a1) { - type = FID_TYPE(v7->fid); + obj = objectListNode->obj; + if ((obj->flags & OBJECT_MULTIHEX) != 0) { + if (obj->elevation == elev) { + if ((obj->flags & OBJECT_HIDDEN) == 0 && (obj->flags & OBJECT_NO_BLOCK) == 0 && obj != excludeObj) { + type = FID_TYPE(obj->fid); if (type == OBJ_TYPE_CRITTER || type == OBJ_TYPE_SCENERY || type == OBJ_TYPE_WALL) { - return v7; + return obj; } } } @@ -2428,7 +2428,7 @@ Object* _obj_blocking_at(Object* a1, int tile, int elev) } // 0x48B930 -Object* _obj_shoot_blocking_at(Object* obj, int tile, int elev) +Object* _obj_shoot_blocking_at(Object* excludeObj, int tile, int elev) { if (!hexGridTileIsValid(tile)) { return NULL; @@ -2439,7 +2439,7 @@ Object* _obj_shoot_blocking_at(Object* obj, int tile, int elev) Object* candidate = objectListItem->obj; if (candidate->elevation == elev) { unsigned int flags = candidate->flags; - if ((flags & OBJECT_HIDDEN) == 0 && ((flags & OBJECT_NO_BLOCK) == 0 || (flags & OBJECT_SHOOT_THRU) == 0) && candidate != obj) { + if ((flags & OBJECT_HIDDEN) == 0 && ((flags & OBJECT_NO_BLOCK) == 0 || (flags & OBJECT_SHOOT_THRU) == 0) && candidate != excludeObj) { int type = FID_TYPE(candidate->fid); // SFALL: Fix to prevent corpses from blocking line of fire. if ((type == OBJ_TYPE_CRITTER && !critterIsDead(candidate)) @@ -2464,7 +2464,7 @@ Object* _obj_shoot_blocking_at(Object* obj, int tile, int elev) unsigned int flags = candidate->flags; if ((flags & OBJECT_MULTIHEX) != 0) { if (candidate->elevation == elev) { - if ((flags & OBJECT_HIDDEN) == 0 && (flags & OBJECT_NO_BLOCK) == 0 && candidate != obj) { + if ((flags & OBJECT_HIDDEN) == 0 && (flags & OBJECT_NO_BLOCK) == 0 && candidate != excludeObj) { int type = FID_TYPE(candidate->fid); // SFALL: Fix to prevent corpses from blocking line of // fire. @@ -2484,7 +2484,7 @@ Object* _obj_shoot_blocking_at(Object* obj, int tile, int elev) } // 0x48BA20 -Object* _obj_ai_blocking_at(Object* a1, int tile, int elevation) +Object* _obj_ai_blocking_at(Object* excludeObj, int tile, int elevation) { if (!hexGridTileIsValid(tile)) { return NULL; @@ -2496,7 +2496,7 @@ Object* _obj_ai_blocking_at(Object* a1, int tile, int elevation) if (object->elevation == elevation) { if ((object->flags & OBJECT_HIDDEN) == 0 && (object->flags & OBJECT_NO_BLOCK) == 0 - && object != a1) { + && object != excludeObj) { int objectType = FID_TYPE(object->fid); if (objectType == OBJ_TYPE_CRITTER || objectType == OBJ_TYPE_SCENERY @@ -2525,7 +2525,7 @@ Object* _obj_ai_blocking_at(Object* a1, int tile, int elevation) if (object->elevation == elevation) { if ((object->flags & OBJECT_HIDDEN) == 0 && (object->flags & OBJECT_NO_BLOCK) == 0 - && object != a1) { + && object != excludeObj) { int objectType = FID_TYPE(object->fid); if (objectType == OBJ_TYPE_CRITTER || objectType == OBJ_TYPE_SCENERY @@ -2571,7 +2571,7 @@ int _obj_scroll_blocking_at(int tile, int elev) } // 0x48BB88 -Object* _obj_sight_blocking_at(Object* a1, int tile, int elevation) +Object* _obj_sight_blocking_at(Object* excludeObj, int tile, int elevation) { ObjectListNode* objectListNode = gObjectListHeadByTile[tile]; while (objectListNode != NULL) { @@ -2579,7 +2579,7 @@ Object* _obj_sight_blocking_at(Object* a1, int tile, int elevation) if (object->elevation == elevation && (object->flags & OBJECT_HIDDEN) == 0 && (object->flags & OBJECT_LIGHT_THRU) == 0 - && object != a1) { + && object != excludeObj) { int objectType = FID_TYPE(object->fid); if (objectType == OBJ_TYPE_SCENERY || objectType == OBJ_TYPE_WALL) { return object; diff --git a/src/object.h b/src/object.h index c397317..f9ccfb5 100644 --- a/src/object.h +++ b/src/object.h @@ -71,11 +71,11 @@ Object* objectFindFirstAtLocation(int elevation, int tile); Object* objectFindNextAtLocation(); void objectGetRect(Object* obj, Rect* rect); bool _obj_occupied(int tile_num, int elev); -Object* _obj_blocking_at(Object* a1, int tile_num, int elev); -Object* _obj_shoot_blocking_at(Object* obj, int tile, int elev); -Object* _obj_ai_blocking_at(Object* a1, int tile, int elevation); +Object* _obj_blocking_at(Object* excludeObj, int tile_num, int elev); +Object* _obj_shoot_blocking_at(Object* excludeObj, int tile, int elev); +Object* _obj_ai_blocking_at(Object* excludeObj, int tile, int elevation); int _obj_scroll_blocking_at(int tile_num, int elev); -Object* _obj_sight_blocking_at(Object* a1, int tile_num, int elev); +Object* _obj_sight_blocking_at(Object* excludeObj, int tile_num, int elev); int objectGetDistanceBetween(Object* object1, Object* object2); int objectGetDistanceBetweenTiles(Object* object1, int tile1, Object* object2, int tile2); int objectListCreate(int tile, int elevation, int objectType, Object*** objectsPtr);