Add CPlayer::RebuildUnitsConsumingResourcesList() and clean up the rest accordingly.
This commit is contained in:
parent
9d2e610448
commit
e68af42918
8 changed files with 24 additions and 96 deletions
action
game
include
stratagus
tolua
unit
|
@ -103,7 +103,7 @@ void HandleActionTrain(CUnit *unit)
|
|||
if (!unit->SubAction) {
|
||||
unit->Data.Train.Ticks = 0;
|
||||
unit->SubAction = 1;
|
||||
AddToUnitsConsumingResources(unit->Slot,
|
||||
unit->Player->AddToUnitsConsumingResources(unit->Slot,
|
||||
unit->Orders[0]->Type->Stats[unit->Player->Index].Costs);
|
||||
}
|
||||
|
||||
|
|
|
@ -201,6 +201,10 @@ void LoadGame(const std::string &filename)
|
|||
LuaLoadFile(filename);
|
||||
CclGarbageCollect(0);
|
||||
|
||||
for (int i = 0; i < NumPlayers; ++i) {
|
||||
Players[i].RebuildUnitsConsumingResourcesList();
|
||||
}
|
||||
|
||||
game_cycle = GameCycle;
|
||||
syncrand = SyncRandSeed;
|
||||
synchash = SyncHash;
|
||||
|
|
|
@ -308,10 +308,10 @@ public:
|
|||
int StoredResources[MaxCosts]; /// Amount of resources in storage
|
||||
int StorageCapacity[MaxCosts]; /// Storage capacity of resources
|
||||
|
||||
void SaveUnitsConsumingResources(CFile *file);
|
||||
void AddToUnitsConsumingResources(int slot, int costs[MaxCosts]);
|
||||
void RemoveFromUnitsConsumingResources(int slot);
|
||||
void UpdateUnitsConsumingResources(int slot, int costs[MaxCosts]);
|
||||
void RebuildUnitsConsumingResourcesList();
|
||||
|
||||
// FIXME: shouldn't use the constant
|
||||
int UnitTypesCount[UnitTypeMax]; /// total units of unit-type
|
||||
|
|
|
@ -918,9 +918,6 @@ extern int CanTransport(const CUnit *transporter, const CUnit *unit);
|
|||
/// Check if unit can move.
|
||||
extern bool CanMove(const CUnit *unit);
|
||||
|
||||
/// Add to UnitsConsumingResources
|
||||
void AddToUnitsConsumingResources(int slot, int costs[MaxCosts]);
|
||||
|
||||
/// Generate a unit reference, a printable unique string for unit
|
||||
extern std::string UnitReference(const CUnit *unit);
|
||||
/// Save an order
|
||||
|
|
|
@ -113,23 +113,6 @@ void CleanPlayers(void)
|
|||
NoRescueCheck = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
** Save the list of units of a player that consume resources
|
||||
**
|
||||
** @param file Output file.
|
||||
*/
|
||||
void CPlayer::SaveUnitsConsumingResources(CFile *file)
|
||||
{
|
||||
std::map<int, int*>::iterator i;
|
||||
for (i = UnitsConsumingResources.begin(); i != UnitsConsumingResources.end(); ++i) {
|
||||
file->printf("AddToUnitsConsumingResources(%d, {", (*i).first);
|
||||
for (int j = 0; j < MaxCosts; ++j) {
|
||||
file->printf("%s%d", (j ? ", " : ""), ((*i).second)[j]);
|
||||
}
|
||||
file->printf("})\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Add to UnitsConsumingResources
|
||||
*/
|
||||
|
@ -175,6 +158,23 @@ void CPlayer::UpdateUnitsConsumingResources(int slot, int costs[MaxCosts])
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Go through the list of units owned by the player and rebuild
|
||||
** the UnitsConsumingResources list.
|
||||
*/
|
||||
void CPlayer::RebuildUnitsConsumingResourcesList()
|
||||
{
|
||||
CUnit *u;
|
||||
|
||||
UnitsConsumingResources.clear();
|
||||
for (int i = 0; i < TotalNumUnits; ++i) {
|
||||
u = Units[i];
|
||||
if (u->Orders[0]->Action == UnitActionTrain && !u->SubAction) {
|
||||
AddToUnitsConsumingResources(u->Slot,
|
||||
u->Orders[0]->Type->Stats[u->Player->Index].Costs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Save state of players to file.
|
||||
|
@ -321,9 +321,6 @@ void SavePlayers(CFile *file)
|
|||
// Allow saved by allow.
|
||||
|
||||
file->printf(")\n\n");
|
||||
|
||||
// Dump the list of units of a player that consume resources
|
||||
p->SaveUnitsConsumingResources(file);
|
||||
}
|
||||
|
||||
DebugPrint("FIXME: must save unit-stats?\n");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
** Lua binding: stratagus
|
||||
** Generated automatically by tolua++-1.0.92 on Wed Mar 28 23:41:31 2007.
|
||||
** Generated automatically by tolua++-1.0.92 on Thu Mar 29 23:28:22 2007.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
@ -14139,62 +14139,6 @@ static int tolua_set_Preference(lua_State* tolua_S)
|
|||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* function: AddToUnitsConsumingResources */
|
||||
#ifndef TOLUA_DISABLE_tolua_stratagus_AddToUnitsConsumingResources00
|
||||
static int tolua_stratagus_AddToUnitsConsumingResources00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isnumber(tolua_S,1,0,&tolua_err) ||
|
||||
!tolua_istable(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
int slot = ((int) tolua_tonumber(tolua_S,1,0));
|
||||
#ifdef __cplusplus
|
||||
int* costs = new int[MaxCosts];
|
||||
#else
|
||||
int* costs = (int*) malloc((MaxCosts)*sizeof(int));
|
||||
#endif
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!tolua_isnumberarray(tolua_S,2,MaxCosts,0,&tolua_err))
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<MaxCosts;i++)
|
||||
costs[i] = ((int) tolua_tofieldnumber(tolua_S,2,i+1,0));
|
||||
}
|
||||
}
|
||||
{
|
||||
AddToUnitsConsumingResources(slot,costs);
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<MaxCosts;i++)
|
||||
tolua_pushfieldnumber(tolua_S,2,i+1,(lua_Number) costs[i]);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
delete [] costs;
|
||||
#else
|
||||
free(costs);
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'AddToUnitsConsumingResources'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* function: GetEffectsVolume */
|
||||
#ifndef TOLUA_DISABLE_tolua_stratagus_GetEffectsVolume00
|
||||
static int tolua_stratagus_GetEffectsVolume00(lua_State* tolua_S)
|
||||
|
@ -16784,7 +16728,6 @@ TOLUA_API int tolua_stratagus_open (lua_State* tolua_S)
|
|||
tolua_variable(tolua_S,"ShowOrders",tolua_get_CPreference_unsigned_ShowOrders,tolua_set_CPreference_unsigned_ShowOrders);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_variable(tolua_S,"Preference",tolua_get_Preference,tolua_set_Preference);
|
||||
tolua_function(tolua_S,"AddToUnitsConsumingResources",tolua_stratagus_AddToUnitsConsumingResources00);
|
||||
tolua_function(tolua_S,"GetEffectsVolume",tolua_stratagus_GetEffectsVolume00);
|
||||
tolua_function(tolua_S,"SetEffectsVolume",tolua_stratagus_SetEffectsVolume00);
|
||||
tolua_function(tolua_S,"GetMusicVolume",tolua_stratagus_GetMusicVolume00);
|
||||
|
|
|
@ -18,7 +18,3 @@ class CPreference
|
|||
};
|
||||
|
||||
CPreference Preference;
|
||||
|
||||
void AddToUnitsConsumingResources(int slot, int costs[MaxCosts]);
|
||||
|
||||
|
||||
|
|
|
@ -3442,15 +3442,6 @@ bool CUnit::IsUnusable() const
|
|||
this->Orders[0]->Action == UnitActionBuilt || this->Destroyed;
|
||||
}
|
||||
|
||||
/**
|
||||
** Add to UnitsConsumingResources
|
||||
*/
|
||||
void AddToUnitsConsumingResources(int slot, int costs[MaxCosts])
|
||||
{
|
||||
CPlayer *p = UnitSlots[slot]->Player;
|
||||
p->AddToUnitsConsumingResources(slot, costs);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- SAVE/LOAD
|
||||
|
|
Loading…
Add table
Reference in a new issue