Skip to content

Commit

Permalink
Fix restoration of droid targets for non-weapon turrets when loading …
Browse files Browse the repository at this point in the history
…savegames. Closes ticket:2737
  • Loading branch information
perim committed May 21, 2011
1 parent b1c962d commit 10f6740
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/action.cpp
Expand Up @@ -2098,6 +2098,11 @@ void actionUpdateDroid(DROID *psDroid)
case DACTION_MOVETODROIDREPAIR:
{
// moving to repair a droid
if (!psDroid->psActionTarget[0])
{
psDroid->action = DACTION_NONE;
return;
}
const int xdiff = (SDWORD)psDroid->pos.x - (SDWORD)psDroid->psActionTarget[0]->pos.x;
const int ydiff = (SDWORD)psDroid->pos.y - (SDWORD)psDroid->psActionTarget[0]->pos.y;
if ( xdiff*xdiff + ydiff*ydiff < REPAIR_RANGE )
Expand Down
19 changes: 8 additions & 11 deletions src/game.cpp
Expand Up @@ -4355,20 +4355,17 @@ static bool loadSaveDroidPointers(const QString &pFileName, DROID **ppsCurrentDr
for (psDroid = ppsCurrentDroidLists[player]; psDroid && psDroid->id != id; psDroid = psDroid->psNext) {}
ASSERT_OR_RETURN(false, psDroid, "Droid %d not found", id);

for (int j = 0; j < psDroid->numWeaps; j++)
for (int j = 0; j < DROID_MAXWEAPS; j++)
{
objTrace(psDroid->id, "weapon %d, nStat %d", j, psDroid->asWeaps[j].nStat);
if (psDroid->asWeaps[j].nStat > 0)
if (ini.contains("actionTarget/" + QString::number(j) + "/id"))
{
if (ini.contains("actionTarget/" + QString::number(j) + "/id"))
{
int tid = ini.value("actionTarget/" + QString::number(j) + "/id", -1).toInt();
int tplayer = ini.value("actionTarget/" + QString::number(j) + "/player", -1).toInt();
OBJECT_TYPE ttype = (OBJECT_TYPE)ini.value("actionTarget/" + QString::number(j) + "/type", 0).toInt();
ASSERT(tid >= 0 && tplayer >= 0, "Bad ID");
setSaveDroidActionTarget(psDroid, getBaseObjFromData(tid, tplayer, ttype), j); // TODO optimise using tplayer and ttype
ASSERT(psDroid->psActionTarget[j], "Failed to find action target");
}
int tid = ini.value("actionTarget/" + QString::number(j) + "/id", -1).toInt();
int tplayer = ini.value("actionTarget/" + QString::number(j) + "/player", -1).toInt();
OBJECT_TYPE ttype = (OBJECT_TYPE)ini.value("actionTarget/" + QString::number(j) + "/type", 0).toInt();
ASSERT(tid >= 0 && tplayer >= 0, "Bad ID");
setSaveDroidActionTarget(psDroid, getBaseObjFromData(tid, tplayer, ttype), j); // TODO optimise using tplayer and ttype
ASSERT(psDroid->psActionTarget[j], "Failed to find action target");
}
}
if (ini.contains("target/id"))
Expand Down

0 comments on commit 10f6740

Please sign in to comment.