2010-03-23 03:35:55 +01:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
2010-04-05 19:43:04 +02:00
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
2010-03-23 03:35:55 +01:00
|
|
|
|
//
|
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_GAME_H_
|
|
|
|
|
#define _GLEST_GAME_GAME_H_
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "gui.h"
|
|
|
|
|
#include "game_camera.h"
|
|
|
|
|
#include "world.h"
|
|
|
|
|
#include "ai_interface.h"
|
|
|
|
|
#include "program.h"
|
|
|
|
|
#include "chat_manager.h"
|
|
|
|
|
#include "script_manager.h"
|
|
|
|
|
#include "game_settings.h"
|
2010-05-29 08:56:32 +02:00
|
|
|
|
#include "network_interface.h"
|
2010-10-02 04:17:50 +02:00
|
|
|
|
#include "types.h"
|
2010-09-07 07:25:40 +02:00
|
|
|
|
#include "leak_dumper.h"
|
2010-03-23 03:35:55 +01:00
|
|
|
|
|
|
|
|
|
using std::vector;
|
2010-10-02 04:17:50 +02:00
|
|
|
|
using namespace Shared::Platform;
|
2010-05-07 08:46:55 +02:00
|
|
|
|
using namespace Shared::PlatformCommon;
|
2010-03-23 03:35:55 +01:00
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
class GraphicMessageBox;
|
|
|
|
|
|
2010-09-12 07:05:08 +02:00
|
|
|
|
enum LoadGameItem {
|
|
|
|
|
lgt_FactionPreview = 0x01,
|
|
|
|
|
lgt_TileSet = 0x02,
|
|
|
|
|
lgt_TechTree = 0x04,
|
|
|
|
|
lgt_Map = 0x08,
|
|
|
|
|
lgt_Scenario = 0x10,
|
|
|
|
|
|
|
|
|
|
lgt_All = (lgt_FactionPreview | lgt_TileSet | lgt_TechTree | lgt_Map | lgt_Scenario)
|
|
|
|
|
};
|
|
|
|
|
|
2010-03-23 03:35:55 +01:00
|
|
|
|
// =====================================================
|
|
|
|
|
// class Game
|
|
|
|
|
//
|
|
|
|
|
// Main game class
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-06-01 18:54:44 +02:00
|
|
|
|
//class Game: public ProgramState, public SimpleTaskCallbackInterface {
|
2011-03-22 03:02:54 +01:00
|
|
|
|
class Game: public ProgramState, public FileCRCPreCacheThreadCallbackInterface {
|
2010-03-23 03:35:55 +01:00
|
|
|
|
public:
|
|
|
|
|
enum Speed{
|
|
|
|
|
sFast,
|
|
|
|
|
sNormal,
|
|
|
|
|
sSlow
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
typedef vector<Ai*> Ais;
|
|
|
|
|
typedef vector<AiInterface*> AiInterfaces;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
//main data
|
|
|
|
|
World world;
|
|
|
|
|
AiInterfaces aiInterfaces;
|
|
|
|
|
Gui gui;
|
|
|
|
|
GameCamera gameCamera;
|
|
|
|
|
Commander commander;
|
|
|
|
|
Console console;
|
|
|
|
|
ChatManager chatManager;
|
|
|
|
|
ScriptManager scriptManager;
|
|
|
|
|
|
|
|
|
|
//misc
|
|
|
|
|
Checksum checksum;
|
|
|
|
|
string loadingText;
|
|
|
|
|
int mouse2d;
|
|
|
|
|
int mouseX, mouseY; //coords win32Api
|
2010-08-24 03:21:34 +02:00
|
|
|
|
int updateFps, lastUpdateFps, avgUpdateFps;
|
2010-10-02 04:17:50 +02:00
|
|
|
|
int totalRenderFps, renderFps, lastRenderFps, avgRenderFps,currentAvgRenderFpsTotal;
|
|
|
|
|
Uint64 tickCount;
|
2010-03-23 03:35:55 +01:00
|
|
|
|
bool paused;
|
|
|
|
|
bool gameOver;
|
|
|
|
|
bool renderNetworkStatus;
|
2010-04-14 22:49:14 +02:00
|
|
|
|
bool showFullConsole;
|
2010-12-20 21:01:14 +01:00
|
|
|
|
bool mouseMoved;
|
2010-03-23 03:35:55 +01:00
|
|
|
|
float scrollSpeed;
|
2011-04-12 01:26:50 +02:00
|
|
|
|
bool camLeftButtonDown;
|
|
|
|
|
bool camRightButtonDown;
|
|
|
|
|
bool camUpButtonDown;
|
|
|
|
|
bool camDownButtonDown;
|
|
|
|
|
|
2010-03-23 03:35:55 +01:00
|
|
|
|
Speed speed;
|
|
|
|
|
GraphicMessageBox mainMessageBox;
|
2010-07-01 08:11:14 +02:00
|
|
|
|
GraphicMessageBox errorMessageBox;
|
2010-03-23 03:35:55 +01:00
|
|
|
|
|
|
|
|
|
//misc ptr
|
|
|
|
|
ParticleSystem *weatherParticleSystem;
|
|
|
|
|
GameSettings gameSettings;
|
2010-03-24 02:28:48 +01:00
|
|
|
|
Vec2i lastMousePos;
|
2010-04-15 03:19:00 +02:00
|
|
|
|
time_t lastRenderLog2d;
|
2010-05-29 08:56:32 +02:00
|
|
|
|
DisplayMessageFunction originalDisplayMsgCallback;
|
2010-06-24 03:23:18 +02:00
|
|
|
|
bool isFirstRender;
|
2010-03-23 03:35:55 +01:00
|
|
|
|
|
2010-08-04 20:49:11 +02:00
|
|
|
|
bool quitTriggeredIndicator;
|
|
|
|
|
|
2010-08-25 20:26:17 +02:00
|
|
|
|
int original_updateFps;
|
|
|
|
|
int original_cameraFps;
|
|
|
|
|
|
2010-08-28 22:52:25 +02:00
|
|
|
|
bool captureAvgTestStatus;
|
|
|
|
|
int updateFpsAvgTest;
|
|
|
|
|
int renderFpsAvgTest;
|
|
|
|
|
|
2011-07-07 00:02:38 +02:00
|
|
|
|
int renderExtraTeamColor;
|
|
|
|
|
static const int renderTeamColorCircleBit=1;
|
|
|
|
|
static const int renderTeamColorPlaneBit=2;
|
|
|
|
|
|
2010-09-11 18:14:03 +02:00
|
|
|
|
bool photoModeEnabled;
|
2011-06-10 00:54:45 +02:00
|
|
|
|
bool visibleHUD;
|
2011-06-21 01:48:22 +02:00
|
|
|
|
bool withRainEffect;
|
2010-10-29 18:27:22 +02:00
|
|
|
|
Program *program;
|
2010-09-11 18:14:03 +02:00
|
|
|
|
|
2011-01-20 09:19:14 +01:00
|
|
|
|
bool gameStarted;
|
|
|
|
|
|
2011-04-05 08:32:23 +02:00
|
|
|
|
time_t lastMaxUnitCalcTime;
|
|
|
|
|
|
2011-09-21 08:51:28 +02:00
|
|
|
|
PopupMenu popupMenu;
|
|
|
|
|
PopupMenu popupMenuSwitchTeams;
|
|
|
|
|
|
|
|
|
|
std::map<int,int> switchTeamIndexMap;
|
|
|
|
|
GraphicMessageBox switchTeamConfirmMessageBox;
|
|
|
|
|
|
|
|
|
|
int exitGamePopupMenuIndex;
|
|
|
|
|
int joinTeamPopupMenuIndex;
|
2011-10-03 02:36:28 +02:00
|
|
|
|
int keyboardSetupPopupMenuIndex;
|
|
|
|
|
ProgramState *currentUIState;
|
2011-09-21 08:51:28 +02:00
|
|
|
|
|
2011-09-24 23:07:15 +02:00
|
|
|
|
bool masterserverMode;
|
|
|
|
|
|
2010-03-23 03:35:55 +01:00
|
|
|
|
public:
|
2011-03-22 03:02:54 +01:00
|
|
|
|
Game();
|
2011-09-24 23:07:15 +02:00
|
|
|
|
Game(Program *program, const GameSettings *gameSettings, bool masterserverMode);
|
2010-03-23 03:35:55 +01:00
|
|
|
|
~Game();
|
|
|
|
|
|
|
|
|
|
//get
|
2010-12-19 09:04:25 +01:00
|
|
|
|
GameSettings *getGameSettings() {return &gameSettings;}
|
|
|
|
|
const GameSettings *getReadOnlyGameSettings() const {return &gameSettings;}
|
2010-03-23 03:35:55 +01:00
|
|
|
|
|
|
|
|
|
const GameCamera *getGameCamera() const {return &gameCamera;}
|
|
|
|
|
GameCamera *getGameCamera() {return &gameCamera;}
|
|
|
|
|
const Commander *getCommander() const {return &commander;}
|
|
|
|
|
Gui *getGui() {return &gui;}
|
|
|
|
|
const Gui *getGui() const {return &gui;}
|
|
|
|
|
Commander *getCommander() {return &commander;}
|
|
|
|
|
Console *getConsole() {return &console;}
|
|
|
|
|
ScriptManager *getScriptManager() {return &scriptManager;}
|
|
|
|
|
World *getWorld() {return &world;}
|
|
|
|
|
const World *getWorld() const {return &world;}
|
|
|
|
|
|
2011-01-30 00:50:21 +01:00
|
|
|
|
bool getPaused() const { return paused;}
|
|
|
|
|
void setPaused(bool value);
|
2010-09-10 14:15:21 +02:00
|
|
|
|
const int getTotalRenderFps() const {return totalRenderFps;}
|
2011-07-07 00:02:38 +02:00
|
|
|
|
|
|
|
|
|
void toggleTeamColorMarker();
|
2010-03-23 03:35:55 +01:00
|
|
|
|
//init
|
2010-09-12 07:05:08 +02:00
|
|
|
|
virtual void load(LoadGameItem loadTypes);
|
2010-03-23 03:35:55 +01:00
|
|
|
|
virtual void load();
|
|
|
|
|
virtual void init();
|
2010-09-12 07:05:08 +02:00
|
|
|
|
virtual void init(bool initForPreviewOnly);
|
2010-03-23 03:35:55 +01:00
|
|
|
|
virtual void update();
|
|
|
|
|
virtual void updateCamera();
|
|
|
|
|
virtual void render();
|
|
|
|
|
virtual void tick();
|
|
|
|
|
|
|
|
|
|
//event managing
|
2011-06-26 03:55:08 +02:00
|
|
|
|
virtual void keyDown(SDL_KeyboardEvent key);
|
|
|
|
|
virtual void keyUp(SDL_KeyboardEvent key);
|
|
|
|
|
virtual void keyPress(SDL_KeyboardEvent c);
|
2010-03-23 03:35:55 +01:00
|
|
|
|
virtual void mouseDownLeft(int x, int y);
|
|
|
|
|
virtual void mouseDownRight(int x, int y);
|
2010-12-20 21:01:14 +01:00
|
|
|
|
virtual void mouseUpCenter(int x, int y);
|
2010-03-23 03:35:55 +01:00
|
|
|
|
virtual void mouseUpLeft(int x, int y);
|
|
|
|
|
virtual void mouseDoubleClickLeft(int x, int y);
|
|
|
|
|
virtual void eventMouseWheel(int x, int y, int zDelta);
|
|
|
|
|
virtual void mouseMove(int x, int y, const MouseState *mouseState);
|
|
|
|
|
|
2010-07-29 07:24:51 +02:00
|
|
|
|
virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); }
|
2010-05-07 08:46:55 +02:00
|
|
|
|
|
2010-08-04 20:49:11 +02:00
|
|
|
|
virtual bool quitTriggered();
|
2010-08-07 06:49:06 +02:00
|
|
|
|
virtual Stats quitAndToggleState();
|
|
|
|
|
Stats quitGame();
|
|
|
|
|
static void exitGameState(Program *program, Stats &endStats);
|
2010-08-04 20:49:11 +02:00
|
|
|
|
|
2010-08-28 22:52:25 +02:00
|
|
|
|
void startPerformanceTimer();
|
|
|
|
|
void endPerformanceTimer();
|
|
|
|
|
Vec2i getPerformanceTimerResults();
|
|
|
|
|
|
2011-03-31 00:14:51 +02:00
|
|
|
|
static Texture2D * findFactionLogoTexture(const GameSettings *settings, Logger *logger=NULL,string factionLogoFilter="loading_screen.*", bool useTechDefaultIfFilterNotFound=true);
|
|
|
|
|
static string findFactionLogoFile(const GameSettings *settings, Logger *logger=NULL, string factionLogoFilter="loading_screen.*");
|
|
|
|
|
static string extractScenarioLogoFile(const GameSettings *settings, string &result, bool &loadingImageUsed, Logger *logger=NULL, string factionLogoFilter="loading_screen.*");
|
|
|
|
|
static string extractFactionLogoFile(bool &loadingImageUsed, string factionName, string scenarioDir, string techName, Logger *logger=NULL, string factionLogoFilter="loading_screen.*");
|
|
|
|
|
static string extractTechLogoFile(string scenarioDir, string techName, bool &loadingImageUsed, Logger *logger=NULL,string factionLogoFilter="loading_screen.*");
|
2011-03-22 03:02:54 +01:00
|
|
|
|
|
2011-06-09 02:59:03 +02:00
|
|
|
|
void loadHudTexture(const GameSettings *settings);
|
2010-08-31 08:38:27 +02:00
|
|
|
|
|
2010-09-30 02:49:57 +02:00
|
|
|
|
bool getGameOver() { return gameOver; }
|
2011-01-20 09:19:14 +01:00
|
|
|
|
bool hasGameStarted() { return gameStarted;}
|
2011-03-22 03:02:54 +01:00
|
|
|
|
virtual vector<Texture2D *> processTech(string techName);
|
2011-03-28 23:04:47 +02:00
|
|
|
|
virtual void consoleAddLine(string line);
|
2010-09-30 02:49:57 +02:00
|
|
|
|
|
2010-03-23 03:35:55 +01:00
|
|
|
|
private:
|
|
|
|
|
//render
|
|
|
|
|
void render3d();
|
|
|
|
|
void render2d();
|
|
|
|
|
|
|
|
|
|
//misc
|
|
|
|
|
void checkWinner();
|
|
|
|
|
void checkWinnerStandard();
|
|
|
|
|
void checkWinnerScripted();
|
|
|
|
|
bool hasBuilding(const Faction *faction);
|
|
|
|
|
void incSpeed();
|
|
|
|
|
void decSpeed();
|
|
|
|
|
int getUpdateLoops();
|
2010-07-01 08:11:14 +02:00
|
|
|
|
|
2010-03-23 03:35:55 +01:00
|
|
|
|
void showLoseMessageBox();
|
|
|
|
|
void showWinMessageBox();
|
|
|
|
|
void showMessageBox(const string &text, const string &header, bool toggle);
|
2010-07-01 08:11:14 +02:00
|
|
|
|
void showErrorMessageBox(const string &text, const string &header, bool toggle);
|
|
|
|
|
|
2010-05-07 08:46:55 +02:00
|
|
|
|
void renderWorker();
|
2010-05-29 08:56:32 +02:00
|
|
|
|
static int ErrorDisplayMessage(const char *msg, bool exitApp);
|
2010-10-19 01:09:43 +02:00
|
|
|
|
|
|
|
|
|
void ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRole role);
|
2011-04-12 01:26:50 +02:00
|
|
|
|
void calcCameraMoveX();
|
|
|
|
|
void calcCameraMoveZ();
|
2011-09-21 08:51:28 +02:00
|
|
|
|
|
|
|
|
|
int getFirstUnusedTeamNumber();
|
2010-03-23 03:35:55 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
|
|
#endif
|