1 // Crimson Fields -- a game of tactical warfare 2 // Copyright (C) 2000-2007 Jens Granseuer 3 // 4 // This program is free software; you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation; either version 2 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 // 18 19 /////////////////////////////////////////////////////////////// 20 // mission.h - the data construct to contain all level info 21 /////////////////////////////////////////////////////////////// 22 23 #ifndef _INCLUDE_MISSION_H 24 #define _INCLUDE_MISSION_H 25 26 #include "map.h" 27 #include "event.h" 28 #include "lset.h" 29 #include "player.h" 30 #include "history.h" 31 #include "lang.h" 32 33 class Mission { 34 public: Mission(void)35 Mission( void ) { history = 0; } 36 ~Mission( void ); 37 38 int Load( MemBuffer &file ); 39 Unit *LoadUnit( MemBuffer &file, bool dummy = false ); 40 int QuickLoad( MemBuffer &file ); 41 int Save( MemBuffer &file ); 42 GetMap(void)43 Map &GetMap( void ) { return map; } GetTerrainSet(void)44 TerrainSet &GetTerrainSet( void ) { return terrain_set; } GetUnitSet(void)45 UnitSet &GetUnitSet( void ) { return unit_set; } 46 GetSequel(void)47 const char *GetSequel( void ) const { return GetInternalMessage(next_map); } GetInfoMsg(void)48 const char *GetInfoMsg( void ) const { return GetMessage(level_info); } GetCampaignInfo(void)49 const char *GetCampaignInfo( void ) const { return GetMessage(campaign_info); } GetName(void)50 const char *GetName( void ) const { return GetMessage(name); } GetCampaignName(void)51 const char *GetCampaignName( void ) const { return GetMessage(campaign_name); } GetMusic(void)52 const char *GetMusic( void ) const { return GetMessage(music); } 53 GetTurn(void)54 unsigned short GetTurn( void ) const { return turn; } NextTurn(void)55 unsigned short NextTurn( void ) { return ++turn; } GetPhase(void)56 unsigned char GetPhase( void ) const { return turn_phase; } GetTime(void)57 unsigned short GetTime( void ) const { return (GetTurn() - 1) * 2 + current_player; } GetHandicap(void)58 unsigned char GetHandicap( void ) const { return handicap; } GetFlags(void)59 unsigned short GetFlags( void ) const { return flags; } 60 61 Unit *CreateUnit( unsigned char type, Player &p, const Point &pos, 62 Direction dir = NORTH, unsigned char group = MAX_GROUP_SIZE, unsigned char xp = 0 ); 63 Unit *GetUnit( unsigned short id ) const; 64 Building *GetShop( unsigned short id ) const; 65 Event *GetEvent( unsigned short id ) const; 66 67 const char *GetMessage( short id ) const; 68 GetPlayer(void)69 Player &GetPlayer( void ) { return GetPlayer(current_player); } GetPlayer(unsigned char id)70 Player &GetPlayer( unsigned char id ) 71 { return id == PLAYER_ONE ? p1 : p2; } GetOtherPlayer(const Player & p)72 Player &GetOtherPlayer( const Player &p ) 73 { return p.ID() == PLAYER_ONE ? p2 : p1; } NextPlayer(void)74 Player &NextPlayer( void ) { current_player ^= 1; return GetPlayer(); } 75 76 void RegisterBattle( Unit *att, Unit *def ); GetHistory(void)77 History *GetHistory( void ) const { return history; } SetHistory(History * h)78 void SetHistory( History *h ) { history = h; } 79 GetEvents(void)80 List &GetEvents( void ) { return events; } GetUnits(void)81 List &GetUnits( void ) { return units; } GetShops(void)82 List &GetShops( void ) { return shops; } GetBattles(void)83 List &GetBattles( void ) { return battles; } 84 SetFlags(unsigned short f)85 void SetFlags( unsigned short f ) { flags = f; } 86 void SetLocale( const string &lang ); SetSequel(signed char seqid)87 void SetSequel( signed char seqid ) { next_map = seqid; } SetPhase(unsigned char phase)88 void SetPhase( unsigned char phase ) { turn_phase = phase; } SetHandicap(unsigned char hcap)89 void SetHandicap( unsigned char hcap ) { handicap = hcap; } 90 91 private: 92 const char *GetInternalMessage( short id ) const; 93 unsigned short CreateUnitID( void ) const; 94 95 unsigned short turn; 96 unsigned char turn_phase; 97 unsigned char current_player; 98 unsigned char handicap; 99 100 unsigned short flags; 101 signed char name; 102 signed char level_info; 103 signed char campaign_name; 104 signed char campaign_info; 105 signed char next_map; 106 signed char music; 107 108 Map map; 109 List units; 110 List shops; 111 List events; 112 List battles; 113 Locale messages; 114 Language internal_messages; // non-translatable strings 115 Player p1; 116 Player p2; 117 118 UnitSet unit_set; 119 TerrainSet terrain_set; 120 History *history; 121 122 template <typename T> // get a specific object from a list FindID(const List & l,unsigned short id)123 T *FindID( const List &l, unsigned short id ) const { 124 for ( T *obj = static_cast<T *>(l.Head()); 125 obj; obj = static_cast<T *>(obj->Next()) ) { 126 if ( obj->ID() == id ) return obj; 127 } 128 return 0; 129 } 130 }; 131 132 #endif /* _INCLUDE_MISSION_H */ 133 134