Skip to content

Commit

Permalink
Removed engine support for StartMetal, StartEnergy
Browse files Browse the repository at this point in the history
This is straightforward to implement using Lua, as the included example shows.

Specifically, the following has been removed:
- reading of modoption / per-team StartMetal, StartEnergy
- default values of storage for commander unit are now 0, as for all other units.

Do not forget to copy the removed resource related engine options to ModOptions.lua, if desired.
  • Loading branch information
tvo committed Jan 27, 2010
1 parent 26549be commit 9eae8eb
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 108 deletions.
58 changes: 0 additions & 58 deletions installer/builddata/springcontent/EngineOptions.lua
Expand Up @@ -58,64 +58,6 @@ local options =
},
},

{
key = 'StartingResources',
name = 'Starting Resources',
desc = 'Sets storage and amount of resources that players will start with',
type = 'section',
},

{
key = 'StartMetal',
name = 'Starting metal',
desc = 'Determines amount of metal and metal storage that each player will start with',
type = 'number',
section= 'StartingResources',
def = 1000,
min = 0,
max = 10000,
step = 1, -- quantization is aligned to the def value
-- (step <= 0) means that there is no quantization
},
{
key = 'StartMetal',
scope = 'team',
name = 'Team Starting metal',
desc = 'Determines amount of metal and metal storage this team will start with',
type = 'number',
section= 'StartingResources',
def = 1000,
min = 0,
max = 10000,
step = 1, -- quantization is aligned to the def value
-- (step <= 0) means that there is no quantization
},
{
key = 'StartEnergy',
name = 'Starting energy',
desc = 'Determines amount of energy and energy storage that each player will start with',
type = 'number',
section= 'StartingResources',
def = 1000,
min = 0,
max = 10000,
step = 1, -- quantization is aligned to the def value
-- (step <= 0) means that there is no quantization
},
{
key = 'StartEnergy',
scope = 'team',
name = 'Team Starting energy',
desc = 'Determines amount of energy and energy storage that this team will start with',
type = 'number',
section= 'StartingResources',
def = 1000,
min = 0,
max = 10000,
step = 1, -- quantization is aligned to the def value
-- (step <= 0) means that there is no quantization
},

{
key = 'MaxUnits',
name = 'Max units',
Expand Down
Expand Up @@ -26,9 +26,12 @@ end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local modOptions = Spring.GetModOptions()


local function GetStartUnit(teamID)
-- get the team startup info
local _,_,_,_,side = Spring.GetTeamInfo(teamID)
local side = select(5, Spring.GetTeamInfo(teamID))
local startUnit
if (side == "") then
-- startscript didn't specify a side for this team
Expand Down Expand Up @@ -60,6 +63,22 @@ local function SpawnStartUnit(teamID)
Spring.SetTeamResource(teamID, "ms", ud.metalStorage)
Spring.SetTeamResource(teamID, "es", ud.energyStorage)
end

-- set start resources, either from mod options or custom team keys
local teamOptions = select(7, Spring.GetTeamInfo(teamID))
local m = teamOptions.startmetal or modOptions.startmetal
local e = teamOptions.startenergy or modOptions.startenergy

-- using SetTeamResource to get rid of any existing resource without affecting stats
-- using AddTeamResource to add starting resource and counting it as income
if (m and tonumber(m) ~= 0) then
Spring.SetTeamResource(teamID, "m", 0)
Spring.AddTeamResource(teamID, "m", tonumber(m))
end
if (e and tonumber(e) ~= 0) then
Spring.SetTeamResource(teamID, "e", 0)
Spring.AddTeamResource(teamID, "e", tonumber(e))
end
end


Expand Down
9 changes: 0 additions & 9 deletions rts/Game/GameSetup.cpp
Expand Up @@ -233,8 +233,6 @@ void CGameSetup::LoadTeams(const TdfParser& file)
}

TeamBase data;
data.startMetal = startMetal;
data.startEnergy = startEnergy;

// Get default color from palette (based on "color" tag)
for (size_t num = 0; num < 3; ++num)
Expand All @@ -247,11 +245,6 @@ void CGameSetup::LoadTeams(const TdfParser& file)
for (std::map<std::string, std::string>::const_iterator it = setup.begin(); it != setup.end(); ++it)
data.SetValue(it->first, it->second);

if (data.startMetal == -1.0)
data.startMetal = startMetal;

if (data.startEnergy == -1.0)
data.startEnergy = startEnergy;
teamStartingData.push_back(data);

teamRemap[a] = i;
Expand Down Expand Up @@ -402,8 +395,6 @@ bool CGameSetup::Init(const std::string& buf)
file.GetDef(diminishingMMs, "0", "GAME\\ModOptions\\DiminishingMMs");
file.GetDef(disableMapDamage, "0", "GAME\\ModOptions\\DisableMapDamage");
file.GetDef(ghostedBuildings, "1", "GAME\\ModOptions\\GhostedBuildings");
file.GetDef(startMetal, "1000", "GAME\\ModOptions\\StartMetal");
file.GetDef(startEnergy, "1000", "GAME\\ModOptions\\StartEnergy");

