[Change] OK. Remove the cargo only when it makes sense, eg.. Player

doesn't have the active mission, or the player died or something.
This commit is contained in:
Allanis 2014-03-09 23:48:26 +00:00
parent 618e1cd9ec
commit c1a85e2e99
2 changed files with 28 additions and 2 deletions

View File

@ -387,6 +387,7 @@ void mission_cleanup(Mission* misn) {
}
if(misn->cargo != NULL) {
for(i = 0; i < misn->ncargo; i++) { /* Must unlink all the cargo. */
if(player != NULL) /* Only remove if player exists. */
pilot_rmMissionCargo(player, misn->cargo[i]);
mission_unlinkCargo(misn, misn->cargo[i]);
}

View File

@ -2227,7 +2227,8 @@ int player_save(xmlTextWriterPtr writer) {
}
static int player_saveShip(xmlTextWriterPtr writer, Pilot* ship, char* loc) {
int i;
int i, j, k;
int found;
xmlw_startElem(writer, "ship");
xmlw_attr(writer, "name", ship->name);
@ -2253,6 +2254,30 @@ static int player_saveShip(xmlTextWriterPtr writer, Pilot* ship, char* loc) {
/* Save the commodities. */
xmlw_startElem(writer, "commodities");
for(i = 0; i < ship->ncommodities; i++) {
/* Remove cargo with id and no mission. */
if(ship->commodities[i].id > 0) {
found = 0;
for(j = 0; j < MISSION_MAX; j++) {
/* Only check active missions. */
if(player_missions[j].id > 0) {
/* Now check if it's in the cargo list. */
for(k = 0; player_missions[j].ncargo; k++) {
/* See if it matches a cargo. */
if(player_missions[j].cargo[k] == ship->commodities[i].id) {
found = 1;
break;
}
}
}
if(found)
break;
}
if(!found) {
WARN("Found mission cargo without assosciated mission.");
WARN("Please save game to remove the dead cargo.");
continue;
}
}
xmlw_startElem(writer, "commodity");