Skip to content
Permalink
Browse files

Move structure limits into stats rule files.

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 cef414f commit 82413100781690e96d56cc6e8a4974fbc9794fd6
@@ -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"

This file was deleted.

This file was deleted.

@@ -312,6 +312,7 @@
"blcfact1.pie"
],
"type": "CYBORG FACTORY",
"userLimits": [ 0, 5, 5 ],
"width": 1
},
"A0FacMod1": {
@@ -400,6 +401,7 @@
"milasbas.pie"
],
"type": "GENERIC",
"userLimits": [ 0, 1, 1 ],
"weapons": [
"LasSat"
],
@@ -428,6 +430,7 @@
"blfact2.pie"
],
"type": "FACTORY",
"userLimits": [ 0, 5, 5 ],
"width": 3
},
"A0PowMod1": {
@@ -468,6 +471,7 @@
"blpower4.pie"
],
"type": "POWER GENERATOR",
"userLimits": [ 0, 10, 10 ],
"width": 2
},
"A0RepairCentre3": {
@@ -489,6 +493,7 @@
"BLRPAIR3.PIE"
],
"type": "REPAIR FACILITY",
"userLimits": [ 0, 5, 5 ],
"width": 1
},
"A0ResearchFacility": {
@@ -512,6 +517,7 @@
"blresch4.pie"
],
"type": "RESEARCH",
"userLimits": [ 0, 5, 5 ],
"width": 2
},
"A0ResearchModule1": {
@@ -566,6 +572,7 @@
"miupbase.PIE"
],
"type": "SAT UPLINK",
"userLimits": [ 0, 1, 1 ],
"width": 2
},
"A0TankTrap": {
@@ -607,6 +614,7 @@
"blvfact2.pie"
],
"type": "VTOL FACTORY",
"userLimits": [ 0, 5, 5 ],
"width": 3
},
"A0VtolPad": {
@@ -628,6 +636,7 @@
"blvtolpd.pie"
],
"type": "REARM PAD",
"userLimits": [ 0, 50, 50 ],
"width": 1
},
"AASite-QuadBof": {
@@ -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)
@@ -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);
@@ -2141,7 +2141,6 @@ bool loadGame(const char *pGameToLoad, bool keepObjects, bool freeMem, bool User
}
}

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

@@ -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))
@@ -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;
}
}
@@ -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);
@@ -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;
}

@@ -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
@@ -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;
@@ -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;
}
}
@@ -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
@@ -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();
@@ -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++;
}
@@ -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++;
}
}
@@ -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;
}
}
}
@@ -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
@@ -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();
}
@@ -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)}
@@ -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);
}
@@ -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])}
@@ -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);
@@ -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
@@ -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;
}
}
@@ -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);

0 comments on commit 8241310

Please sign in to comment.
You can’t perform that action at this time.