diff --git a/src/actions.cc b/src/actions.cc index 292e5ce..e7dfc1d 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -85,7 +85,7 @@ static int _is_next_to(Object* a1, Object* a2); static int _action_climb_ladder(Object* a1, Object* a2); static int _action_use_skill_in_combat_error(Object* critter); static int _pick_fall(Object* obj, int anim); -static int _report_explosion(Attack* attack, Object* a2); +static int _report_explosion(Attack* attack, Object* sourceObj); static int _finished_explosion(Object* a1, Object* a2); static int _compute_explosion_damage(int min, int max, Object* defender, int* knockbackDistancePtr); static int _can_talk_to(Object* a1, Object* a2); @@ -1576,9 +1576,9 @@ bool _action_explode_running() // action_explode // 0x412CF4 -int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* a5, bool a6) +int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* sourceObj, bool animate) { - if (a6 && _action_in_explode) { + if (animate && _action_in_explode) { return -2; } @@ -1653,7 +1653,7 @@ int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* attackComputeDeathFlags(attack); - if (a6) { + if (animate) { _action_in_explode = true; reg_anim_begin(ANIMATION_REQUEST_RESERVED); @@ -1675,7 +1675,7 @@ int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* animationRegisterHideObjectForced(adjacentExplosions[rotation]); } - animationRegisterCallbackForced(attack, a5, (AnimationCallback*)_report_explosion, -1); + animationRegisterCallbackForced(attack, sourceObj, (AnimationCallback*)_report_explosion, -1); animationRegisterCallbackForced(NULL, NULL, (AnimationCallback*)_finished_explosion, -1); if (reg_anim_end() == -1) { _action_in_explode = false; @@ -1706,7 +1706,7 @@ int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* } } - _report_explosion(attack, a5); + _report_explosion(attack, sourceObj); _combat_explode_scenery(explosion, NULL); @@ -1721,7 +1721,7 @@ int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* } // 0x413144 -int _report_explosion(Attack* attack, Object* a2) +int _report_explosion(Attack* attack, Object* sourceObj) { bool mainTargetWasDead; if (attack->defender != NULL) { @@ -1741,27 +1741,27 @@ int _report_explosion(Attack* attack, Object* a2) Object* anyDefender = NULL; int xp = 0; - if (a2 != NULL) { - if (attack->defender != NULL && attack->defender != a2) { + if (sourceObj != NULL) { + if (attack->defender != NULL && attack->defender != sourceObj) { if ((attack->defender->data.critter.combat.results & DAM_DEAD) != 0) { - if (a2 == gDude && !mainTargetWasDead) { + if (sourceObj == gDude && !mainTargetWasDead) { xp += critterGetExp(attack->defender); } } else { - _critter_set_who_hit_me(attack->defender, a2); + _critter_set_who_hit_me(attack->defender, sourceObj); anyDefender = attack->defender; } } for (int index = 0; index < attack->extrasLength; index++) { Object* critter = attack->extras[index]; - if (critter != a2) { + if (critter != sourceObj) { if ((critter->data.critter.combat.results & DAM_DEAD) != 0) { - if (a2 == gDude && !extrasWasDead[index]) { + if (sourceObj == gDude && !extrasWasDead[index]) { xp += critterGetExp(critter); } } else { - _critter_set_who_hit_me(critter, a2); + _critter_set_who_hit_me(critter, sourceObj); if (anyDefender == NULL) { anyDefender = critter; @@ -1772,15 +1772,15 @@ int _report_explosion(Attack* attack, Object* a2) if (anyDefender != NULL) { if (!isInCombat()) { - STRUCT_664980 combat; + CombatStartData combat; combat.attacker = anyDefender; - combat.defender = a2; + combat.defender = sourceObj; combat.actionPointsBonus = 0; combat.accuracyBonus = 0; combat.damageBonus = 0; combat.minDamage = 0; combat.maxDamage = INT_MAX; - combat.field_1C = 0; + combat.overrideAttackResults = 0; scriptsRequestCombat(&combat); } } @@ -1789,7 +1789,7 @@ int _report_explosion(Attack* attack, Object* a2) internal_free(attack); gameUiEnable(); - if (a2 == gDude) { + if (sourceObj == gDude) { _combat_give_exps(xp); } diff --git a/src/actions.h b/src/actions.h index 88d8ae0..1794f93 100644 --- a/src/actions.h +++ b/src/actions.h @@ -16,7 +16,7 @@ int actionUseSkill(Object* a1, Object* a2, int skill); bool _is_hit_from_front(Object* attacker, Object* defender); bool _can_see(Object* a1, Object* a2); bool _action_explode_running(); -int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* a5, bool a6); +int actionExplode(int tile, int elevation, int minDamage, int maxDamage, Object* sourceObj, bool animate); int actionTalk(Object* a1, Object* a2); void actionDamage(int tile, int elevation, int minDamage, int maxDamage, int damageType, bool animated, bool bypassArmor); bool actionCheckPush(Object* a1, Object* a2); diff --git a/src/combat.cc b/src/combat.cc index 70098c0..20dc5e3 100644 --- a/src/combat.cc +++ b/src/combat.cc @@ -94,13 +94,13 @@ static bool _combat_safety_invalidate_weapon_func(Object* attacker, Object* weap static void _combatInitAIInfoList(); static int aiInfoCopy(int srcIndex, int destIndex); static int _combatAIInfoSetLastMove(Object* object, int move); -static void _combat_begin(Object* a1); -static void _combat_begin_extra(Object* a1); +static void _combat_begin(Object* attacker); +static void _combat_begin_extra(Object* attacker); static void _combat_update_critters_in_los(bool a1); static void _combat_over(); static void _combat_add_noncoms(); -static int _compare_faster(const void* a1, const void* a2); -static void _combat_sequence_init(Object* a1, Object* a2); +static int _compare_faster(const void* critter1Ptr, const void* critter2Ptr); +static void _combat_sequence_init(Object* attacker, Object* defender); static void _combat_sequence(); static void combatAttemptEnd(); static int _combat_input(); @@ -161,7 +161,7 @@ unsigned int gCombatState = COMBAT_STATE_0x02; static CombatAiInfo* _aiInfoList = NULL; // 0x51094C -static STRUCT_664980* _gcsd = NULL; +static CombatStartData* _gcsd = NULL; // 0x510950 static bool _combat_call_display = false; @@ -2560,7 +2560,7 @@ static int _combatAIInfoSetLastMove(Object* object, int move) } // 0x421A34 -static void _combat_begin(Object* a1) +static void _combat_begin(Object* attacker) { _combat_turn_running = 0; animationStop(); @@ -2610,7 +2610,7 @@ static void _combat_begin(Object* a1) gameUiDisable(0); gameMouseSetCursor(MOUSE_CURSOR_WAIT_WATCH); _combat_ending_guy = NULL; - _combat_begin_extra(a1); + _combat_begin_extra(attacker); _caiTeamCombatInit(_combat_list, _list_total); interfaceBarEndButtonsShow(true); _gmouse_enable_scrolling(); @@ -2636,15 +2636,15 @@ static void _combat_begin(Object* a1) } // 0x421C8C -static void _combat_begin_extra(Object* a1) +static void _combat_begin_extra(Object* attacker) { for (int index = 0; index < _list_total; index++) { _combat_update_critter_outline_for_los(_combat_list[index], 0); } - attackInit(&_main_ctd, a1, NULL, 4, 3); + attackInit(&_main_ctd, attacker, NULL, 4, 3); - _combat_turn_obj = a1; + _combat_turn_obj = attacker; _combat_ai_begin(_list_total, _combat_list); @@ -2933,21 +2933,21 @@ static void _combat_add_noncoms() // Compares critters by sequence. // // 0x4223C8 -static int _compare_faster(const void* a1, const void* a2) +static int _compare_faster(const void* critter1Ptr, const void* critter2Ptr) { - Object* v1 = *(Object**)a1; - Object* v2 = *(Object**)a2; + Object* critter1 = *(Object**)critter1Ptr; + Object* critter2 = *(Object**)critter2Ptr; - int sequence1 = critterGetStat(v1, STAT_SEQUENCE); - int sequence2 = critterGetStat(v2, STAT_SEQUENCE); + int sequence1 = critterGetStat(critter1, STAT_SEQUENCE); + int sequence2 = critterGetStat(critter2, STAT_SEQUENCE); if (sequence1 > sequence2) { return -1; } else if (sequence1 < sequence2) { return 1; } - int luck1 = critterGetStat(v1, STAT_LUCK); - int luck2 = critterGetStat(v2, STAT_LUCK); + int luck1 = critterGetStat(critter1, STAT_LUCK); + int luck2 = critterGetStat(critter2, STAT_LUCK); if (luck1 > luck2) { return -1; } else if (luck1 < luck2) { @@ -2957,14 +2957,17 @@ static int _compare_faster(const void* a1, const void* a2) return 0; } +// Initializes combat sequence for the first round. +// // 0x42243C -static void _combat_sequence_init(Object* a1, Object* a2) +static void _combat_sequence_init(Object* attacker, Object* defender) { + // Always place attacker first (swap with critter at 0 index). int next = 0; - if (a1 != NULL) { + if (attacker != NULL) { for (int index = 0; index < _list_total; index++) { Object* obj = _combat_list[index]; - if (obj == a1) { + if (obj == attacker) { Object* temp = _combat_list[next]; _combat_list[index] = temp; _combat_list[next] = obj; @@ -2974,10 +2977,11 @@ static void _combat_sequence_init(Object* a1, Object* a2) } } - if (a2 != NULL) { + // Place defender second. + if (defender != NULL) { for (int index = 0; index < _list_total; index++) { Object* obj = _combat_list[index]; - if (obj == a2) { + if (obj == defender) { Object* temp = _combat_list[next]; _combat_list[index] = temp; _combat_list[next] = obj; @@ -2987,7 +2991,8 @@ static void _combat_sequence_init(Object* a1, Object* a2) } } - if (a1 != gDude && a2 != gDude) { + // Place dude third, if he's neither attacker, nor defender. + if (attacker != gDude && defender != gDude) { for (int index = 0; index < _list_total; index++) { Object* obj = _combat_list[index]; if (obj == gDude) { @@ -3003,15 +3008,17 @@ static void _combat_sequence_init(Object* a1, Object* a2) _list_com = next; _list_noncom -= next; - if (a1 != NULL) { - _critter_set_who_hit_me(a1, a2); + if (attacker != NULL) { + _critter_set_who_hit_me(attacker, defender); } - if (a2 != NULL) { - _critter_set_who_hit_me(a2, a1); + if (defender != NULL) { + _critter_set_who_hit_me(defender, attacker); } } +// Updates combat sequence for the next round. +// // 0x422580 static void _combat_sequence() { @@ -3019,6 +3026,7 @@ static void _combat_sequence() int count = _list_com; + // Remove dead critters from the combatant list. for (int index = 0; index < count; index++) { Object* critter = _combat_list[index]; if ((critter->data.critter.combat.results & DAM_DEAD) != 0) { @@ -3033,6 +3041,7 @@ static void _combat_sequence() } } + // Move knocked out and disengaged critters to non-combatant list. for (int index = 0; index < count; index++) { Object* critter = _combat_list[index]; if (critter != gDude) { @@ -3050,6 +3059,7 @@ static void _combat_sequence() } } + // Sort combatant list based on Sequence stat. if (count != 0) { _list_com = count; qsort(_combat_list, count, sizeof(*_combat_list), _compare_faster); @@ -3212,16 +3222,16 @@ static void _combat_set_move_all() } // 0x42299C -static int _combat_turn(Object* a1, bool a2) +static int _combat_turn(Object* obj, bool a2) { - _combat_turn_obj = a1; + _combat_turn_obj = obj; - attackInit(&_main_ctd, a1, NULL, HIT_MODE_PUNCH, HIT_LOCATION_TORSO); + attackInit(&_main_ctd, obj, NULL, HIT_MODE_PUNCH, HIT_LOCATION_TORSO); - if ((a1->data.critter.combat.results & (DAM_KNOCKED_OUT | DAM_DEAD | DAM_LOSE_TURN)) != 0) { - a1->data.critter.combat.results &= ~DAM_LOSE_TURN; + if ((obj->data.critter.combat.results & (DAM_KNOCKED_OUT | DAM_DEAD | DAM_LOSE_TURN)) != 0) { + obj->data.critter.combat.results &= ~DAM_LOSE_TURN; } else { - if (a1 == gDude) { + if (obj == gDude) { keyboardReset(); interfaceRenderArmorClass(true); _combat_free_move = 2 * perkGetRank(gDude, PERK_BONUS_MOVE); @@ -3231,13 +3241,13 @@ static int _combat_turn(Object* a1, bool a2) } bool scriptOverrides = false; - if (a1->sid != -1) { - scriptSetObjects(a1->sid, NULL, NULL); - scriptSetFixedParam(a1->sid, 4); - scriptExecProc(a1->sid, SCRIPT_PROC_COMBAT); + if (obj->sid != -1) { + scriptSetObjects(obj->sid, NULL, NULL); + scriptSetFixedParam(obj->sid, 4); + scriptExecProc(obj->sid, SCRIPT_PROC_COMBAT); Script* scr; - if (scriptGetScript(a1->sid, &scr) != -1) { + if (scriptGetScript(obj->sid, &scr) != -1) { scriptOverrides = scr->scriptOverrides; } @@ -3247,11 +3257,11 @@ static int _combat_turn(Object* a1, bool a2) } if (!scriptOverrides) { - if (!a2 && _critter_is_prone(a1)) { - _combat_standup(a1); + if (!a2 && _critter_is_prone(obj)) { + _combat_standup(obj); } - if (a1 == gDude) { + if (obj == gDude) { gameUiEnable(); _gmouse_3d_refresh(); @@ -3275,7 +3285,7 @@ static int _combat_turn(Object* a1, bool a2) if (_combat_input() == -1) { gameUiDisable(1); gameMouseSetCursor(MOUSE_CURSOR_WAIT_WATCH); - a1->data.critter.combat.damageLastTurn = 0; + obj->data.critter.combat.damageLastTurn = 0; interfaceBarEndButtonsRenderRedLights(); _combat_outline_off(); interfaceRenderActionPoints(-1, -1); @@ -3285,18 +3295,18 @@ static int _combat_turn(Object* a1, bool a2) } } else { Rect rect; - if (objectEnableOutline(a1, &rect) == 0) { - tileWindowRefreshRect(&rect, a1->elevation); + if (objectEnableOutline(obj, &rect) == 0) { + tileWindowRefreshRect(&rect, obj->elevation); } - _combat_ai(a1, _gcsd != NULL ? _gcsd->defender : NULL); + _combat_ai(obj, _gcsd != NULL ? _gcsd->defender : NULL); } } // NOTE: Uninline. _combat_turn_run(); - if (a1 == gDude) { + if (obj == gDude) { gameUiDisable(1); gameMouseSetCursor(MOUSE_CURSOR_WAIT_WATCH); interfaceBarEndButtonsRenderRedLights(); @@ -3307,8 +3317,8 @@ static int _combat_turn(Object* a1, bool a2) _combat_turn_obj = gDude; } else { Rect rect; - if (objectDisableOutline(a1, &rect) == 0) { - tileWindowRefreshRect(&rect, a1->elevation); + if (objectDisableOutline(obj, &rect) == 0) { + tileWindowRefreshRect(&rect, obj->elevation); } } } @@ -3317,7 +3327,7 @@ static int _combat_turn(Object* a1, bool a2) return -1; } - if (a1 != gDude || _combat_elev == gDude->elevation) { + if (obj != gDude || _combat_elev == gDude->elevation) { _combat_free_move = 0; return 0; } @@ -3365,23 +3375,23 @@ static bool _combat_should_end() } // 0x422D2C -void _combat(STRUCT_664980* attack) +void _combat(CombatStartData* csd) { ScopedGameMode gm(GameMode::kCombat); - if (attack == NULL - || (attack->attacker == NULL || attack->attacker->elevation == gElevation) - || (attack->defender == NULL || attack->defender->elevation == gElevation)) { - int v3 = gCombatState & 0x01; + if (csd == NULL + || (csd->attacker == NULL || csd->attacker->elevation == gElevation) + || (csd->defender == NULL || csd->defender->elevation == gElevation)) { + bool wasInCombat = (gCombatState & 0x01) != 0; _combat_begin(NULL); - int v6; + int curIndex; - // TODO: Not sure. - if (v3 != 0) { + // If we loaded a save in combat, we need to force dude turn and then continue with the next combatant. + if (wasInCombat) { if (_combat_turn(gDude, true) == -1) { - v6 = -1; + curIndex = -1; } else { int index; for (index = 0; index < _list_com; index++) { @@ -3389,33 +3399,33 @@ void _combat(STRUCT_664980* attack) break; } } - v6 = index + 1; + curIndex = index + 1; } _gcsd = NULL; } else { - Object* v3; - Object* v9; - if (attack != NULL) { - v3 = attack->defender; - v9 = attack->attacker; + Object* defender; + Object* attacker; + if (csd != NULL) { + defender = csd->defender; + attacker = csd->attacker; } else { - v3 = NULL; - v9 = NULL; + defender = NULL; + attacker = NULL; } - _combat_sequence_init(v9, v3); - _gcsd = attack; - v6 = 0; + _combat_sequence_init(attacker, defender); + _gcsd = csd; + curIndex = 0; } do { - if (v6 == -1) { + if (curIndex == -1) { break; } _combat_set_move_all(); - for (; v6 < _list_com; v6++) { - if (_combat_turn(_combat_list[v6], false) == -1) { + for (; curIndex < _list_com; curIndex++) { + if (_combat_turn(_combat_list[curIndex], false) == -1) { break; } @@ -3426,12 +3436,12 @@ void _combat(STRUCT_664980* attack) _gcsd = NULL; } - if (v6 < _list_com) { + if (curIndex < _list_com) { break; } _combat_sequence(); - v6 = 0; + curIndex = 0; _combatNumTurns += 1; } while (!_combat_should_end()); @@ -3503,11 +3513,11 @@ int _combat_attack(Object* attacker, Object* defender, int hitMode, int hitLocat _main_ctd.defenderDamage = _gcsd->maxDamage; } - if (_gcsd->field_1C) { + if (_gcsd->overrideAttackResults) { // FIXME: looks like a bug, two different fields are used to set // one field. - _main_ctd.defenderFlags = _gcsd->field_20; - _main_ctd.defenderFlags = _gcsd->field_24; + _main_ctd.defenderFlags = _gcsd->attackerResults; + _main_ctd.defenderFlags = _gcsd->targetResults; } } @@ -5700,9 +5710,9 @@ bool _combat_to_hit(Object* target, int* accuracy) } // 0x4267CC -void _combat_attack_this(Object* a1) +void _combat_attack_this(Object* target) { - if (a1 == NULL) { + if (target == NULL) { return; } @@ -5721,7 +5731,7 @@ void _combat_attack_this(Object* a1) char formattedText[80]; const char* sfx; - int rc = _combat_check_bad_shot(gDude, a1, hitMode, aiming); + int rc = _combat_check_bad_shot(gDude, target, hitMode, aiming); switch (rc) { case COMBAT_BAD_SHOT_NO_AMMO: item = critterGetWeaponForHitMode(gDude, hitMode); @@ -5771,21 +5781,21 @@ void _combat_attack_this(Object* a1) } if (!isInCombat()) { - STRUCT_664980 stru; - stru.attacker = gDude; - stru.defender = a1; - stru.actionPointsBonus = 0; - stru.accuracyBonus = 0; - stru.damageBonus = 0; - stru.minDamage = 0; - stru.maxDamage = INT_MAX; - stru.field_1C = 0; - _combat(&stru); + CombatStartData combat; + combat.attacker = gDude; + combat.defender = target; + combat.actionPointsBonus = 0; + combat.accuracyBonus = 0; + combat.damageBonus = 0; + combat.minDamage = 0; + combat.maxDamage = INT_MAX; + combat.overrideAttackResults = 0; + _combat(&combat); return; } if (!aiming) { - _combat_attack(gDude, a1, hitMode, HIT_LOCATION_UNCALLED); + _combat_attack(gDude, target, hitMode, HIT_LOCATION_UNCALLED); return; } @@ -5794,8 +5804,8 @@ void _combat_attack_this(Object* a1) } int hitLocation; - if (calledShotSelectHitLocation(a1, &hitLocation, hitMode) != -1) { - _combat_attack(gDude, a1, hitMode, hitLocation); + if (calledShotSelectHitLocation(target, &hitLocation, hitMode) != -1) { + _combat_attack(gDude, target, hitMode, hitLocation); } } diff --git a/src/combat.h b/src/combat.h index 2438b37..43e9ca2 100644 --- a/src/combat.h +++ b/src/combat.h @@ -33,7 +33,7 @@ void _combat_update_critter_outline_for_los(Object* critter, bool a2); void _combat_over_from_load(); void _combat_give_exps(int exp_points); void _combat_turn_run(); -void _combat(STRUCT_664980* attack); +void _combat(CombatStartData* attack); void attackInit(Attack* attack, Object* attacker, Object* defender, int hitMode, int hitLocation); int _combat_attack(Object* attacker, Object* defender, int hitMode, int hitLocation); int _combat_bullet_start(const Object* attacker, const Object* target); @@ -48,7 +48,7 @@ void _combat_anim_begin(); void _combat_anim_finished(); int _combat_check_bad_shot(Object* attacker, Object* defender, int hitMode, bool aiming); bool _combat_to_hit(Object* target, int* accuracy); -void _combat_attack_this(Object* a1); +void _combat_attack_this(Object* target); void _combat_outline_on(); void _combat_outline_off(); void _combat_highlight_change(); diff --git a/src/combat_ai.cc b/src/combat_ai.cc index 3ee2082..701a718 100644 --- a/src/combat_ai.cc +++ b/src/combat_ai.cc @@ -3472,22 +3472,22 @@ void _combatai_check_retaliation(Object* a1, Object* a2) } // 0x42BA04 -bool isWithinPerception(Object* a1, Object* a2) +bool isWithinPerception(Object* critter, Object* target) { - if (a2 == NULL) { + if (target == NULL) { return false; } - int distance = objectGetDistanceBetween(a2, a1); - int perception = critterGetStat(a1, STAT_PERCEPTION); - int sneak = skillGetValue(a2, SKILL_SNEAK); - if (_can_see(a1, a2)) { + int distance = objectGetDistanceBetween(target, critter); + int perception = critterGetStat(critter, STAT_PERCEPTION); + int sneak = skillGetValue(target, SKILL_SNEAK); + if (_can_see(critter, target)) { int maxDistance = perception * 5; - if ((a2->flags & OBJECT_TRANS_GLASS) != 0) { + if ((target->flags & OBJECT_TRANS_GLASS) != 0) { maxDistance /= 2; } - if (a2 == gDude) { + if (target == gDude) { if (dudeIsSneaking()) { maxDistance /= 4; if (sneak > 120) { @@ -3510,7 +3510,7 @@ bool isWithinPerception(Object* a1, Object* a2) maxDistance = perception; } - if (a2 == gDude) { + if (target == gDude) { if (dudeIsSneaking()) { maxDistance /= 4; if (sneak > 120) { diff --git a/src/combat_defs.h b/src/combat_defs.h index b726418..c37e23c 100644 --- a/src/combat_defs.h +++ b/src/combat_defs.h @@ -86,7 +86,7 @@ typedef enum HitLocation { HIT_LOCATION_SPECIFIC_COUNT = HIT_LOCATION_COUNT - 1, } HitLocation; -typedef struct STRUCT_664980 { +typedef struct CombatStartData { Object* attacker; Object* defender; int actionPointsBonus; @@ -94,10 +94,10 @@ typedef struct STRUCT_664980 { int damageBonus; int minDamage; int maxDamage; - int field_1C; // probably bool, indicating field_20 and field_24 used - int field_20; // flags on attacker - int field_24; // flags on defender -} STRUCT_664980; + int overrideAttackResults; + int attackerResults; + int targetResults; +} CombatStartData; typedef struct Attack { Object* attacker; diff --git a/src/interpreter_extra.cc b/src/interpreter_extra.cc index b2d3295..73e02e5 100644 --- a/src/interpreter_extra.cc +++ b/src/interpreter_extra.cc @@ -1858,7 +1858,7 @@ static void opAttackComplex(Program* program) combatData->whoHitMe = target; } } else { - STRUCT_664980 attack; + CombatStartData attack; attack.attacker = self; attack.defender = target; attack.actionPointsBonus = 0; @@ -1871,11 +1871,11 @@ static void opAttackComplex(Program* program) // flags to be the same? Maybe because both of them // are applied to defender because of the bug in 0x422F3C? if (data[1] == data[0]) { - attack.field_1C = 1; - attack.field_24 = data[0]; - attack.field_20 = data[1]; + attack.overrideAttackResults = 1; + attack.targetResults = data[0]; + attack.attackerResults = data[1]; } else { - attack.field_1C = 0; + attack.overrideAttackResults = 0; } scriptsRequestCombat(&attack); @@ -4445,7 +4445,7 @@ static void opAttackSetup(Program* program) attacker->data.critter.combat.whoHitMe = defender; } } else { - STRUCT_664980 attack; + CombatStartData attack; attack.attacker = attacker; attack.defender = defender; attack.actionPointsBonus = 0; @@ -4453,7 +4453,7 @@ static void opAttackSetup(Program* program) attack.damageBonus = 0; attack.minDamage = 0; attack.maxDamage = INT_MAX; - attack.field_1C = 0; + attack.overrideAttackResults = 0; scriptsRequestCombat(&attack); } diff --git a/src/inventory.cc b/src/inventory.cc index beb2132..a42eb26 100644 --- a/src/inventory.cc +++ b/src/inventory.cc @@ -240,7 +240,7 @@ typedef struct InventoryCursorData { typedef enum InventoryMoveResult { INVENTORY_MOVE_RESULT_FAILED, - INVENTORY_MOVE_RESULT_COUGHT_STEALING, + INVENTORY_MOVE_RESULT_CAUGHT_STEALING, INVENTORY_MOVE_RESULT_SUCCESS, }; @@ -1555,38 +1555,38 @@ static void _exit_inventory(bool shouldEnableIso) _gmouse_enable(); if (_dropped_explosive) { - Attack v1; - attackInit(&v1, gDude, NULL, HIT_MODE_PUNCH, HIT_LOCATION_TORSO); - v1.attackerFlags = DAM_HIT; - v1.tile = gDude->tile; - _compute_explosion_on_extras(&v1, 0, 0, 1); + Attack attack; + attackInit(&attack, gDude, NULL, HIT_MODE_PUNCH, HIT_LOCATION_TORSO); + attack.attackerFlags = DAM_HIT; + attack.tile = gDude->tile; + _compute_explosion_on_extras(&attack, 0, 0, 1); - Object* v2 = NULL; - for (int index = 0; index < v1.extrasLength; index++) { - Object* critter = v1.extras[index]; + Object* watcher = NULL; + for (int index = 0; index < attack.extrasLength; index++) { + Object* critter = attack.extras[index]; if (critter != gDude && critter->data.critter.combat.team != gDude->data.critter.combat.team && statRoll(critter, STAT_PERCEPTION, 0, NULL) >= ROLL_SUCCESS) { _critter_set_who_hit_me(critter, gDude); - if (v2 == NULL) { - v2 = critter; + if (watcher == NULL) { + watcher = critter; } } } - if (v2 != NULL) { + if (watcher != NULL) { if (!isInCombat()) { - STRUCT_664980 v3; - v3.attacker = v2; - v3.defender = gDude; - v3.actionPointsBonus = 0; - v3.accuracyBonus = 0; - v3.damageBonus = 0; - v3.minDamage = 0; - v3.maxDamage = INT_MAX; - v3.field_1C = 0; - scriptsRequestCombat(&v3); + CombatStartData combat; + combat.attacker = watcher; + combat.defender = gDude; + combat.actionPointsBonus = 0; + combat.accuracyBonus = 0; + combat.damageBonus = 0; + combat.minDamage = 0; + combat.maxDamage = INT_MAX; + combat.overrideAttackResults = 0; + scriptsRequestCombat(&combat); } } @@ -4350,7 +4350,7 @@ int inventoryOpenLooting(Object* looter, Object* target) InventoryItem* inventoryItem = &(_pud->items[_pud->length - (slotIndex + _stack_offset[_curr_stack] + 1)]); InventoryMoveResult rc = _move_inventory(inventoryItem->item, slotIndex, _target_stack[_target_curr_stack], true); - if (rc == INVENTORY_MOVE_RESULT_COUGHT_STEALING) { + if (rc == INVENTORY_MOVE_RESULT_CAUGHT_STEALING) { isCaughtStealing = true; } else if (rc == INVENTORY_MOVE_RESULT_SUCCESS) { stealingXp += stealingXpBonus; @@ -4374,7 +4374,7 @@ int inventoryOpenLooting(Object* looter, Object* target) InventoryItem* inventoryItem = &(_target_pud->items[_target_pud->length - (slotIndex + _target_stack_offset[_target_curr_stack] + 1)]); InventoryMoveResult rc = _move_inventory(inventoryItem->item, slotIndex, _target_stack[_target_curr_stack], false); - if (rc == INVENTORY_MOVE_RESULT_COUGHT_STEALING) { + if (rc == INVENTORY_MOVE_RESULT_CAUGHT_STEALING) { isCaughtStealing = true; } else if (rc == INVENTORY_MOVE_RESULT_SUCCESS) { stealingXp += stealingXpBonus; @@ -4598,11 +4598,11 @@ static InventoryMoveResult _move_inventory(Object* item, int slotIndex, Object* if (quantityToMove != -1) { if (_gIsSteal) { if (skillsPerformStealing(_inven_dude, targetObj, item, true) == 0) { - result = INVENTORY_MOVE_RESULT_COUGHT_STEALING; + result = INVENTORY_MOVE_RESULT_CAUGHT_STEALING; } } - if (result != INVENTORY_MOVE_RESULT_COUGHT_STEALING) { + if (result != INVENTORY_MOVE_RESULT_CAUGHT_STEALING) { if (itemMove(_inven_dude, targetObj, item, quantityToMove) != -1) { result = INVENTORY_MOVE_RESULT_SUCCESS; } else { @@ -4627,11 +4627,11 @@ static InventoryMoveResult _move_inventory(Object* item, int slotIndex, Object* if (quantityToMove != -1) { if (_gIsSteal) { if (skillsPerformStealing(_inven_dude, targetObj, item, false) == 0) { - result = INVENTORY_MOVE_RESULT_COUGHT_STEALING; + result = INVENTORY_MOVE_RESULT_CAUGHT_STEALING; } } - if (result != INVENTORY_MOVE_RESULT_COUGHT_STEALING) { + if (result != INVENTORY_MOVE_RESULT_CAUGHT_STEALING) { if (itemMove(targetObj, _inven_dude, item, quantityToMove) == 0) { if ((item->flags & OBJECT_IN_RIGHT_HAND) != 0) { targetObj->fid = buildFid(FID_TYPE(targetObj->fid), targetObj->fid & 0xFFF, FID_ANIM_TYPE(targetObj->fid), 0, targetObj->rotation + 1); diff --git a/src/proto_instance.cc b/src/proto_instance.cc index 0c57d8a..5fc173a 100644 --- a/src/proto_instance.cc +++ b/src/proto_instance.cc @@ -1083,29 +1083,29 @@ static int _protinstTestDroppedExplosive(Object* a1) _compute_explosion_on_extras(&attack, 0, 0, 1); int team = gDude->data.critter.combat.team; - Object* v2 = NULL; + Object* watcher = NULL; for (int index = 0; index < attack.extrasLength; index++) { Object* v5 = attack.extras[index]; if (v5 != gDude && v5->data.critter.combat.team != team && statRoll(v5, STAT_PERCEPTION, 0, NULL) >= 2) { _critter_set_who_hit_me(v5, gDude); - if (v2 == NULL) { - v2 = v5; + if (watcher == NULL) { + watcher = v5; } } } - if (v2 != NULL && !isInCombat()) { - STRUCT_664980 attack; - attack.attacker = v2; - attack.defender = gDude; - attack.actionPointsBonus = 0; - attack.accuracyBonus = 0; - attack.minDamage = 0; - attack.maxDamage = 99999; - attack.field_1C = 0; - scriptsRequestCombat(&attack); + if (watcher != NULL && !isInCombat()) { + CombatStartData combat; + combat.attacker = watcher; + combat.defender = gDude; + combat.actionPointsBonus = 0; + combat.accuracyBonus = 0; + combat.minDamage = 0; + combat.maxDamage = 99999; + combat.overrideAttackResults = 0; + scriptsRequestCombat(&combat); } } return 0; diff --git a/src/queue.cc b/src/queue.cc index 42d6bf9..510720f 100644 --- a/src/queue.cc +++ b/src/queue.cc @@ -37,7 +37,7 @@ typedef struct EventTypeDescription { static int flareEventProcess(Object* obj, void* data); static int explosionEventProcess(Object* obj, void* data); static int _queue_explode_exit(Object* obj, void* data); -static int _queue_do_explosion_(Object* obj, bool a2); +static int _queue_do_explosion_(Object* obj, bool animate); static int explosionFailureEventProcess(Object* obj, void* data); // Last queue list node found during [queueFindFirstEvent] and @@ -454,7 +454,7 @@ static int _queue_explode_exit(Object* obj, void* data) } // 0x4A2834 -static int _queue_do_explosion_(Object* explosive, bool a2) +static int _queue_do_explosion_(Object* explosive, bool animate) { int tile; int elevation; @@ -483,7 +483,7 @@ static int _queue_do_explosion_(Object* explosive, bool a2) } } - if (actionExplode(tile, elevation, minDamage, maxDamage, gDude, a2) == -2) { + if (actionExplode(tile, elevation, minDamage, maxDamage, gDude, animate) == -2) { queueAddEvent(50, explosive, NULL, EVENT_TYPE_EXPLOSION); } else { _obj_destroy(explosive); diff --git a/src/scripts.cc b/src/scripts.cc index ddcf5c6..d1b3713 100644 --- a/src/scripts.cc +++ b/src/scripts.cc @@ -213,10 +213,10 @@ static char* _blank_str = byte_50D6C0; static unsigned int gScriptsRequests; // 0x664958 -static STRUCT_664980 stru_664958; +static CombatStartData gScriptsRequestedCSD; // 0x664980 -static STRUCT_664980 stru_664980; +static CombatStartData gScriptsCSD; // 0x6649A8 static int gScriptsRequestedElevatorType; @@ -884,7 +884,7 @@ static int scriptsClearPendingRequests() // 0x4A3F90 int _scripts_clear_combat_requests(Script* script) { - if ((gScriptsRequests & SCRIPT_REQUEST_COMBAT) != 0 && stru_664958.attacker == script->owner) { + if ((gScriptsRequests & SCRIPT_REQUEST_COMBAT) != 0 && gScriptsRequestedCSD.attacker == script->owner) { gScriptsRequests &= ~(SCRIPT_REQUEST_0x0400 | SCRIPT_REQUEST_COMBAT); } return 0; @@ -901,14 +901,14 @@ int scriptsHandleRequests() if (!_action_explode_running()) { // entering combat gScriptsRequests &= ~(SCRIPT_REQUEST_0x0400 | SCRIPT_REQUEST_COMBAT); - memcpy(&stru_664980, &stru_664958, sizeof(stru_664980)); + memcpy(&gScriptsCSD, &gScriptsRequestedCSD, sizeof(gScriptsCSD)); if ((gScriptsRequests & SCRIPT_REQUEST_0x40) != 0) { gScriptsRequests &= ~SCRIPT_REQUEST_0x40; _combat(NULL); } else { - _combat(&stru_664980); - memset(&stru_664980, 0, sizeof(stru_664980)); + _combat(&gScriptsCSD); + memset(&gScriptsCSD, 0, sizeof(gScriptsCSD)); } } } @@ -1097,14 +1097,14 @@ int _scripts_check_state_in_combat() } // 0x4A457C -int scriptsRequestCombat(STRUCT_664980* a1) +int scriptsRequestCombat(CombatStartData* combat) { if ((gScriptsRequests & SCRIPT_REQUEST_0x0400) != 0) { return -1; } - if (a1) { - memcpy(&stru_664958, a1, sizeof(stru_664958)); + if (combat) { + memcpy(&gScriptsRequestedCSD, combat, sizeof(gScriptsRequestedCSD)); } else { gScriptsRequests |= SCRIPT_REQUEST_0x40; } @@ -1117,10 +1117,10 @@ int scriptsRequestCombat(STRUCT_664980* a1) // Likely related to random encounter, ala scriptsRequestRandomEncounter RELEASE // // 0x4A45D4 -void _scripts_request_combat_locked(STRUCT_664980* a1) +void _scripts_request_combat_locked(CombatStartData* a1) { if (a1 != NULL) { - memcpy(&stru_664958, a1, sizeof(stru_664958)); + memcpy(&gScriptsRequestedCSD, a1, sizeof(gScriptsRequestedCSD)); } else { gScriptsRequests |= SCRIPT_REQUEST_0x40; } diff --git a/src/scripts.h b/src/scripts.h index e061fd0..c583a2c 100644 --- a/src/scripts.h +++ b/src/scripts.h @@ -173,8 +173,8 @@ int scriptEventProcess(Object* obj, void* data); int _scripts_clear_combat_requests(Script* script); int scriptsHandleRequests(); int _scripts_check_state_in_combat(); -int scriptsRequestCombat(STRUCT_664980* a1); -void _scripts_request_combat_locked(STRUCT_664980* ptr); +int scriptsRequestCombat(CombatStartData* combat); +void _scripts_request_combat_locked(CombatStartData* combat); void scriptsRequestWorldMap(); int scriptsRequestElevator(Object* a1, int a2); int scriptsRequestExplosion(int tile, int elevation, int minDamage, int maxDamage); diff --git a/src/worldmap.cc b/src/worldmap.cc index 3243d8d..b660cdf 100644 --- a/src/worldmap.cc +++ b/src/worldmap.cc @@ -3684,7 +3684,7 @@ int wmSetupRandomEncounter() prevCritter->data.critter.combat.whoHitMe = critter; critter->data.critter.combat.whoHitMe = prevCritter; - STRUCT_664980 combat; + CombatStartData combat; combat.attacker = prevCritter; combat.defender = critter; combat.actionPointsBonus = 0; @@ -3692,7 +3692,7 @@ int wmSetupRandomEncounter() combat.damageBonus = 0; combat.minDamage = 0; combat.maxDamage = 500; - combat.field_1C = 0; + combat.overrideAttackResults = 0; _caiSetupTeamCombat(critter, prevCritter); _scripts_request_combat_locked(&combat); @@ -3701,7 +3701,7 @@ int wmSetupRandomEncounter() if (!isInCombat()) { prevCritter->data.critter.combat.whoHitMe = gDude; - STRUCT_664980 combat; + CombatStartData combat; combat.attacker = prevCritter; combat.defender = gDude; combat.actionPointsBonus = 0; @@ -3709,7 +3709,7 @@ int wmSetupRandomEncounter() combat.damageBonus = 0; combat.minDamage = 0; combat.maxDamage = 500; - combat.field_1C = 0; + combat.overrideAttackResults = 0; _caiSetupTeamCombat(gDude, prevCritter); _scripts_request_combat_locked(&combat);