Skip to content

Commit

Permalink
Move structure limits into stats rule files.
Browse files Browse the repository at this point in the history
Limits used to be set in scripts. Now they
are defined in structure.json instead. One
advantage of this change is that the code
is much simpler. Also, we can now set a
default limit value that is different from
the maximum, which we previously could not.
  • Loading branch information
perim committed Dec 12, 2017
1 parent 8c96a94 commit 924135c
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 227 deletions.
3 changes: 0 additions & 3 deletions data/base/wrf/limiter_data.wrf
Expand Up @@ -9,6 +9,3 @@ file SSENSOR "sensor.json"
file SECM "ecm.json"
file SREPAIR "repair.json"
file SSTRUCT "structure.json"
directory "multiplay/script"
file SCRIPT "multilim.slo"
file SCRIPTVAL "multilim.vlo"
29 changes: 0 additions & 29 deletions data/mp/multiplay/script/multilim.slo

This file was deleted.

23 changes: 0 additions & 23 deletions data/mp/multiplay/script/multilim.vlo

This file was deleted.

9 changes: 9 additions & 0 deletions data/mp/stats/structure.json
Expand Up @@ -312,6 +312,7 @@
"blcfact1.pie"
],
"type": "CYBORG FACTORY",
"userLimits": [ 0, 5, 5 ],
"width": 1
},
"A0FacMod1": {
Expand Down Expand Up @@ -400,6 +401,7 @@
"milasbas.pie"
],
"type": "GENERIC",
"userLimits": [ 0, 1, 1 ],
"weapons": [
"LasSat"
],
Expand Down Expand Up @@ -428,6 +430,7 @@
"blfact2.pie"
],
"type": "FACTORY",
"userLimits": [ 0, 5, 5 ],
"width": 3
},
"A0PowMod1": {
Expand Down Expand Up @@ -468,6 +471,7 @@
"blpower4.pie"
],
"type": "POWER GENERATOR",
"userLimits": [ 0, 10, 10 ],
"width": 2
},
"A0RepairCentre3": {
Expand All @@ -489,6 +493,7 @@
"BLRPAIR3.PIE"
],
"type": "REPAIR FACILITY",
"userLimits": [ 0, 5, 5 ],
"width": 1
},
"A0ResearchFacility": {
Expand All @@ -512,6 +517,7 @@
"blresch4.pie"
],
"type": "RESEARCH",
"userLimits": [ 0, 5, 5 ],
"width": 2
},
"A0ResearchModule1": {
Expand Down Expand Up @@ -566,6 +572,7 @@
"miupbase.PIE"
],
"type": "SAT UPLINK",
"userLimits": [ 0, 1, 1 ],
"width": 2
},
"A0TankTrap": {
Expand Down Expand Up @@ -607,6 +614,7 @@
"blvfact2.pie"
],
"type": "VTOL FACTORY",
"userLimits": [ 0, 5, 5 ],
"width": 3
},
"A0VtolPad": {
Expand All @@ -628,6 +636,7 @@
"blvtolpd.pie"
],
"type": "REARM PAD",
"userLimits": [ 0, 50, 50 ],
"width": 1
},
"AASite-QuadBof": {
Expand Down
1 change: 0 additions & 1 deletion po/POTFILES.in
Expand Up @@ -131,7 +131,6 @@ data/base/sequenceaudio/devastation.txt
data/base/sequenceaudio/outro.txt
data/mp/messages/strings/names.txt
data/mp/messages/strings/resstrings.txt
data/mp/multiplay/script/multilim.slo
data/mp/multiplay/script/scavfact.js
data/mp/multiplay/skirmish/nb_common/standard_build_order.js
data/mp/multiplay/skirmish/nb_generic.js
Expand Down
3 changes: 1 addition & 2 deletions src/droid.cpp
Expand Up @@ -944,7 +944,6 @@ DroidStartBuild droidStartBuild(DROID *psDroid)
psDroid->order.type == DORDER_LINEBUILD))
{
STRUCTURE_STATS *psStructStat = psDroid->order.psStats;
STRUCTURE_LIMITS *structLimit = &asStructLimits[psDroid->player][psStructStat - asStructureStats];

ItemAvailability ia = (ItemAvailability)apStructTypeLists[psDroid->player][psStructStat - asStructureStats];
if (ia != AVAILABLE && ia != REDUNDANT)
Expand All @@ -957,7 +956,7 @@ DroidStartBuild droidStartBuild(DROID *psDroid)
}

//need to check structLimits have not been exceeded
if (structLimit->currentQuantity >= structLimit->limit)
if (psStructStat->curCount[psDroid->player] >= psStructStat->upgrade[psDroid->player].limit)
{
intBuildFinished(psDroid);
cancelBuild(psDroid);
Expand Down
6 changes: 2 additions & 4 deletions src/game.cpp
Expand Up @@ -2141,7 +2141,6 @@ bool loadGame(const char *pGameToLoad, bool keepObjects, bool freeMem, bool User
}
}

initStructLimits();
aFileName[fileExten] = '\0';
strcat(aFileName, "mstruct.json");

