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 authored and KJeff01 committed Sep 26, 2019
1 parent 1cfb90a commit ba06ee1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/multiint.cpp
Expand Up @@ -1729,19 +1729,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
69 changes: 68 additions & 1 deletion src/multilimit.cpp
Expand Up @@ -51,13 +51,16 @@
#include "multilimit.h"
#include "lib/ivis_opengl/piemode.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 @@ -68,6 +71,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 @@ -90,6 +96,7 @@ static inline void freeLimitSet()
free(ingame.pStructureLimits);
ingame.numStructureLimits = 0;
ingame.pStructureLimits = nullptr;
ingame.flags &= MPFLAGS_FORCELIMITS;
}
}

Expand Down Expand Up @@ -140,6 +147,34 @@ 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 (challengeActive)
{
widgSetButtonState(psWScreen, IDLIMITS_FORCE, WBUT_DISABLE);
widgSetButtonState(psWScreen, IDLIMITS_FORCEOFF, WBUT_DISABLE);
}
else 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 @@ -217,6 +252,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 @@ -245,6 +288,14 @@ void runLimitScreen()

break;
case IDLIMITS_OK:
if (!challengeActive && widgGetButtonState(psWScreen, IDLIMITS_FORCE))
{
ingame.flags |= MPFLAGS_FORCELIMITS;
}
else
{
ingame.flags &= ~MPFLAGS_FORCELIMITS;
}
resetReadyStatus(false);
createLimitSet();
changeTitleMode(MULTIOPTION);
Expand Down Expand Up @@ -332,6 +383,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 @@ -82,6 +82,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 ba06ee1

Please sign in to comment.