1 /***************************************************************************
2                           gamecore.h  -  The core of the game
3                              -------------------
4     begin                : do okt 14 2004
5     copyright            : (C) 2004 by CJP
6     email                : cornware-cjp@users.sourceforge.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef GAMECORE_H
19 #define GAMECORE_H
20 
21 #include <vector>
22 namespace std {}
23 using namespace std;
24 
25 //Frequently used
26 #include "cstring.h"
27 #include "lconfig.h"
28 #include "usmacros.h"
29 #include "timer.h"
30 
31 //Simulation stuff
32 #include "playercontrol.h"
33 #include "clientplayercontrol.h"
34 #include "rulecontrol.h"
35 #include "world.h"
36 
37 //Player stuff
38 #include "objectchoice.h"
39 #include "player.h"
40 
41 //Other things
42 #include "filecontrol.h"
43 #include "hiscorefile.h"
44 
45 /**
46   *@author CJP
47   */
48 
49 class CGameCore {
50 public:
51 	CGameCore();
52 	virtual ~CGameCore();
53 
54 	//step 1: initialise network connection etc.
55 	//the last function call defines the current state
56 	bool initLocalGame(const CString &trackfile);
57 	bool initClientGame(const CString &host, unsigned int port, bool keepOldReplay=false);
58 	bool initReplayGame(const CString &replayfile);
59 
60 	//step 2: add players
61 	bool addPlayer(CPlayer *p, CObjectChoice choice);
62 
63 	//step 3: wait for the start signal and load everything
64 	typedef bool (* LoadStatusCallback) (const CString &t, float);
65 	virtual bool readyAndLoad(LoadStatusCallback callBackFun = NULL);
66 
67 	//step 4: start the game time counter
68 	void setStartTime(float offset = 0.0);
69 
70 	//step 5: Play
71 	virtual bool update(); //true = continue false = leave
72 	void setPause(bool pause = true);
73 
74 	//step 6: Get hiscore+replay data and stop game (go back to step 1 or 2)
75 	//this does not undo step 1
76 	//to stop a network connection, init a local game
77 	void stopGame(bool saveHiscore = true);
78 
79 	//step 7: Get result information of last game (hiscore, replay)
80 	CHiscore getHiscore(bool onlyThisGame = false);
getReplayFile()81 	CString getReplayFile() {return m_ReplayFile;}
82 
83 	//some tools
84 	//TODO: place these e.g. in CWorld
85 	bool isLocalPlayer(unsigned int ID);
86 
getFPS()87 	float getFPS(){return m_FPS;}
88 
89 protected:
90 	CWorld *m_World;
91 	vector<CPlayer *> m_Players;
92 	CPlayerControl *m_PCtrl;
93 	vector<CSimulation *> m_Simulations;
94 	CClientNet *m_ClientNet;
95 	CString m_TrackFile;
96 
97 	CString m_ReplayFile;
98 
99 	enum {eLocalGame, eNetworkGame, eReplayGame} m_GameType;
100 
101 	CHiscore m_LastHiscores;
102 	CHiscore m_LastHiscoresThisGame;
103 
104 	CTimer m_Timer; //for the FPS counter
105 	float m_TimerOffset; //timer offset relative to game time
106 	float m_PauseStartTime; //timer time when the last pause started
107 	float m_GlobalTimeAccel; //time acceleration (1.0 = normal)
108 	float m_FPS;
109 
110 	virtual void loadTrackData();
111 	virtual void loadMovObjData();
112 
113 	void collectHiscoreData(bool saveHiscore);
114 
115 	void resetGame();
116 	void unloadGame();
117 	virtual void unloadData();
118 };
119 
120 #endif
121