From 0cf5ce0d7209232ab9f6e819d0618e4fbbffca6d Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Wed, 12 Jan 2011 19:16:42 +0100 Subject: [PATCH] Fix assert failure and droid paralysis when multiweapons droids are set to pursue. --- src/action.cpp | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/src/action.cpp b/src/action.cpp index 7b67725f7bc..e2b6e7eb520 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -928,16 +928,12 @@ void actionUpdateDroid(DROID *psDroid) && psWeapStats->rotate && aiBestNearestTarget(psDroid, &psTemp, i, NULL) >= 0) { - if (secondaryGetState(psDroid, DSO_ATTACK_LEVEL) != DSS_ALEV_ALWAYS) - { - psTemp = NULL; - } - else + if (secondaryGetState(psDroid, DSO_ATTACK_LEVEL) == DSS_ALEV_ALWAYS) { psDroid->action = DACTION_ATTACK; + setDroidActionTarget(psDroid, psTemp, 0); } } - setDroidActionTarget(psDroid, psTemp, 0); } } } @@ -947,7 +943,6 @@ void actionUpdateDroid(DROID *psDroid) { droidSelfRepair(psDroid); } - break; case DACTION_WAITDURINGREPAIR: // Check that repair facility still exists @@ -1036,9 +1031,9 @@ void actionUpdateDroid(DROID *psDroid) if (secondaryGetState(psDroid, DSO_ATTACK_LEVEL) == DSS_ALEV_ALWAYS) { psDroid->action = DACTION_MOVEFIRE; + setDroidActionTarget(psDroid, psTemp, 0); } } - setDroidActionTarget(psDroid, psTemp, 0); } } } @@ -1234,19 +1229,6 @@ void actionUpdateDroid(DROID *psDroid) } } } - // If main turret lost its target, but we're not ordered to attack any specific - // target, try to find a new one. - else if (psDroid->psActionTarget[0] == NULL && - psDroid->order != DORDER_ATTACK && - aiChooseTarget((BASE_OBJECT*)psDroid, &psTargets[i], i, false, NULL)) - { - // FIXME What is this code path for? - // FIXME If psDroid->psActionTarget[0] == NULL, then actionVisibleTarget(psDroid, psActionTarget, i) crashes. - // FIXME And if aiChooseTarget above fails, psActionTarget stays NULL. - // FIXME So, assuming the game can't crash, psDroid->psActionTarget[0] is never NULL. - debug(LOG_NEVER, "Can this happen?"); - setDroidActionTarget(psDroid, psTargets[i], i); - } if (psDroid->psActionTarget[i]) { @@ -2200,16 +2182,9 @@ void actionUpdateDroid(DROID *psDroid) BASE_OBJECT *psTemp = NULL; WEAPON_STATS* const psWeapStats = &asWeaponStats[psDroid->asWeaps[i].nStat]; - if (psDroid->asWeaps[i].nStat > 0 - && psWeapStats->rotate - && aiBestNearestTarget(psDroid, &psTemp, i, NULL) >= 0) - { - if (secondaryGetState(psDroid, DSO_ATTACK_LEVEL) != DSS_ALEV_ALWAYS) - { - psTemp = NULL; - } - } - if (psTemp) + if (psDroid->asWeaps[i].nStat > 0 && psWeapStats->rotate + && secondaryGetState(psDroid, DSO_ATTACK_LEVEL) == DSS_ALEV_ALWAYS + && aiBestNearestTarget(psDroid, &psTemp, i, NULL) >= 0 && psTemp) { psDroid->action = DACTION_ATTACK; setDroidActionTarget(psDroid, psTemp, 0);