X-Git-Url: http://git.maemo.org/git/?p=lordsawar;a=blobdiff_plain;f=src%2Fgame.h;fp=src%2Fgame.h;h=ba8b79990fdeff629c06cc01a2ea92ff65637cca;hp=0000000000000000000000000000000000000000;hb=9eda00ff73353c55ecef6f82131166d5d4a85e29;hpb=3d34d4aa85a929f912464f71158396a388274f27 diff --git a/src/game.h b/src/game.h new file mode 100644 index 0000000..ba8b799 --- /dev/null +++ b/src/game.h @@ -0,0 +1,253 @@ +// Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine +// Copyright (C) 2007, 2008 Ole Laursen +// +// 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 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Library General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301, USA. + +#ifndef GAME_H +#define GAME_H + +#include +#include +#include +#include +#include +#include + +#include "rectangle.h" +#include "sidebar-stats.h" +#include "map-tip-position.h" +#include "callback-enums.h" +#include "army.h" +#include "fight.h" +#include "game-parameters.h" +#include "player.h" +#include "defs.h" + +class NextTurn; +class GameBigMap; +class SmallMap; +class GameScenario; +class Hero; +class City; +class Stack; +class Player; +class Temple; +class Ruin; +class Signpost; +class Fight; +class Quest; +class Stack; +class Reward; +class StackTile; +class Sage; + +/** Controls a game. + * + * Manages the big and small map, the game scenario and who's turn it is, etc. + * It's mostly a puppeteer class that connects the various other classes with + * signals and callbacks. + * + */ +class Game +{ + public: + Game(GameScenario* gameScenario, NextTurn *nextTurn); + ~Game(); + + void redraw(); + void blank(bool on); + + void select_next_movable_stack(); + void center_selected_stack(); + void defend_selected_stack(); + void park_selected_stack(); + void deselect_selected_stack(); + void search_selected_stack(); + void search_stack(Stack *stack); + void move_selected_stack_along_path(); + void move_selected_stack_northwest(); + void move_selected_stack_north(); + void move_selected_stack_northeast(); + void move_selected_stack_east(); + void move_selected_stack_west(); + void move_selected_stack_southwest(); + void move_selected_stack_south(); + void move_selected_stack_southeast(); + void move_all_stacks(); + void end_turn(); + void recalculate_moves_for_stack(Stack *s); + + void startGame(); // initiate game flow + void loadGame(); + void stopGame(); // stop game flow, clean up + // save current game, returns true if successful + bool saveGame(std::string file); + bool saveTurnFile(std::string file); + + static GameScenario *getScenario(); + GameBigMap &get_bigmap(); + SmallMap &get_smallmap(); + + // signals + sigc::signal > current_map_position; + sigc::signal, Gdk::Rectangle> smallmap_changed; + sigc::signal > bigmap_changed; + sigc::signal sidebar_stats_changed; + sigc::signal progress_status_changed; + sigc::signal progress_changed; + sigc::signal + can_select_next_movable_stack, + can_center_selected_stack, + can_defend_selected_stack, + can_park_selected_stack, + can_deselect_selected_stack, + can_search_selected_stack, + can_plant_standard_selected_stack, + can_move_selected_stack_along_path, + can_move_selected_stack, + can_group_ungroup_selected_stack, + can_move_all_stacks, + can_disband_stack, + can_change_signpost, + can_see_history, + can_see_diplomacy, + received_diplomatic_proposal, + city_too_poor_to_produce, + can_end_turn; + sigc::signal stack_info_changed; + sigc::signal map_tip_changed; + sigc::signal stack_tip_changed; + sigc::signal city_tip_changed; + sigc::signal ruin_searched; + sigc::signal sage_visited; + sigc::signal fight_started; + sigc::signal abbreviated_fight_started; + sigc::signal ruinfight_started; + sigc::signal advice_asked; + sigc::signal ruinfight_finished; + sigc::signal hero_offers_service; + sigc::signal enemy_offers_surrender; + sigc::signal surrender_answered; + sigc::signal > stack_considers_treachery; + sigc::signal temple_searched; + sigc::signal quest_assigned; + sigc::signal city_defeated; + sigc::signal city_pillaged; + sigc::signal > city_sacked; + sigc::signal city_razed; + sigc::signal city_visited; + sigc::signal ruin_visited; + sigc::signal temple_visited; + sigc::signal next_player_turn; + sigc::signal remote_next_player_turn; + sigc::signal hero_arrives; + sigc::signal medal_awarded_to_army; + sigc::signal hero_gains_level; + sigc::signal game_loaded; + sigc::signal game_over; + sigc::signal player_died; + sigc::signal game_stopped; + sigc::signal commentator_comments; + sigc::signal > stack_moves; + + void addPlayer(Player *p); + + void inhibitAutosaveRemoval(bool inhibit); + + void endOfGameRoaming(Player *winner); + private: + static Game *current_game; + + // move the selected stack one tile in a given direction + void move_selected_stack_dir(int diffx, int diffy); + void move_map_dir(int diffx, int diffy); + + // centers the map on a city of the active player + void center_view_on_city(); + + void update_control_panel(); + void update_sidebar_stats(); + void update_stack_info(); // emit stack_info_changed + void clear_stack_info(); + + // locks/unlocks the input widgets during computer turns + void lock_inputs(); + void unlock_inputs(); + + //! Maybe peform treachery + bool maybeTreachery(Stack *stack, Player *them, Vector pos); + + // bigmap callbacks + void on_stack_selected(Stack* s); + void on_stack_grouped_or_ungrouped(Stack *s); + void on_city_visted (City* c); + void on_ruin_queried (Ruin* r, bool brief); + void on_temple_queried (Temple* t, bool brief); + void on_signpost_queried (Signpost* s); + void on_stack_queried (Vector tile); + void on_stack_unqueried (); + void on_city_visited(City *city); // for city window + void on_city_queried (Vector, City *city); // for city info tip + void on_city_unqueried (); + + // smallmap callbacks + void on_smallmap_changed(Glib::RefPtr map); + void on_bigmap_changed(Glib::RefPtr map); + + // misc. callbacks + void invading_city(City* city, int gold); + void init_turn_for_player(Player* p); + void on_player_died(Player *p); + void stack_searches_ruin(Ruin *ruin, Stack *stack); + void stack_searches_temple(Temple *temple, Stack *stack); + + //! Callback when the army of a human player reaches a new level. + Army::Stat heroGainsLevel(Hero * a); + //! Callback when an army gets a new medal. + void newMedalArmy(Army* a, int medaltype); + //! Called whenever a stack has changed, updates the map etc. + void stackUpdate(Stack* s); + //! Called whenever players fight + void on_fight_started(Fight &fight); + //! Called whenever a player receives an offer of surrender + void on_surrender_offered(Player *recipient); + void nextRound(); + //! Called after a player's stack attacks a city + void on_city_fight_finished(City *city, Fight::Result result); + + void looting_city(City *city, int &gold); + void unselect_active_stack(); + void select_active_stack(); + bool recruitHero(HeroProto *hero, City *city, int gold); + + void on_stack_grouped(Stack *stack, bool grouped); + void stack_arrives_on_tile(Stack *stack, Vector tile); + void stack_leaves_tile(Stack *stack, Vector tile); + void on_stack_halted(Stack *stack); + + + GameScenario* d_gameScenario; + NextTurn* d_nextTurn; + std::auto_ptr bigmap; + std::auto_ptr smallmap; + + + bool input_locked; + + std::list connections[MAX_PLAYERS + 1]; +}; + +#endif