[Add] Mission tracks cargo and makes sure you have it.
This commit is contained in:
parent
8172d0f21f
commit
1d57250606
@ -44,11 +44,16 @@ end
|
|||||||
|
|
||||||
function land()
|
function land()
|
||||||
if space.landName() == planet then
|
if space.landName() == planet then
|
||||||
player.rmCargo(carg_id)
|
if player.rmCargo(carg_id) then
|
||||||
player.pay(misn_reward)
|
player.pay(misn_reward)
|
||||||
tk.msg("Mission Accomplished",
|
tk.msg("Mission Accomplished",
|
||||||
string.format("The workers unload the %s at the docks.", carg_type))
|
string.format("The workers unload the %s at the docks.", carg_type))
|
||||||
misn_finish()
|
misn_finish()
|
||||||
|
else
|
||||||
|
tk.msg("Where is the cargo?",
|
||||||
|
string.format("You are missing the %d tons of %s!.",
|
||||||
|
carg_mass, carg_type))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -281,6 +281,7 @@ static int player_addCargo(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int player_rmCargo(lua_State* L) {
|
static int player_rmCargo(lua_State* L) {
|
||||||
|
int ret;
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
|
|
||||||
MIN_ARGS(1);
|
MIN_ARGS(1);
|
||||||
@ -288,8 +289,9 @@ static int player_rmCargo(lua_State* L) {
|
|||||||
if(lua_isnumber(L, -1)) id = (unsigned int) lua_tonumber(L, -1);
|
if(lua_isnumber(L, -1)) id = (unsigned int) lua_tonumber(L, -1);
|
||||||
else return 0;
|
else return 0;
|
||||||
|
|
||||||
pilot_rmMissionCargo(player, id);
|
ret = pilot_rmMissionCargo(player, id);
|
||||||
|
|
||||||
|
lua_pushboolean(L, !ret);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/pilot.c
10
src/pilot.c
@ -656,17 +656,15 @@ unsigned int pilot_addMissionCargo(Pilot* pilot, Commodity* cargo, int quantity)
|
|||||||
return pilot->commodities[pilot->ncommodities-1].id;
|
return pilot->commodities[pilot->ncommodities-1].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pilot_rmMissionCargo(Pilot* pilot, unsigned int cargo_id) {
|
int pilot_rmMissionCargo(Pilot* pilot, unsigned int cargo_id) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < pilot->ncommodities; i++)
|
for(i = 0; i < pilot->ncommodities; i++)
|
||||||
if(pilot->commodities[i].id == cargo_id)
|
if(pilot->commodities[i].id == cargo_id)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if(i >= pilot->ncommodities) {
|
if(i >= pilot->ncommodities)
|
||||||
DEBUG("Mission Cargo id '%d' not found on pilot '%s'", cargo_id, pilot->name);
|
return 1;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove cargo.
|
// Remove cargo.
|
||||||
pilot->cargo_free += pilot->commodities[i].quantity;
|
pilot->cargo_free += pilot->commodities[i].quantity;
|
||||||
@ -676,6 +674,8 @@ void pilot_rmMissionCargo(Pilot* pilot, unsigned int cargo_id) {
|
|||||||
pilot->ncommodities--;
|
pilot->ncommodities--;
|
||||||
pilot->commodities = realloc(pilot->commodities,
|
pilot->commodities = realloc(pilot->commodities,
|
||||||
sizeof(PilotCommodity) * pilot->ncommodities);
|
sizeof(PilotCommodity) * pilot->ncommodities);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get rid of quantity cargo from pilot,
|
// Try to get rid of quantity cargo from pilot,
|
||||||
|
@ -148,7 +148,7 @@ int pilot_addCargo(Pilot* pilot, Commodity* cargo, int quantity);
|
|||||||
int pilot_rmCargo(Pilot* pilot, Commodity* cargo, int quantity);
|
int pilot_rmCargo(Pilot* pilot, Commodity* cargo, int quantity);
|
||||||
// Mission cargo - Not to be confused with normal cargo.
|
// Mission cargo - Not to be confused with normal cargo.
|
||||||
unsigned int pilot_addMissionCargo(Pilot* pilot, Commodity* cargo, int quantity);
|
unsigned int pilot_addMissionCargo(Pilot* pilot, Commodity* cargo, int quantity);
|
||||||
void pilot_rmMissionCargo(Pilot* pilot, unsigned int cargo_id);
|
int pilot_rmMissionCargo(Pilot* pilot, unsigned int cargo_id);
|
||||||
|
|
||||||
|
|
||||||
// Creation.
|
// Creation.
|
||||||
|
Loading…
Reference in New Issue
Block a user