2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 1998-2000, Matthes Bender
|
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
|
|
|
* Copyright (c) 2009-2013, The OpenClonk Team and contributors
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2009-05-08 13:28:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Main class to run the game */
|
|
|
|
|
|
|
|
#ifndef INC_C4Game
|
|
|
|
#define INC_C4Game
|
|
|
|
|
|
|
|
#include <C4Scenario.h>
|
|
|
|
#include <C4PathFinder.h>
|
|
|
|
#include <C4Extra.h>
|
|
|
|
#include "C4Scoreboard.h"
|
2009-05-26 06:10:38 +00:00
|
|
|
#include <C4PlayerControl.h>
|
2015-01-02 20:13:26 +00:00
|
|
|
#include <C4TransferZone.h>
|
2009-09-21 04:01:55 +00:00
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
class C4Game
|
2010-03-28 17:58:21 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
// used as StdCompiler-parameter
|
|
|
|
struct CompileSettings
|
2009-05-26 06:10:38 +00:00
|
|
|
{
|
2010-03-28 17:58:21 +00:00
|
|
|
bool fScenarioSection;
|
|
|
|
bool fPlayers;
|
|
|
|
bool fExact;
|
2014-10-03 21:12:43 +00:00
|
|
|
bool fSync;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2014-10-03 21:12:43 +00:00
|
|
|
CompileSettings(bool fScenarioSection, bool fPlayers, bool fExact, bool fSync)
|
|
|
|
: fScenarioSection(fScenarioSection), fPlayers(fPlayers), fExact(fExact), fSync(fSync) { }
|
2010-03-28 17:58:21 +00:00
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
// struct of keyboard set and indexed control key
|
|
|
|
struct C4KeySetCtrl
|
|
|
|
{
|
|
|
|
int32_t iKeySet, iCtrl;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
C4KeySetCtrl(int32_t iKeySet, int32_t iCtrl) : iKeySet(iKeySet), iCtrl(iCtrl) {}
|
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
public:
|
|
|
|
C4Game();
|
|
|
|
~C4Game();
|
2011-01-19 01:13:51 +00:00
|
|
|
|
2011-03-13 15:46:18 +00:00
|
|
|
C4GameParameters &Parameters;
|
2014-09-27 14:04:48 +00:00
|
|
|
class C4ScenarioParameters &StartupScenarioParameters; // parameters given on command line or during startup UI
|
2010-03-28 17:58:21 +00:00
|
|
|
C4ClientList &Clients; // Shortcut
|
|
|
|
C4TeamList &Teams; // Shortcut
|
|
|
|
C4PlayerInfoList &PlayerInfos; // Shortcut
|
|
|
|
C4PlayerInfoList &RestorePlayerInfos; // Shortcut
|
2011-03-11 02:43:38 +00:00
|
|
|
C4RoundResults &RoundResults;
|
2010-03-28 17:58:21 +00:00
|
|
|
C4Scenario C4S;
|
2014-09-23 21:02:03 +00:00
|
|
|
class C4ScenarioParameterDefs &ScenarioParameterDefs;
|
2010-03-28 17:58:21 +00:00
|
|
|
C4ComponentHost Info;
|
|
|
|
C4ComponentHost Title;
|
|
|
|
C4ComponentHost Names;
|
|
|
|
C4ComponentHost GameText;
|
2011-03-02 17:13:43 +00:00
|
|
|
C4LangStringTable MainSysLangStringTable, ScenarioLangStringTable;
|
2010-03-28 17:58:21 +00:00
|
|
|
StdStrBuf PlayerNames;
|
|
|
|
C4Control &Input; // shortcut
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
C4PathFinder PathFinder;
|
|
|
|
C4TransferZones TransferZones;
|
|
|
|
C4Group ScenarioFile;
|
|
|
|
C4GroupSet GroupSet;
|
|
|
|
C4Group *pParentGroup;
|
|
|
|
C4Extra Extra;
|
2013-12-22 22:47:40 +00:00
|
|
|
class C4ScenarioObjectsScriptHost *pScenarioObjectsScript;
|
2010-03-28 17:58:21 +00:00
|
|
|
C4ScenarioSection *pScenarioSections, *pCurrentScenarioSection;
|
|
|
|
C4Effect *pGlobalEffects;
|
|
|
|
C4PlayerControlDefs PlayerControlDefs;
|
2011-03-30 20:11:47 +00:00
|
|
|
C4PlayerControlAssignmentSets PlayerControlUserAssignmentSets, PlayerControlDefaultAssignmentSets;
|
2010-03-28 17:58:21 +00:00
|
|
|
C4Scoreboard Scoreboard;
|
2011-03-11 02:43:38 +00:00
|
|
|
C4Network2Stats *pNetworkStatistics; // may be NULL if no statistics are recorded
|
|
|
|
C4KeyboardInput &KeyboardInput;
|
|
|
|
C4FileMonitor *pFileMonitor;
|
|
|
|
C4GameSec1Timer *pSec1Timer;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
char CurrentScenarioSection[C4MaxName+1];
|
|
|
|
char ScenarioFilename[_MAX_PATH+1];
|
|
|
|
StdCopyStrBuf ScenarioTitle;
|
|
|
|
char PlayerFilenames[20*_MAX_PATH+1];
|
|
|
|
char DefinitionFilenames[20*_MAX_PATH+1];
|
|
|
|
char DirectJoinAddress[_MAX_PATH+1];
|
2011-03-11 02:43:38 +00:00
|
|
|
C4Network2Reference *pJoinReference;
|
2010-03-28 17:58:21 +00:00
|
|
|
int32_t StartupPlayerCount;
|
|
|
|
int32_t FPS,cFPS;
|
|
|
|
int32_t HaltCount;
|
|
|
|
bool GameOver;
|
|
|
|
bool Evaluated;
|
|
|
|
bool GameOverDlgShown;
|
|
|
|
bool fScriptCreatedObjects;
|
|
|
|
bool fLobby;
|
|
|
|
int32_t iLobbyTimeout;
|
|
|
|
bool fObserve;
|
|
|
|
bool fReferenceDefinitionOverride;
|
|
|
|
bool NetworkActive;
|
|
|
|
bool Record;
|
|
|
|
StdStrBuf RecordDumpFile;
|
|
|
|
StdStrBuf RecordStream;
|
|
|
|
bool TempScenarioFile;
|
|
|
|
bool fPreinited; // set after PreInit has been called; unset by Clear and Default
|
|
|
|
int32_t FrameCounter;
|
|
|
|
int32_t iTick2,iTick3,iTick5,iTick10,iTick35,iTick255,iTick1000;
|
|
|
|
bool TimeGo;
|
|
|
|
int32_t Time;
|
|
|
|
int32_t StartTime;
|
|
|
|
int32_t InitProgress; int32_t LastInitProgress; int32_t LastInitProgressShowTime;
|
|
|
|
int32_t RandomSeed;
|
|
|
|
bool GameGo;
|
|
|
|
bool FullSpeed;
|
|
|
|
int32_t FrameSkip; bool DoSkipFrame;
|
|
|
|
bool fResortAnyObject; // if set, object list will be checked for unsorted objects next frame
|
|
|
|
bool IsRunning; // (NoSave) if set, the game is running; if not, just the startup message board is painted
|
|
|
|
bool PointersDenumerated; // (NoSave) set after object pointers have been denumerated
|
|
|
|
size_t StartupLogPos, QuitLogPos; // current log positions when game was last started and cleared
|
|
|
|
bool fQuitWithError; // if set, game shut down irregularly
|
|
|
|
int32_t iMusicLevel; // scenario-defined music level
|
|
|
|
// current play list
|
|
|
|
StdCopyStrBuf PlayList;
|
|
|
|
bool DebugMode;
|
|
|
|
// next mission to be played after this one
|
|
|
|
StdCopyStrBuf NextMission, NextMissionText, NextMissionDesc;
|
|
|
|
// debug settings
|
2010-10-04 19:39:19 +00:00
|
|
|
uint16_t DebugPort; StdStrBuf DebugPassword, DebugHost; int DebugWait;
|
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
// Init and execution
|
|
|
|
void Clear();
|
|
|
|
void Abort(bool fApproved = false); // hard-quit on Esc+Y (/J/O)
|
|
|
|
void Evaluate();
|
|
|
|
void ShowGameOverDlg();
|
|
|
|
bool DoKeyboardInput(C4KeyCode vk_code, C4KeyEventType eEventType, bool fAlt, bool fCtrl, bool fShift, bool fRepeated, class C4GUI::Dialog *pForDialog=NULL, bool fPlrCtrlOnly=false, int32_t iStrength=-1);
|
2015-03-22 08:58:43 +00:00
|
|
|
void DrawCrewOverheadText(C4TargetFacet &cgo, int32_t iPlayer);
|
2010-03-28 17:58:21 +00:00
|
|
|
void FixRandom(int32_t iSeed);
|
|
|
|
bool Init();
|
|
|
|
bool PreInit();
|
2010-10-04 19:39:19 +00:00
|
|
|
void SetScenarioFilename(const char*);
|
2011-09-12 21:25:16 +00:00
|
|
|
bool HasScenario() { return *DirectJoinAddress || *ScenarioFilename || RecordStream.getSize(); }
|
2010-03-28 17:58:21 +00:00
|
|
|
bool Execute();
|
2011-03-11 02:43:38 +00:00
|
|
|
C4Player *JoinPlayer(const char *szFilename, int32_t iAtClient, const char *szAtClientName, C4PlayerInfo *pInfo);
|
2010-03-28 17:58:21 +00:00
|
|
|
bool DoGameOver();
|
|
|
|
bool CanQuickSave();
|
|
|
|
bool QuickSave(const char *strFilename, const char *strTitle, bool fForceSave=false);
|
|
|
|
void SetInitProgress(float fToProgress);
|
|
|
|
void OnResolutionChanged(unsigned int iXRes, unsigned int iYRes); // update anything that's dependant on screen resolution
|
2012-10-08 22:54:34 +00:00
|
|
|
void OnKeyboardLayoutChanged();
|
2010-03-28 17:58:21 +00:00
|
|
|
void InitFullscreenComponents(bool fRunning);
|
|
|
|
bool ToggleChat();
|
|
|
|
// Pause
|
|
|
|
bool TogglePause();
|
|
|
|
bool Pause();
|
|
|
|
bool Unpause();
|
|
|
|
bool IsPaused();
|
|
|
|
// Network
|
|
|
|
void Synchronize(bool fSavePlayerFiles);
|
|
|
|
void SyncClearance();
|
|
|
|
bool ReSync();
|
|
|
|
void SyncCheckFiles(); // check if files are in sync
|
|
|
|
// Editing
|
|
|
|
bool DropFile(const char *szFilename, float iX, float iY);
|
|
|
|
bool DropDef(C4ID id, float iX, float iY);
|
|
|
|
bool LoadDef(const char *szFilename);
|
|
|
|
bool ReloadFile(const char *szPath);
|
|
|
|
bool ReloadDef(C4ID id);
|
|
|
|
bool ReloadParticle(const char *szName);
|
|
|
|
// Object functions
|
2010-10-29 22:05:36 +00:00
|
|
|
void ClearPointers(C4Object *cobj);
|
2010-03-28 17:58:21 +00:00
|
|
|
C4Object *CreateObject(C4PropList * type, C4Object *pCreator, int32_t owner=NO_OWNER,
|
2015-01-11 21:04:35 +00:00
|
|
|
int32_t x=50, int32_t y=50, int32_t r=0, bool grow_from_center=false,
|
2010-05-04 15:35:18 +00:00
|
|
|
C4Real xdir=Fix0, C4Real ydir=Fix0, C4Real rdir=Fix0, int32_t iController=NO_OWNER);
|
2010-03-28 17:58:21 +00:00
|
|
|
C4Object *CreateObject(C4ID type, C4Object *pCreator, int32_t owner=NO_OWNER,
|
2015-01-11 21:04:35 +00:00
|
|
|
int32_t x=50, int32_t y=50, int32_t r=0, bool grow_from_center=false,
|
2010-05-04 15:35:18 +00:00
|
|
|
C4Real xdir=Fix0, C4Real ydir=Fix0, C4Real rdir=Fix0, int32_t iController=NO_OWNER);
|
2010-03-28 17:58:21 +00:00
|
|
|
C4Object *CreateObjectConstruction(C4PropList * type,
|
|
|
|
C4Object *pCreator,
|
|
|
|
int32_t owner,
|
|
|
|
int32_t ctx=0, int32_t bty=0,
|
|
|
|
int32_t con=1, bool terrain=false);
|
|
|
|
C4Object *CreateInfoObject(C4ObjectInfo *cinf, int32_t owner,
|
|
|
|
int32_t tx=50, int32_t ty=50);
|
2010-12-27 19:15:55 +00:00
|
|
|
C4Object *OverlapObject(int32_t tx, int32_t ty, int32_t wdt, int32_t hgt, int32_t Plane);
|
2013-03-03 18:25:18 +00:00
|
|
|
C4Object *FindObject(C4Def * pDef,
|
2010-03-28 17:58:21 +00:00
|
|
|
int32_t iX=0, int32_t iY=0, int32_t iWdt=0, int32_t iHgt=0,
|
|
|
|
DWORD ocf=OCF_All,
|
|
|
|
C4Object *pFindNext=NULL);
|
|
|
|
C4Object *FindVisObject( // find object in view at pos, regarding parallaxity and visibility (but not distance)
|
|
|
|
float tx, float ty, int32_t iPlr, const C4Facet &fctViewportGame, const C4Facet &fctViewportGUI,
|
|
|
|
float iX, float iY,
|
|
|
|
DWORD category,
|
|
|
|
float gui_x, float gui_y);
|
|
|
|
/* int32_t ObjectCount(C4ID id,
|
|
|
|
int32_t x=0, int32_t y=0, int32_t wdt=0, int32_t hgt=0,
|
|
|
|
DWORD ocf=OCF_All,
|
|
|
|
const char *szAction=NULL, C4Object *pActionTarget=NULL,
|
|
|
|
C4Object *pExclude=NULL,
|
|
|
|
C4Object *pContainer=NULL,
|
|
|
|
int32_t iOwner=ANY_OWNER);*/
|
|
|
|
int32_t ObjectCount(C4ID id);
|
2014-01-22 20:46:50 +00:00
|
|
|
void CastObjects(C4ID id, C4Object *pCreator, int32_t num, int32_t level, int32_t tx, int32_t ty, int32_t iOwner=NO_OWNER, int32_t iController=NO_OWNER, C4ValueArray *out_objects=NULL);
|
2015-07-31 03:13:31 +00:00
|
|
|
C4Object *PlaceVegetation(C4PropList *def, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, int32_t iGrowth, C4PropList *shape_proplist, C4PropList * out_pos_proplist);
|
2012-04-18 13:23:35 +00:00
|
|
|
C4Object *PlaceAnimal(C4PropList *def);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
bool LoadScenarioSection(const char *szSection, DWORD dwFlags);
|
|
|
|
bool SaveDesc(C4Group &hGroup, bool fSaveGame=false, bool fReference=false, bool fLobby=false, bool fUnregistered=false, bool fRecord=false);
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2012-01-10 21:40:46 +00:00
|
|
|
bool DrawTextSpecImage(C4Facet& fctTarget, const char *szSpec, class C4DrawTransform* pTransform, uint32_t dwClr=0xff);
|
|
|
|
float GetTextSpecImageAspect(const char* szSpec);
|
2014-07-05 13:25:30 +00:00
|
|
|
bool DrawPropListSpecImage(C4Facet& fctTarget, C4PropList *pSpec);
|
2010-03-28 17:58:21 +00:00
|
|
|
bool SpeedUp();
|
|
|
|
bool SlowDown();
|
|
|
|
bool InitKeyboard(); // register main keyboard input functions
|
|
|
|
void UpdateLanguage();
|
|
|
|
bool InitPlayerControlSettings();
|
2011-03-30 20:11:47 +00:00
|
|
|
bool InitPlayerControlUserSettings(); // merge player control default settings and config overloads into user setting
|
2014-10-03 21:42:31 +00:00
|
|
|
void SetDefaultGamma();
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
protected:
|
2011-01-19 01:13:51 +00:00
|
|
|
void Default();
|
2010-03-28 17:58:21 +00:00
|
|
|
void InitInEarth();
|
|
|
|
void InitVegetation();
|
|
|
|
void InitAnimals();
|
|
|
|
void InitGoals();
|
|
|
|
void InitRules();
|
|
|
|
void InitValueOverloads();
|
|
|
|
void InitEnvironment();
|
|
|
|
void CloseScenario();
|
|
|
|
void DeleteObjects(bool fDeleteInactive);
|
|
|
|
void ExecObjects();
|
|
|
|
void Ticks();
|
|
|
|
bool CheckObjectEnumeration();
|
|
|
|
bool LoadScenarioComponents();
|
|
|
|
public:
|
2011-03-02 17:13:43 +00:00
|
|
|
bool LoadAdditionalSystemGroup(class C4Group &parent_group);
|
2010-03-28 17:58:21 +00:00
|
|
|
bool SaveGameTitle(C4Group &hGroup);
|
|
|
|
protected:
|
2011-03-26 22:59:35 +00:00
|
|
|
bool InitGame(C4Group &hGroup, bool fLoadSection, bool fLoadSky, C4ValueNumbers *);
|
2010-03-28 17:58:21 +00:00
|
|
|
bool InitGameFinal();
|
|
|
|
bool InitNetworkFromAddress(const char *szAddress);
|
|
|
|
bool InitNetworkFromReference(const C4Network2Reference &Reference);
|
|
|
|
bool InitNetworkHost();
|
|
|
|
bool DoLobby();
|
|
|
|
bool PreInitControl();
|
|
|
|
bool InitControl();
|
|
|
|
bool InitScriptEngine();
|
|
|
|
bool LinkScriptEngine();
|
2011-03-26 22:59:35 +00:00
|
|
|
bool InitPlayers(C4ValueNumbers *);
|
2010-03-28 17:58:21 +00:00
|
|
|
bool InitRecord();
|
2011-03-27 14:51:14 +00:00
|
|
|
bool OpenScenario();
|
2010-03-28 17:58:21 +00:00
|
|
|
bool InitDefs();
|
|
|
|
bool InitMaterialTexture();
|
|
|
|
bool GameOverCheck();
|
|
|
|
bool PlaceInEarth(C4ID id);
|
|
|
|
public:
|
2011-03-26 22:59:35 +00:00
|
|
|
void CompileFunc(StdCompiler *pComp, CompileSettings comp, C4ValueNumbers *);
|
2014-10-03 21:12:43 +00:00
|
|
|
bool SaveData(C4Group &hGroup, bool fSaveSection, bool fSaveExact, bool fSaveSync, C4ValueNumbers *);
|
2010-03-28 17:58:21 +00:00
|
|
|
protected:
|
2014-10-03 21:12:43 +00:00
|
|
|
bool CompileRuntimeData(C4Group &hGroup, bool fLoadSection, bool exact, bool sync, C4ValueNumbers *);
|
2010-03-28 17:58:21 +00:00
|
|
|
bool StoreParticipantPlayers();
|
|
|
|
bool RecreatePlayerFiles();
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
// Object function internals
|
|
|
|
C4Object *NewObject( C4PropList *ndef, C4Object *pCreator,
|
|
|
|
int32_t owner, C4ObjectInfo *info,
|
|
|
|
int32_t tx, int32_t ty, int32_t tr,
|
2010-05-04 15:35:18 +00:00
|
|
|
C4Real xdir, C4Real ydir, C4Real rdir,
|
2015-01-11 21:04:35 +00:00
|
|
|
int32_t con, int32_t iController, bool grow_from_center);
|
2010-03-28 17:58:21 +00:00
|
|
|
void ClearObjectPtrs(C4Object *tptr);
|
|
|
|
void ObjectRemovalCheck();
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
bool ToggleDebugMode(); // dbg modeon/off if allowed
|
|
|
|
bool ActivateMenu(const char *szCommand); // exec given menu command for first local player
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
public:
|
|
|
|
bool ToggleChart(); // chart dlg on/off
|
|
|
|
void SetMusicLevel(int32_t iToLvl); // change game music volume; multiplied by config volume for real volume
|
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2010-03-28 17:58:21 +00:00
|
|
|
extern C4Game Game;
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// a global wrapper
|
|
|
|
inline StdStrBuf GetKeyboardInputName(const char *szKeyName, bool fShort = false, int32_t iIndex = 0)
|
|
|
|
{
|
|
|
|
return Game.KeyboardInput.GetKeyCodeNameByKeyName(szKeyName, fShort, iIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|