File: mapedcommands.cpp

package info (click to toggle)
asc 2.6.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 82,860 kB
  • ctags: 26,395
  • sloc: cpp: 158,660; sh: 11,274; ansic: 6,878; makefile: 604; perl: 138
file content (193 lines) | stat: -rw-r--r-- 4,609 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193


#include <iostream>

#include "../ascstring.h"
#include "../vehicle.h"
#include "../gamemap.h"
#include "../spfst.h"
#include "../spfst-legacy.h"
               
#include "../itemrepository.h"
#include "../dlg_box.h"
#include "mapedcommands.h"
#include "../ed_mapcomponent.h"
#include "../dialogs/fieldmarker.h"
#include "../edglobal.h"
         
         
         
         
void clearField( GameMap* map, const MapCoordinate& pos )
{
   MapField* fld = map->getField(pos);
   if ( fld ) {
      if ( fld->building )
         delete fld->building;
      
      if ( fld->vehicle )
         delete fld->vehicle;
      
      while ( !fld->objects.empty() )
         fld->removeObject( fld->objects[0].typ );
               
   }  
}
         
Object* placeObject( GameMap* map, const MapCoordinate& pos, const ObjectType* obj, bool force )
{
   MapField* fld = map->getField( pos );
   if ( fld ) {
      if ( !fld->addobject( obj, -1, force ))
         return NULL;
      else
         return fld->checkForObject(obj);
   } else
      return NULL;
}

Building* placeBuilding( GameMap* map, const MapCoordinate& pos, const BuildingType* bld, int owner )
{
   if ( map && bld && owner >= 0 && owner <= 8 ) {
      MapField* fld = map->getField(pos);
      if ( fld ) {
         putbuilding( map, pos, owner*8, bld, bld->construction_steps );
         if ( fld->building && (fld->building->typ == bld ))
            return fld->building;
      }
   }
   return NULL;
}


Vehicle* placeUnit( GameMap* map, const MapCoordinate& pos, const VehicleType* veh, int owner )
{
   if ( map && veh && owner >= 0 && owner < 8 ) {
      MapField* fld = map->getField(pos);
      if ( fld ) {
         int r = VehicleItem::place( map, pos, veh, owner );
         if ( r < 0 )
            return NULL;
         else
            return fld->vehicle;
      }
   }
   return NULL;
}


bool placeTerrain( GameMap* map, const MapCoordinate& pos, const TerrainType* terrain, int weather )
{
   if ( map && terrain ) {
      MapField* fld = map->getField(pos);
      fld->typ = terrain->weather[0]; 
      fld->setWeather( weather );
      fld->setparams( );
      for ( int d = 0; d < 6; ++d ) {
         MapCoordinate pos2 = getNeighbouringFieldCoordinate( pos, d );
         MapField* fld = map->getField( pos2 );
         if ( fld ) 
            for ( MapField::ObjectContainer::iterator i = fld->objects.begin(); i != fld->objects.end(); ++i )
               calculateobject( pos2, false, i->typ, map );
      }
      return true;
   } else
      return false;
}

int selectPlayer( GameMap* map )
{
   vector<ASCString> buttons;
   buttons.push_back ( "~O~k" );
   buttons.push_back ( "~C~ancel" );

   vector<ASCString> player;
   for ( int i = 0; i < 8; ++i )
      player.push_back ( ASCString ( strrr(i)) + " " + map->player[i].getName());

   pair<int,int> playerRes = chooseString ( "Choose Player", player, buttons );
   if ( playerRes.first == 0 && playerRes.second >= 0) 
      return playerRes.second;
   else
      return -1;
}

FieldVector::FieldVector() 
{
}
      
unsigned int FieldVector::size() {
  return vector<MapCoordinate>::size();
}

MapCoordinate FieldVector::getItem( int i ) {
   return at(i-1);  
}



class LuaFieldSearcher : public SearchFields {
   public:
      FieldVector fields;
      
      LuaFieldSearcher ( GameMap* _gamemap ) : SearchFields ( _gamemap ) {
           
      };
       
   protected:
      void testfield ( const MapCoordinate& pos ) {
         fields.push_back(pos); 
      };
      
};
      
      
FieldVector getFieldsInDistance( GameMap* map, const MapCoordinate& position, int distance )
{
   LuaFieldSearcher lfs ( map );
   lfs.initsearch( position, distance, distance );
   lfs.startsearch();
   return lfs.fields;
}

MapCoordinate selectPosition()
{
   SelectFromMap::CoordinateList list;
   SelectFromMap sfm( list, actmap, true );
   sfm.Show();
   sfm.RunModal();
   if ( list.size () )
      return *list.begin();
   else
      return MapCoordinate(-1,-1);
         
}

Resources putResources( ContainerBase* container, const Resources& resources )
{
   return container->putResource( resources, false, 0, container->getOwner() );
}

void setReactionFire( Vehicle* vehicle, bool state )
{
   if ( state )
      vehicle->reactionfire.enable();
   else
      vehicle->reactionfire.disable();
}

int EditingEnvironment :: getSelectedPlayerPosition() const
{
   return selection.getPlayer();
}

int EditingEnvironment :: getBrushSize() const
{
   return selection.brushSize;
}


EditingEnvironment getEditingEnvironment() 
{
   return EditingEnvironment();
}