~ubuntu-branches/ubuntu/precise/widelands/precise-backports

« back to all changes in this revision

Viewing changes to src/editor_game_base.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Quinson
  • Date: 2005-02-14 10:41:12 UTC
  • Revision ID: james.westby@ubuntu.com-20050214104112-6v08iux9fptxpva9
Tags: upstream-build9
Import upstream version build9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2002-2004 by The Widelands Development Team
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (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., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *
 
18
 */
 
19
 
 
20
#ifndef __S__EDITOR_GAME_BASE_H
 
21
#define __S__EDITOR_GAME_BASE_H
 
22
 
 
23
#include <cassert>
 
24
#include <map>
 
25
#include <string>
 
26
#include <vector>
 
27
#include "constants.h"
 
28
#include "descr_maintainer.h"
 
29
#include "geometry.h"
 
30
#include "types.h"
 
31
 
 
32
class Battle;
 
33
class Bob;
 
34
class Building;
 
35
class Building_Descr;
 
36
class Immovable;
 
37
class Interactive_Base;
 
38
class Map;
 
39
class Object_Manager;
 
40
class Player;
 
41
class Tribe_Descr;
 
42
 
 
43
class Editor_Game_Base {
 
44
   friend class Interactive_Base;
 
45
   friend class Game_Game_Class_Data_Packet;
 
46
   
 
47
   public:
 
48
      Editor_Game_Base();
 
49
      virtual ~Editor_Game_Base();
 
50
 
 
51
      void set_map(Map* map);
 
52
      inline Map *get_map() { return m_map; }
 
53
      inline Object_Manager* get_objects() { return m_objects; }
 
54
 
 
55
      void unconquer_area(uchar playernr, Coords coords);
 
56
      void conquer_area(uchar playernr, Coords coords, Building_Descr*);
 
57
      void conquer_area_no_building(uchar playernr, Coords coords, int radius);
 
58
 
 
59
      // logic handler func
 
60
      virtual void think() = 0;
 
61
 
 
62
      // Player commands
 
63
      void remove_player(int plnum);
 
64
      void add_player(int plnum, int type, const char* tribe, const char* name);
 
65
      inline Player* get_player(int n) { assert(n>=1 && n<=MAX_PLAYERS); return m_players[n-1]; }
 
66
      Player* get_safe_player(int n);
 
67
      
 
68
      virtual bool is_game() = 0;
 
69
 
 
70
      // loading stuff
 
71
      void postload();
 
72
      void load_graphics();
 
73
      virtual void cleanup_for_load(bool flush_graphics=true, bool flush_animations=true);
 
74
 
 
75
      // warping stuff. instantly creating map_objects
 
76
      Building* warp_building(Coords, char owner, int idx);
 
77
                Building* warp_constructionsite(Coords c, char owner, int idx, int oldid=-1);
 
78
      Bob *create_bob(Coords c, int idx, Tribe_Descr* = 0);
 
79
      Immovable* create_immovable(Coords c, int idx, Tribe_Descr*);
 
80
                Immovable* create_immovable(Coords c, std::string name, Tribe_Descr*);
 
81
      Battle*    create_battle ();
 
82
      
 
83
      std::vector<int> get_battle_serials() { return m_battle_serials; }
 
84
      inline int get_gametime(void) { return m_gametime; }
 
85
                Interactive_Base* get_iabase() { return m_iabase; }
 
86
 
 
87
                // safe system for storing pointers to non-Map_Object C++ objects
 
88
                // unlike objects in the Object_Manager, these pointers need not be
 
89
                // synchronized across the network, and they are not saved in savegames
 
90
                uint add_trackpointer(void* ptr);
 
91
                void* get_trackpointer(uint serial);
 
92
                void remove_trackpointer(uint serial);
 
93
      
 
94
      // Manually load a tribe into memory. Used by the editor
 
95
      void manually_load_tribe(const char* tribe);
 
96
      // Get a tribe from the loaded list, when available
 
97
      Tribe_Descr* get_tribe(const char* tribe); 
 
98
 
 
99
        enum losegain_t { LOSE=0, GAIN };
 
100
        virtual void player_immovable_notification (PlayerImmovable*, losegain_t)=0;
 
101
        virtual void player_field_notification (const FCoords&, losegain_t)=0;
 
102
      
 
103
      // Military stuff
 
104
   std::vector<Coords>* get_attack_points(uchar player);
 
105
   
 
106
   virtual void make_influence_map ();
 
107
 
 
108
      /// Returns the influence value of one position (a) with the radius (radius) about (b)
 
109
   virtual int calc_influence (Coords a, Coords b, int radius);
 
110
   
 
111
   protected:
 
112
      // next function is used to update the current gametime,
 
113
      // for queue runs e.g.
 
114
      inline int* get_game_time_pointer(void) { return &m_gametime; }
 
115
      inline void set_iabase(Interactive_Base* b) { m_iabase=b; }
 
116
      
 
117
   private:
 
118
      struct Conquer_Info {
 
119
         uchar  player;
 
120
         Coords middle_point;
 
121
         ushort    area;
 
122
      };
 
123
      std::vector<Conquer_Info> m_conquer_info;
 
124
      void do_conquer_area(uchar playernr, Coords coords, int radius, bool conquer);
 
125
 
 
126
   private:
 
127
                void cleanup_playerimmovables_area(Coords coords, int radius);
 
128
 
 
129
      int m_gametime;
 
130
      Player*                                                   m_players[MAX_PLAYERS];
 
131
      Object_Manager*                           m_objects;
 
132
      std::vector<Tribe_Descr*> m_tribes;
 
133
      Interactive_Base*          m_iabase;
 
134
      Map*                                                              m_map;
 
135
 
 
136
                uint                                                            m_lasttrackserial;
 
137
                std::map<uint, void*>           m_trackpointers;
 
138
      // I know that this fucks, ideas ?
 
139
#define MAX_X     512
 
140
#define MAX_Y     512      
 
141
public:
 
142
      int  m_conquer_map[MAX_PLAYERS+1][MAX_X][MAX_Y]; // m_conquer_map[playernr][x][y] = [quantity of influence]
 
143
                                                         // The playernr 0 is the REAL OWNER
 
144
      std::vector<int>           m_battle_serials;    // The serials of the battles only used to load/save
 
145
};
 
146
 
 
147
extern const uchar g_playercolors[MAX_PLAYERS][12];
 
148
 
 
149
#endif // __S__EDITOR_GAME_BASE_H