make changes work with tolua++, trying to be backwards compatible

This commit is contained in:
Tim Felgentreff 2022-03-03 22:43:07 +01:00
parent f56179a421
commit bd60335b14
7 changed files with 99 additions and 21 deletions

View file

@ -44,7 +44,7 @@
/*----------------------------------------------------------------------------
-- Declarations
----------------------------------------------------------------------------*/
ENUM_CLASS FogOfWarTypes { cTiled, cEnhanced, cTiledLegacy, cNumOfTypes }; /// Types of the fog of war
enum class FogOfWarTypes { cTiled, cEnhanced, cTiledLegacy, cNumOfTypes }; /// Types of the fog of war
class CFogOfWar
{
public:

View file

@ -74,6 +74,16 @@ ENUM_CLASS SlotOption : uint8_t {
Closed
};
#if USING_TOLUAPP
class ServerSetupStateRacesArray {
public:
ServerSetupStateRacesArray() : p(nullptr) {}
int8_t& operator[](int idx) { return p[idx].Race; }
int8_t& operator[](int idx) const { return p[idx].Race; }
SettingsPresets *p;
};
#endif
/**
** Multiplayer game setup menu state
*/
@ -93,6 +103,34 @@ public:
SlotOption CompOpt[PlayerMax]; /// Free slot option selection {"Available", "Computer", "Closed" }
uint8_t Ready[PlayerMax]; /// Client ready state
// Fill in here...
#if USING_TOLUAPP
// TODO: can be removed once tolua++ is gone
inline char get_ResourcesOption() { return (char)ServerGameSettings.Resources; }
inline char get_UnitsOption() { return (char)ServerGameSettings.NumUnits; }
inline char get_FogOfWar() { return (char)!ServerGameSettings.NoFogOfWar; }
inline char get_Inside() { return (char)ServerGameSettings.Inside; }
inline char get_RevealMap() { return (char)ServerGameSettings.RevealMap; }
inline char get_GameTypeOption() { return (char)ServerGameSettings.GameType; }
inline char get_Difficulty() { return (char)ServerGameSettings.Difficulty; }
inline char get_Opponents() { return (char)ServerGameSettings.Opponents; }
inline char set_ResourcesOption(char v) { return ServerGameSettings.Resources = v; }
inline char set_UnitsOption(char v) { return ServerGameSettings.NumUnits = v; }
inline char set_FogOfWar(char v) { return ServerGameSettings.NoFogOfWar = !v; }
inline char set_Inside(char v) { return ServerGameSettings.Inside = v; }
inline char set_RevealMap(char v) { return ServerGameSettings.RevealMap = (MapRevealModes)v; }
inline char set_GameTypeOption(char v) { return ServerGameSettings.GameType = (GameTypes)v; }
inline char set_Difficulty(char v) { return ServerGameSettings.Difficulty = v; }
inline char set_Opponents(char v) { return ServerGameSettings.Opponents = v; }
ServerSetupStateRacesArray racesArray;
inline ServerSetupStateRacesArray *get_Race() {
if (racesArray.p == nullptr) {
racesArray.p = ((SettingsPresets*)ServerGameSettings.Presets);
}
return &racesArray;
}
#endif
};
/**

View file

@ -46,7 +46,8 @@
/*----------------------------------------------------------------------------
-- TODO: Remove this once we move off of tolua++ and can properly support strongly typed enums
----------------------------------------------------------------------------*/
#if 1
#define USING_TOLUAPP 1
#if USING_TOLUAPP
// using tolua++
#define ENUM_CLASS enum
#else

View file

@ -49,11 +49,23 @@ struct SettingsPresets {
string AIScript;
int Race;
int Team;
int Type;
PlayerTypes Type;
};
enum RevealTypes {
cNoRevelation,
cAllUnits,
cBuildingsOnly
};
enum NetGameTypes {
SettingsSinglePlayerGame,
SettingsMultiPlayerGame,
Unset
};
class Settings {
int NetGameType;
NetGameTypes NetGameType;
SettingsPresets Presets[PlayerMax];
@ -61,17 +73,34 @@ class Settings {
int NumUnits;
int Opponents;
int Difficulty;
int GameType;
GameTypes GameType;
bool NoFogOfWar;
bool Inside;
int RevealMap;
int MapRichness;
MapRevealModes RevealMap;
};
$[
Settings.MapRichness = 0
$]
extern Settings GameSettings;
#define SettingsPresetMapDefault -1
enum MapRevealModes {
cHidden,
cKnown,
cExplored,
cNumOfModes
};
enum FieldOfViewTypes {
cShadowCasting,
cSimpleRadial,
NumOfTypes
};
enum GameTypes {
SettingsGameTypeMapDefault = SettingsPresetMapDefault,
SettingsGameTypeMelee = 0,

View file

@ -8,7 +8,7 @@ class CMapInfo
string Postamble;
int MapWidth;
int MapHeight;
int PlayerType[PlayerMax];
PlayerTypes PlayerType[PlayerMax];
};
class CTileset

View file

@ -14,20 +14,30 @@ int GetNetworkState();
void NetworkServerResyncClients(void);
void NetworkDetachFromServer(void);
class ServerSetupStateRacesArray {
int& operator[](int idx) { return p[idx].Race; }
int& operator[](int idx) const { return p[idx].Race; }
}
class CServerSetup {
unsigned char ResourcesOption;
unsigned char UnitsOption;
unsigned char FogOfWar;
unsigned char Inside;
unsigned char RevealMap;
unsigned char GameTypeOption;
unsigned char Difficulty;
unsigned char MapRichness;
unsigned char Opponents;
unsigned short CompOpt[PlayerMax]; // cannot use char since tolua interpret variable as string else.
unsigned short Ready[PlayerMax]; // cannot use char since tolua interpret variable as string else.
unsigned short Race[PlayerMax]; // cannot use char since tolua interpret variable as string else.
Settings ServerGameSettings;
SlotOption CompOpt[PlayerMax];
unsigned short Ready[PlayerMax]; // cannot use char since tolua interpret variable as string.
tolua_property unsigned char ResourcesOption;
tolua_property unsigned char UnitsOption;
tolua_property unsigned char FogOfWar;
tolua_property unsigned char Inside;
tolua_property unsigned char RevealMap;
tolua_property unsigned char GameTypeOption;
tolua_property unsigned char Difficulty;
tolua_property unsigned char Opponents;
tolua_property tolua_readonly ServerSetupStateRacesArray *Race;
};
$[
CServerSetup.MapRichness = 0
$]
extern CServerSetup LocalSetupState;
extern CServerSetup ServerSetupState;
extern int NetLocalHostsSlot;

View file

@ -12,7 +12,7 @@ class CPlayer
int Index;
string Name;
int Type;
PlayerTypes Type;
int Race;
string AiName;