Skip to content

Commit

Permalink
Option to enforce structure limits
Browse files Browse the repository at this point in the history
As a new option, remove structures which exceed structure limits. This
allows use of full bases while still making meaningful limits.
  • Loading branch information
topimiettinen committed Jun 26, 2019
1 parent e6ebad0 commit c59984b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/multiint.cpp
Expand Up @@ -1670,19 +1670,21 @@ static const LimitIcon limitIcons[] =
{"A0VTolFactory1", N_("VTOLs disabled."), IMAGE_NO_VTOL},
{"A0Sat-linkCentre", N_("Satellite Uplink disabled."), IMAGE_NO_UPLINK},
{"A0LasSatCommand", N_("Laser Satellite disabled."), IMAGE_NO_LASSAT},
{nullptr, N_("Structure Limits Enforced."), IMAGE_DARK_LOCKED},
};

void updateLimitFlags()
{
unsigned i;
unsigned flags = 0;
unsigned flags = ingame.flags & MPFLAGS_FORCELIMITS;

if (!ingame.bHostSetup)
{
return; // The host works out the flags.
}

for (i = 0; i < ARRAY_SIZE(limitIcons); ++i)
assert(MPFLAGS_FORCELIMITS == (1 << (ARRAY_SIZE(limitIcons) - 1)));
for (i = 0; i < ARRAY_SIZE(limitIcons) - 1; ++i) // skip last item, MPFLAGS_FORCELIMITS
{
int stat = getStructStatFromName(limitIcons[i].stat);
bool disabled = stat >= 0 && asStructureStats[stat].upgrade[0].limit == 0;
Expand Down
60 changes: 59 additions & 1 deletion src/multilimit.cpp
Expand Up @@ -52,13 +52,16 @@
#include "lib/ivis_opengl/piemode.h"
#include "lib/script/script.h"
#include "challenge.h"
#include "objmem.h"

// ////////////////////////////////////////////////////////////////////////////
// defines
#define IDLIMITS 22000
#define IDLIMITS_RETURN (IDLIMITS+1)
#define IDLIMITS_OK (IDLIMITS+2)
#define IDLIMITS_ENTRIES_START (IDLIMITS+4)
#define IDLIMITS_FORCE (IDLIMITS+3)
#define IDLIMITS_FORCEOFF (IDLIMITS+4)
#define IDLIMITS_ENTRIES_START (IDLIMITS+5)
#define IDLIMITS_ENTRIES_END (IDLIMITS+99)

#define LIMITSX 25
Expand All @@ -69,6 +72,9 @@
#define LIMITS_OKX (LIMITSW-90)
#define LIMITS_OKY (LIMITSH-42)

#define LIMITS_FORCEOFFX (LIMITSX+25)
#define LIMITS_FORCEX (LIMITSX+65)

#define BARWIDTH 480
#define BARHEIGHT 40

Expand All @@ -91,6 +97,7 @@ static inline void freeLimitSet()
free(ingame.pStructureLimits);
ingame.numStructureLimits = 0;
ingame.pStructureLimits = nullptr;
ingame.flags &= MPFLAGS_FORCELIMITS;
}
}

Expand Down Expand Up @@ -141,6 +148,29 @@ bool startLimitScreen()
psWidget->setGeometry(LIMITSX, LIMITSY, LIMITSW, LIMITSH);
}));

// force limits off button
addMultiBut(psWScreen, IDLIMITS, IDLIMITS_FORCEOFF,
LIMITS_FORCEOFFX, LIMITS_OKY,
iV_GetImageWidth(FrontImages, IMAGE_DARK_UNLOCKED),
iV_GetImageHeight(FrontImages, IMAGE_DARK_UNLOCKED),
_("Map Can Exceed Limits"), IMAGE_DARK_UNLOCKED, IMAGE_DARK_UNLOCKED, true);
// force limits button
addMultiBut(psWScreen, IDLIMITS, IDLIMITS_FORCE,
LIMITS_FORCEX, LIMITS_OKY,
iV_GetImageWidth(FrontImages, IMAGE_DARK_LOCKED),
iV_GetImageHeight(FrontImages, IMAGE_DARK_LOCKED),
_("Force Limits at Start"), IMAGE_DARK_LOCKED, IMAGE_DARK_LOCKED, true);
if (ingame.flags & MPFLAGS_FORCELIMITS)
{
widgSetButtonState(psWScreen, IDLIMITS_FORCE, WBUT_DISABLE);
widgSetButtonState(psWScreen, IDLIMITS_FORCEOFF, 0);
}
else
{
widgSetButtonState(psWScreen, IDLIMITS_FORCE, 0);
widgSetButtonState(psWScreen, IDLIMITS_FORCEOFF, WBUT_DISABLE);
}

// return button.
addMultiBut(psWScreen, IDLIMITS, IDLIMITS_RETURN,
LIMITS_OKX - 40, LIMITS_OKY,
Expand Down Expand Up @@ -218,6 +248,14 @@ void runLimitScreen()
// icons that are always about.
switch (id)
{
case IDLIMITS_FORCE:
widgSetButtonState(psWScreen, IDLIMITS_FORCE, WBUT_DISABLE);
widgSetButtonState(psWScreen, IDLIMITS_FORCEOFF, 0);
break;
case IDLIMITS_FORCEOFF:
widgSetButtonState(psWScreen, IDLIMITS_FORCE, 0);
widgSetButtonState(psWScreen, IDLIMITS_FORCEOFF, WBUT_DISABLE);
break;
case IDLIMITS_RETURN:
// reset the sliders..
for (unsigned i = 0; i < numStructureStats; ++i)
Expand Down Expand Up @@ -247,6 +285,10 @@ void runLimitScreen()

break;
case IDLIMITS_OK:
if (widgGetButtonState(psWScreen, IDLIMITS_FORCE))
{
ingame.flags |= MPFLAGS_FORCELIMITS;
}
resetReadyStatus(false);
createLimitSet();
changeTitleMode(MULTIOPTION);
Expand Down Expand Up @@ -334,6 +376,22 @@ void applyLimitSet()
for (int player = 0; player < MAX_PLAYERS; player++)
{
asStructureStats[id].upgrade[player].limit = pEntry[i].limit;

if (ingame.flags & MPFLAGS_FORCELIMITS)
{
while (asStructureStats[id].curCount[player] > asStructureStats[id].upgrade[player].limit)
{
for (STRUCTURE *psStruct = apsStructLists[player]; psStruct; psStruct = psStruct->psNext)
{
if (psStruct->pStructureType->type == asStructureStats[id].type)
{
removeStruct(psStruct, true);
break;
}
}

}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/multiplay.h
Expand Up @@ -81,6 +81,7 @@ struct MULTIPLAYERINGAME
UDWORD numStructureLimits; // number of limits
MULTISTRUCTLIMITS *pStructureLimits; // limits chunk.
uint8_t flags; ///< Bitmask, shows which structures are disabled.
#define MPFLAGS_FORCELIMITS 0x20 ///< Flag to force structure limits
UDWORD skScores[MAX_PLAYERS][2]; // score+kills for local skirmish players.
char phrases[5][255]; // 5 favourite text messages.
};
Expand Down

0 comments on commit c59984b

Please sign in to comment.