1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#include "StdAfx.h"
#include "GlobalSynced.h"
#include <assert.h>
#include <cstring>
#include "Game/GameSetup.h"
#include "Game/PlayerHandler.h"
#include "ExternalAI/SkirmishAIHandler.h"
#include "Lua/LuaGaia.h"
#include "Lua/LuaRules.h"
#include "Team.h"
#include "TeamHandler.h"
#include "GlobalConstants.h"
#include "Util.h"
/**
* @brief global synced
*
* Global instance of CGlobalSyncedStuff
*/
CGlobalSyncedStuff* gs;
CR_BIND(CGlobalSyncedStuff,);
CR_REG_METADATA(CGlobalSyncedStuff, (
CR_MEMBER(frameNum),
CR_MEMBER(speedFactor),
CR_MEMBER(userSpeedFactor),
CR_MEMBER(paused),
CR_MEMBER(mapx),
CR_MEMBER(mapy),
CR_MEMBER(mapSquares),
CR_MEMBER(hmapx),
CR_MEMBER(hmapy),
CR_MEMBER(pwr2mapx),
CR_MEMBER(pwr2mapy),
CR_MEMBER(tempNum),
CR_MEMBER(godMode),
CR_MEMBER(globalLOS),
CR_MEMBER(cheatEnabled),
CR_MEMBER(noHelperAIs),
CR_MEMBER(editDefsEnabled),
CR_MEMBER(useLuaGaia),
CR_MEMBER(randSeed),
CR_MEMBER(initRandSeed),
CR_RESERVED(64)
));
/**
* Initializes variables in CGlobalSyncedStuff
*/
CGlobalSyncedStuff::CGlobalSyncedStuff()
{
hmapx = 256;
hmapy = 256;
randSeed = 18655;
initRandSeed = randSeed;
frameNum = 0;
speedFactor = 1;
userSpeedFactor = 1;
paused = false;
godMode = false;
globalLOS = false;
cheatEnabled = false;
noHelperAIs = false;
editDefsEnabled = false;
tempNum = 2;
useLuaGaia = true;
// TODO: put this somewhere else (playerHandler is unsynced, even)
playerHandler = new CPlayerHandler();
teamHandler = new CTeamHandler();
}
CGlobalSyncedStuff::~CGlobalSyncedStuff()
{
// TODO: put this somewhere else (playerHandler is unsynced, even)
SafeDelete(playerHandler);
SafeDelete(teamHandler);
}
void CGlobalSyncedStuff::LoadFromSetup(const CGameSetup* setup)
{
noHelperAIs = !!setup->noHelperAIs;
useLuaGaia = CLuaGaia::SetConfigString(setup->luaGaiaStr);
CLuaRules::SetConfigString(setup->luaRulesStr);
// TODO: this call is unsynced, technically
playerHandler->LoadFromSetup(setup);
skirmishAIHandler.LoadFromSetup(*setup);
teamHandler->LoadFromSetup(setup);
}
/**
* @return synced random integer
*
* returns a synced random integer
*/
int CGlobalSyncedStuff::randInt()
{
randSeed = (randSeed * 214013L + 2531011L);
return randSeed & RANDINT_MAX;
}
/**
* @return synced random float
*
* returns a synced random float
*/
float CGlobalSyncedStuff::randFloat()
{
randSeed = (randSeed * 214013L + 2531011L);
return float(randSeed & RANDINT_MAX)/RANDINT_MAX;
}
/**
* @return synced random vector
*
* returns a synced random vector
*/
float3 CGlobalSyncedStuff::randVector()
{
float3 ret;
do {
ret.x = randFloat()*2-1;
ret.y = randFloat()*2-1;
ret.z = randFloat()*2-1;
} while(ret.SqLength()>1);
return ret;
}
|