Show gamestate.h syntax highlighted
/***************************************************************************
gamestate.h
-------------------
begin : Fri Feb 4 2005
copyright : (C) 2005 by Brendon Lloyd Higgins
email : bh_doc@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it 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 GAMESTATE_H_INCLUDED
#define GAMESTATE_H_INCLUDED
#include <clientstate.h>
#include <connectstate.h>
#include <playeroptionsdialog.h>
#include <worldpos.h>
#include <mappos.h>
#include <ClanLib/network.h>
#include <ClanLib/display.h>
class MessageBox;
class Rules;
class WorldClient;
/**
* Handles the actual game, UI and media and logic and play and stuff. (Oh my?)
*/
class GameState: public ClientState {
public:
/**
* Constructor.
*/
GameState(CL_NetSession* ns, const CL_NetComputer& s,
PlayerList* p, PlayerClient* m, Rules* r, WorldClient* w,
bool sp);
/**
* Destructor.
*/
virtual ~GameState();
virtual ClientState* go(Client* c);
private:
/**
* Logic state of the game.
*/
enum LogicState {
/**
* Game progresses normally.
*/
PLAY,
/**
* Game is paused.
*/
PAUSE,
/**
* The game has ended.
*/
END,
/**
* User requested we sotp the game and return to the main menu.
*/
DISCONNECT,
/**
* User requested that we shutdown completely.
*/
QUIT
};
/**
* UI state of the game.
*/
enum UIState {
/**
* Nothing special.
*/
NOTHING,
/**
* In land manipulation mode.
*/
LAND_MANIP,
/**
* Moving the magnet.
*/
MOVING_MAGNET,
/**
* In fire column planting mode.
*/
PLACING_FIRECOLUMN,
/**
* In swamp planting mode.
*/
PLACING_SWAMP
};
/**
* Takes an onscreen coord and maps it to a world coord by taking into
* account screen offset and zoom.
* \see worldToScreen
*/
CL_Point screenToWorld(const CL_Point& p) const;
/**
* Takes a world coord and maps it to an onscreen coord by taking into
* account screen offset and zoom.
* \see screenToWorld
*/
CL_Point worldToScreen(const CL_Point& p) const;
/**
* Return the coordinates of the center of the screen.
*/
CL_Point getScreenCenterOffset() const;
/**
* Return the coordinates of the center of the screen.
* \param onWorld If not null, this will be set to true if the center pos
* is located on a world tile, otherwise it will be set false.
*/
WorldPos getScreenCenterPosLocal(bool* onWorld = 0) const;
/**
* Takes a position and moves the screen offset so that position is
* in the center. The pos is taken as literal local coords.
* \param p The pos to center at.
* \param onWorld If true, assumes \p p is valid and will use on-world tile
* coords, else will use flat coords.
*/
void centerScreenLocal(const WorldPos& p, bool onWorld = true);
/**
* Limits the offset of the display so you can't go flying off into
* the aether. This tests the current offset to make sure that the center
* of the screen is still within a flat map.
* \return true if the offset is valid, else false.
*/
bool limitDisplayOffset() const;
/**
* Handle window close signals. Quit.
*/
void onCloseWindow();
/**
* Handle keyboard input, keyup.
*/
void onInputUp(const CL_InputEvent& key);
/**
* Handle FPS counter tick.
*/
void onFrames(int fps);
/**
* Call necessary functions to undo the current UI state.
*/
void turnUIStateOff();
/**
* Move into "dragging view" state.
*/
void dragViewOn();
/**
* Move out of "dragging view" state.
*/
void dragViewOff();
/**
* Move into "moving land" state.
*/
void movingLandOn();
/**
* Move out of "moving land" state.
*/
void movingLandOff();
/**
* Handle mouse movement while dragging the view.
*/
void onMouseDragView(const CL_InputEvent& e);
/**
* Handle moving the mouse to update the corner pointer.
*/
void onMouseMoveCornerPointer(const CL_InputEvent& e);
/**
* Handle moving the mouse to update the corner pointer.
* \param x Mouse x.
* \param y Mouse y.
*/
void onMouseMoveCornerPointer(int x, int y);
/**
* Handle mouse button up.
*/
void onMouseUp(const CL_InputEvent& e);
/**
* Handle mouse button down.
*/
void onMouseDown(const CL_InputEvent& e);
/**
* Someone said something.
*/
void onSay(CL_NetPacket& packet, CL_NetComputer &computer);
/**
* Admin message recieved.
*/
void onAdmin(CL_NetPacket& packet, CL_NetComputer &computer);
/**
* Create a player.
*/
void onPlayerCreate(CL_InputSource& is);
/**
* Process a player message.
*/
void onPlayerMessage(CL_NetPacket& p);
/**
* Remove a player from the list.
*/
void onPlayerRemove(CL_NetPacket& p);
/**
* Set the "nothing" state.
*/
void onNothingState();
/**
* Pause button pressed.
*/
void onPauseButton();
/**
* Zoom in button pressed.
*/
void onZoomInButton();
/**
* Zoom out button pressed.
*/
void onZoomOutButton();
/**
* Rotate button pressed.
*/
void onRotateClockButton();
/**
* Rotate button pressed.
*/
void onRotateAntiButton();
/**
* Config button pressed.
*/
void onConfigButton();
/**
* Move magnet button pressed.
*/
void onMoveMagnetButton();
/**
* Forest button pressed.
*/
void onForestButton();
/**
* Land manip. button pressed.
*/
void onMovingLandButton();
/**
* Swamp button pressed.
*/
void onSwampButton();
/**
* Fire column button pressed.
*/
void onFireColumnButton();
/**
* Apply the player options dialog settings.
*/
void onPlayerOptionsDialogApply();
/**
* A player's colour has changed.
*/
void onPlayerColourChange(unsigned int old, PlayerClient* p);
/**
* A player's name has changed.
*/
void onPlayerNameChange(const std::string& old, PlayerClient* p);
/**
* A map tile has moved. This makes sure that any UI component that is
* following a tile (such as the corner diamonds) gets updated as necessary.
*/
void onTileMoved(const MapPos& pos);
/**
* Ask the server to move the player's magnet to \p p.
*/
void sendMoveMagnet(const WorldPos& p);
/**
* Ask the server to make a fire column at pos \p p.
*/
void sendCreateFireColumn(const WorldPos& p);
/**
* Ask the server to make a swamp near tile at \p p.
*/
void sendCreateSwamp(const MapPos& p);
/**
* The client.
*/
Client* client;
/**
* The current net session.
*/
CL_NetSession* netsession;
/**
* The server.
*/
CL_NetComputer server;
/**
* The list of players.
*/
PlayerList* players;
/**
* The local player.
*/
PlayerClient* me;
/**
* Game rules.
*/
Rules* rules;
/**
* The world.
*/
WorldClient* world;
/**
* The GUI component for the world.
*/
CL_Component* worldComp;
/**
* Current logic state.
*/
LogicState logicState;
/**
* Current ui state.
*/
UIState uiState;
/**
* Is the view being dragged?
*/
bool dragging;
/**
* Mouse view dragging slot.
*/
CL_Slot mouseViewDrag;
/**
* Mouse movement slot.
*/
CL_Slot mouseMove;
/**
* Mouse click slot.
*/
CL_Slot mouseClick;
/**
* Mouse holding position.
*/
CL_Point lastMouse;
/**
* Current offset of the world to the display.
*/
CL_Point displayOffset;
/**
* Current zoom multiplier. zoom = 2^zoomLevel
*/
double zoom;
/**
* Current zoom power. zoom = 2^zoomLevel
*/
int zoomLevel;
/**
* The major corner pointer sprite.
*/
CL_Sprite* cornerPointer;
/**
* The minor corner pointer sprite.
*/
CL_Sprite* subCornerPointer;
/**
* The location of the minor corner pointer sprites.
*/
CL_Point cornerPointerLoc[4];
/**
* Which corner is major? 0, 1, 2, 3, or -1 for none.
*/
int cornerPointerDraw;
/**
* Location of the tile that is being pointed to.
*/
MapPos cornerPointerPos;
/**
* The message box.
*/
MessageBox* messages;
/**
* The player's options.
*/
PlayerOptionsDialog* pod;
/**
* Game GUI component manager.
*/
CL_ComponentManager* componentManager;
};
#endif /* ndef GAMESTATE_H_INCLUDED */
See more files for this project here