Expand Down Expand Up @@ -2381,7 +2380,6 @@ bool loadGame(const char *pGameToLoad, bool keepObjects, bool freeMem, bool User
}

//load in the structures
initStructLimits();
aFileName[fileExten] = '\0';
strcat(aFileName, "struct.json");
if (!loadSaveStructure2(aFileName, apsStructLists))
Expand Down Expand Up @@ -6446,7 +6444,7 @@ bool loadSaveStructLimits(const char *pFileName)
STRUCTURE_STATS *psStats = asStructureStats + statInc;
if (name.compare(psStats->id) == 0)
{
asStructLimits[player][statInc].limit = limit != 255 ? limit : LOTS_OF;
asStructureStats[statInc].upgrade[player].limit = limit != 255 ? limit : LOTS_OF;
break;
}
}
Expand Down Expand Up @@ -6478,7 +6476,7 @@ bool writeStructLimitsFile(const char *pFileName)
STRUCTURE_STATS *psStats = asStructureStats;
for (int i = 0; i < numStructureStats; i++, psStats++)
{
const int limit = MIN(asStructLimits[player][i].limit, 255);
const int limit = MIN(asStructureStats[i].upgrade[player].limit, 255);
if (limit != 255)
{
ini.setValue(psStats->id, limit);
Expand Down
2 changes: 1 addition & 1 deletion src/multiint.cpp
Expand Up @@ -1605,7 +1605,7 @@ void updateLimitFlags()
for (i = 0; i < ARRAY_SIZE(limitIcons); ++i)
{
int stat = getStructStatFromName(limitIcons[i].stat);
bool disabled = asStructLimits[0] != nullptr && stat >= 0 && asStructLimits[0][stat].limit == 0;
bool disabled = stat >= 0 && asStructureStats[stat].upgrade[0].limit == 0;
flags |= disabled << i;
}

Expand Down
24 changes: 11 additions & 13 deletions src/multilimit.cpp
Expand Up @@ -111,11 +111,9 @@ bool startLimitScreen()

if (challengeActive)
{
// reset the sliders..
// it's a HACK since the actual limiter structure was cleared in the startMultiOptions function
for (unsigned i = 0; i < numStructureStats; ++i)
{
asStructLimits[0][i].limit = asStructLimits[0][i].globalLimit;
asStructureStats[i].upgrade[0].limit = asStructureStats[i].base.limit;
}

// turn off the sliders
Expand Down Expand Up @@ -160,7 +158,7 @@ bool startLimitScreen()

for (unsigned i = 0; i < numStructureStats; ++i)
{
if (asStructLimits[0][i].globalLimit != LOTS_OF)
if (asStructureStats[i].base.limit != LOTS_OF)
{
W_FORM *button = new W_FORM(limitsList);
button->id = limitsButtonId;
Expand All @@ -170,8 +168,8 @@ bool startLimitScreen()
++limitsButtonId;

addFESlider(limitsButtonId, limitsButtonId - 1, 290, 11,
asStructLimits[0][i].globalLimit,
asStructLimits[0][i].limit);
asStructureStats[i].maxLimit,
asStructureStats[i].upgrade[0].limit);
++limitsButtonId;
}
}
Expand All @@ -194,7 +192,7 @@ void runLimitScreen()
unsigned statid = widgGetFromID(psWScreen, id - 1)->UserData;
if (statid)
{
asStructLimits[0][statid].limit = (UBYTE)((W_SLIDER *)(widgGetFromID(psWScreen, id)))->pos;
asStructureStats[statid].upgrade[0].limit = (UBYTE)((W_SLIDER *)(widgGetFromID(psWScreen, id)))->pos;
}
}
else
Expand All @@ -206,7 +204,7 @@ void runLimitScreen()
// reset the sliders..
for (unsigned i = 0; i < numStructureStats; ++i)
{
asStructLimits[0][i].limit = asStructLimits[0][i].globalLimit;
asStructureStats[i].upgrade[0].limit = asStructureStats[i].base.limit;
}
// free limiter structure
freeLimitSet();
Expand Down Expand Up @@ -263,7 +261,7 @@ void createLimitSet()
for (unsigned i = 0; i < numStructureStats; i++)
{
// If the limit differs from the default
if (asStructLimits[0][i].limit != LOTS_OF)
if (asStructureStats[i].upgrade[0].limit != LOTS_OF)
{
numchanges++;
}
Expand All @@ -277,11 +275,11 @@ void createLimitSet()
// Prepare chunk
for (unsigned i = 0; i < numStructureStats; i++)
{
if (asStructLimits[0][i].limit != LOTS_OF)
if (asStructureStats[i].upgrade[0].limit != LOTS_OF)
{
ASSERT_OR_RETURN(, idx < numchanges, "Bad number of changed limits");
pEntry[idx].id = i;
pEntry[idx].limit = asStructLimits[0][i].limit;
pEntry[idx].limit = asStructureStats[i].upgrade[0].limit;
idx++;
}
}
Expand Down Expand Up @@ -312,9 +310,9 @@ void applyLimitSet()
// So long as the ID is valid
if (id < numStructureStats)
{
for (auto &asStructLimit : asStructLimits)
for (int player = 0; player < MAX_PLAYERS; player++)
{
asStructLimit[id].limit = pEntry[i].limit;
asStructureStats[id].upgrade[player].limit = pEntry[i].limit;
}
}
}
Expand Down
21 changes: 12 additions & 9 deletions src/qtscriptfuncs.cpp
Expand Up @@ -92,7 +92,8 @@ enum Scrcb {
SCRCB_HEA,
SCRCB_ELW,
SCRCB_HIT,
SCRCB_LAST = SCRCB_HIT
SCRCB_LIMIT,
SCRCB_LAST = SCRCB_LIMIT
};

// TODO, move this stuff into a script common subsystem
Expand Down Expand Up @@ -2769,9 +2770,7 @@ static QScriptValue js_setStructureLimits(QScriptContext *context, QScriptEngine
SCRIPT_ASSERT(context, limit < LOTS_OF && limit >= 0, "Invalid limit");
SCRIPT_ASSERT(context, structInc < numStructureStats && structInc >= 0, "Invalid structure");

STRUCTURE_LIMITS *psStructLimits = asStructLimits[player];
psStructLimits[structInc].limit = limit;
psStructLimits[structInc].globalLimit = limit;
asStructureStats[structInc].upgrade[player].limit = limit;

return QScriptValue();
}
Expand Down Expand Up @@ -3301,7 +3300,7 @@ static QScriptValue js_isStructureAvailable(QScriptContext *context, QScriptEngi
player = engine->globalObject().property("me").toInt32();
}
return QScriptValue(apStructTypeLists[player][index] == AVAILABLE
&& asStructLimits[player][index].currentQuantity < asStructLimits[player][index].limit);
&& asStructureStats[index].curCount[player] < asStructureStats[index].upgrade[player].limit);
}