file.GetDef(maxSpeed, "3.0", "GAME\\ModOptions\\MaxSpeed");
file.GetDef(minSpeed, "0.3", "GAME\\ModOptions\\MinSpeed");
Expand Down
3 changes: 0 additions & 3 deletions rts/Game/GameSetup.h
Expand Up @@ -92,9 +92,6 @@ class CGameSetup

std::string saveName;

int startMetal;
int startEnergy;

int gameMode;
int noHelperAIs;

Expand Down
7 changes: 1 addition & 6 deletions rts/Sim/Misc/Team.cpp
Expand Up @@ -38,8 +38,6 @@ CR_REG_METADATA(CTeam, (
CR_MEMBER(startPos),
CR_MEMBER(teamStartNum),
CR_MEMBER(teamAllyteam),
CR_MEMBER(startMetal),
CR_MEMBER(startEnergy),
// CR_MEMBER(customValues),
// from CTeam
CR_MEMBER(teamNum),
Expand Down Expand Up @@ -265,11 +263,8 @@ void CTeam::StartposMessage(const float3& pos)
void CTeam::operator=(const TeamBase& base)
{
TeamBase::operator=(base);
energy = base.startEnergy;
energyIncome = base.startEnergy; // should that count as income?
metal = base.startMetal;
metalIncome = base.startMetal;
}

void CTeam::ResetFrameVariables()
{
prevMetalPull = metalPull;
Expand Down
35 changes: 15 additions & 20 deletions rts/Sim/Misc/TeamBase.cpp
Expand Up @@ -25,47 +25,42 @@ TeamBase::TeamBase() :
leader(-1),
handicap(1),
startPos(-100,-100,-100),
teamAllyteam(-1),
startMetal(-1.0),
startEnergy(-1.0)
teamAllyteam(-1)
{
}

void TeamBase::SetValue(const std::string& key, const std::string& value)
{
if (key == "handicap")
if (key == "handicap") {
handicap = std::atof(value.c_str()) / 100 + 1;
else if (key == "teamleader")
}
else if (key == "teamleader") {
leader = std::atoi(value.c_str());
else if (key == "side")
}
else if (key == "side") {
side = StringToLower(value);
else if (key == "allyteam")
}
else if (key == "allyteam") {
teamAllyteam = std::atoi(value.c_str());
else if (key == "startmetal")
startMetal = std::atof(value.c_str());
else if (key == "startenergy")
startEnergy = std::atof(value.c_str());
else if (key == "rgbcolor")
{
}
else if (key == "rgbcolor") {
std::istringstream buf(value);
for (size_t b = 0; b < 3; ++b)
{
for (size_t b = 0; b < 3; ++b) {
float tmp;
buf >> tmp;
color[b] = tmp * 255;
}
color[3] = 255;
}
else if (key == "startposx")
{
else if (key == "startposx") {
if (!value.empty())
startPos.x = atoi(value.c_str());
}
else if (key == "startposz")
{
else if (key == "startposz") {
if (!value.empty())
startPos.z = atoi(value.c_str());
}
else
else {
customValues[key] = value;
}
}
3 changes: 0 additions & 3 deletions rts/Sim/Misc/TeamBase.h
Expand Up @@ -34,9 +34,6 @@ class TeamBase
int teamStartNum;
int teamAllyteam;

float startMetal;
float startEnergy;

static unsigned char teamDefaultColor[10][4];

private:
Expand Down
10 changes: 2 additions & 8 deletions rts/Sim/Units/UnitDefHandler.cpp
Expand Up @@ -247,14 +247,8 @@ void CUnitDefHandler::ParseUnitDefTable(const LuaTable& udTable, const string& u

ud.isCommander = udTable.GetBool("commander", false);

if (ud.isCommander) {
ud.metalStorage = udTable.GetFloat("metalStorage", gameSetup->startMetal);
ud.energyStorage = udTable.GetFloat("energyStorage", gameSetup->startEnergy);
}
else {
ud.metalStorage = udTable.GetFloat("metalStorage", 0.0f);
ud.energyStorage = udTable.GetFloat("energyStorage", 0.0f);
}
ud.metalStorage = udTable.GetFloat("metalStorage", 0.0f);
ud.energyStorage = udTable.GetFloat("energyStorage", 0.0f);

ud.extractsMetal = udTable.GetFloat("extractsMetal", 0.0f);
ud.windGenerator = udTable.GetFloat("windGenerator", 0.0f);
Expand Down

0 comments on commit 9eae8eb

Please sign in to comment.