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 // history.h - constructs to record the important events during a turn 21 // and replay them on the next 22 /////////////////////////////////////////////////////////////////////// 23 24 #ifndef _INCLUDE_HISTORY_H 25 #define _INCLUDE_HISTORY_H 26 27 #include "combat.h" 28 29 class HistEvent : public Node { 30 public: HistEvent(void)31 HistEvent( void ) : processed(false) {} 32 int Load ( MemBuffer &file ); 33 int Save( MemBuffer &file ) const; 34 35 unsigned char type; 36 short data[4]; 37 bool processed; 38 }; 39 40 41 class MapWindow; 42 43 class History { 44 public: 45 enum HistEventType { 46 HIST_MOVE = 0, 47 HIST_ATTACK, 48 HIST_COMBAT, 49 HIST_TILE, // map tile change 50 HIST_TILE_INTERNAL, 51 HIST_MSG, 52 HIST_UNIT, 53 HIST_TRANSPORT_CRYSTALS, 54 HIST_TRANSPORT_UNIT 55 }; 56 57 enum HistUnitEventType { 58 HIST_UEVENT_CREATE, 59 HIST_UEVENT_DESTROY, 60 HIST_UEVENT_REPAIR 61 }; 62 History(void)63 History( void ) {} 64 short Load( MemBuffer &file, Mission &mission ); 65 int Save( MemBuffer &file, bool network = false ) const; 66 67 void StartRecording( List &list ); 68 69 int RecordAttackEvent( const Unit &u, const Unit &target ); 70 int RecordCombatEvent( const Combat &combat, unsigned char loss1, 71 unsigned char loss2 ); 72 int RecordMoveEvent( const Unit &u, Direction dir ); 73 int RecordMsgEvent( short title, unsigned short msg, short pos ); 74 int RecordTileEvent( unsigned short tile, unsigned short old, 75 short dx, short dy ); 76 int RecordTransportEvent( const UnitContainer &source, 77 const Transport &dest, short crystals ); 78 int RecordTransportEvent( const UnitContainer &source, 79 const Transport &dest, const Unit &u ); 80 int RecordUnitEvent( const Unit &u, HistUnitEventType type ); 81 82 void Replay( MapWindow *mapwin ); 83 84 void UndoMove( const Unit &u ); 85 void SetEventsProcessed( void ) const; GetEvents(void)86 const List &GetEvents( void ) const { return events; } 87 Unit *GetDummy( unsigned short id ) const; 88 89 private: 90 void BeginReplay( List &backup, Map *map ); 91 void EndReplay( List &backup, Map *map ); 92 93 void ReplayAttackEvent( const HistEvent &event, MapWindow *mapwin ); 94 void ReplayCombatEvent( const HistEvent &event, MapWindow *mapwin ); 95 void ReplayMessageEvent( const HistEvent &event, View *view ); 96 void ReplayMoveEvent( const HistEvent &event, MapWindow *mapwin ); 97 void ReplayTileEvent( const HistEvent &event, MapWindow *mapwin ); 98 void ReplayUnitEvent( const HistEvent &event, MapWindow *mapwin ); 99 100 List events; 101 List units; 102 103 unsigned short delay; 104 105 Unit *lastunit; 106 Point lastpos; 107 }; 108 109 #endif /* _INCLUDE_HISTORY_H */ 110 111