//-- \subsection{isVTOL(droid)}
Expand Down Expand Up @@ -3435,8 +3434,8 @@ static QScriptValue js_donateObject(QScriptContext *context, QScriptEngine *engi
{
STRUCTURE *psStruct = IdToStruct(id, player);
SCRIPT_ASSERT(context, psStruct, "No such struct id %u belonging to player %u", id, player);
int max = psStruct->pStructureType - asStructureStats;
if (asStructLimits[player][max].currentQuantity + 1 > asStructLimits[player][max].limit)
const int statidx = psStruct->pStructureType - asStructureStats;
if (asStructureStats[statidx].curCount[player] + 1 > asStructureStats[statidx].upgrade[player].limit)
{
return QScriptValue(false);
}
Expand Down Expand Up @@ -3516,7 +3515,7 @@ static QScriptValue js_getStructureLimit(QScriptContext *context, QScriptEngine
{
player = engine->globalObject().property("me").toInt32();
}
return QScriptValue(asStructLimits[player][index].limit);
return QScriptValue(asStructureStats[index].upgrade[player].limit);
}

//-- \subsection{countStruct(structure type[, player])}
Expand All @@ -3540,7 +3539,7 @@ static QScriptValue js_countStruct(QScriptContext *context, QScriptEngine *engin
|| (player == ALLIES && aiCheckAlliances(i, me))
|| (player == ENEMIES && !aiCheckAlliances(i, me)))
{
quantity += asStructLimits[i][index].currentQuantity;
quantity += asStructureStats[index].curCount[i];
}
}
return QScriptValue(quantity);
Expand Down Expand Up @@ -4833,6 +4832,8 @@ QScriptValue js_stats(QScriptContext *context, QScriptEngine *engine)
}
psStats->upgrade[player].hitpoints = value;
break;
case SCRCB_LIMIT:
psStats->upgrade[player].limit = value; break;
}
}
else
Expand Down Expand Up @@ -5080,6 +5081,7 @@ QScriptValue js_stats(QScriptContext *context, QScriptEngine *engine)
case SCRCB_HEA: return psStats->upgrade[player].thermal; break;
case SCRCB_ARM: return psStats->upgrade[player].armour; break;
case SCRCB_HIT: return psStats->upgrade[player].hitpoints;
case SCRCB_LIMIT: return psStats->upgrade[player].limit;
default: SCRIPT_ASSERT(context, false, "Component type not found for upgrade"); break;
}
}
Expand Down Expand Up @@ -5456,6 +5458,7 @@ bool registerFunctions(QScriptEngine *engine, const QString& scriptName)
setStatsFunc(strct, engine, "Resistance", i, SCRCB_ELW, j);
setStatsFunc(strct, engine, "Thermal", i, SCRCB_HEA, j);
setStatsFunc(strct, engine, "HitPoints", i, SCRCB_HIT, j);
setStatsFunc(strct, engine, "Limit", i, SCRCB_LIMIT, j);
structbase.setProperty(psStats->name, strct, QScriptValue::ReadOnly | QScriptValue::Undeletable);
}
node.setProperty("Building", structbase, QScriptValue::ReadOnly | QScriptValue::Undeletable);
Expand Down

0 comments on commit 924135c

Please sign in to comment.