Advanced Strategic Command
mapedcommands.cpp
Go to the documentation of this file.
1 
2 
3 #include <iostream>
4 
5 #include "../ascstring.h"
6 #include "../vehicle.h"
7 #include "../gamemap.h"
8 #include "../spfst.h"
9 #include "../spfst-legacy.h"
10 
11 #include "../itemrepository.h"
12 #include "../dlg_box.h"
13 #include "mapedcommands.h"
14 #include "../ed_mapcomponent.h"
15 #include "../dialogs/fieldmarker.h"
16 #include "../edglobal.h"
17 
18 
19 
20 
21 void clearField( GameMap* map, const MapCoordinate& pos )
22 {
23  MapField* fld = map->getField(pos);
24  if ( fld ) {
25  if ( fld->building )
26  delete fld->building;
27 
28  if ( fld->vehicle )
29  delete fld->vehicle;
30 
31  while ( !fld->objects.empty() )
32  fld->removeObject( fld->objects[0].typ );
33 
34  }
35 }
36 
37 Object* placeObject( GameMap* map, const MapCoordinate& pos, const ObjectType* obj, bool force )
38 {
39  MapField* fld = map->getField( pos );
40  if ( fld ) {
41  if ( !fld->addobject( obj, -1, force ))
42  return NULL;
43  else
44  return fld->checkForObject(obj);
45  } else
46  return NULL;
47 }
48 
49 Building* placeBuilding( GameMap* map, const MapCoordinate& pos, const BuildingType* bld, int owner )
50 {
51  if ( map && bld && owner >= 0 && owner <= 8 ) {
52  MapField* fld = map->getField(pos);
53  if ( fld ) {
54  putbuilding( map, pos, owner*8, bld, bld->construction_steps );
55  if ( fld->building && (fld->building->typ == bld ))
56  return fld->building;
57  }
58  }
59  return NULL;
60 }
61 
62 
63 Vehicle* placeUnit( GameMap* map, const MapCoordinate& pos, const VehicleType* veh, int owner )
64 {
65  if ( map && veh && owner >= 0 && owner < 8 ) {
66  MapField* fld = map->getField(pos);
67  if ( fld ) {
68  int r = VehicleItem::place( map, pos, veh, owner );
69  if ( r < 0 )
70  return NULL;
71  else
72  return fld->vehicle;
73  }
74  }
75  return NULL;
76 }
77 
78 
79 bool placeTerrain( GameMap* map, const MapCoordinate& pos, const TerrainType* terrain, int weather )
80 {
81  if ( map && terrain ) {
82  MapField* fld = map->getField(pos);
83  fld->typ = terrain->weather[0];
84  fld->setWeather( weather );
85  fld->setparams( );
86  for ( int d = 0; d < 6; ++d ) {
88  MapField* fld = map->getField( pos2 );
89  if ( fld )
90  for ( MapField::ObjectContainer::iterator i = fld->objects.begin(); i != fld->objects.end(); ++i )
91  calculateobject( pos2, false, i->typ, map );
92  }
93  return true;
94  } else
95  return false;
96 }
97 
98 int selectPlayer( GameMap* map )
99 {
100  vector<ASCString> buttons;
101  buttons.push_back ( "~O~k" );
102  buttons.push_back ( "~C~ancel" );
103 
104  vector<ASCString> player;
105  for ( int i = 0; i < 8; ++i )
106  player.push_back ( ASCString ( strrr(i)) + " " + map->player[i].getName());
107 
108  pair<int,int> playerRes = chooseString ( "Choose Player", player, buttons );
109  if ( playerRes.first == 0 && playerRes.second >= 0)
110  return playerRes.second;
111  else
112  return -1;
113 }
114 
116 {
117 }
118 
119 unsigned int FieldVector::size() {
120  return vector<MapCoordinate>::size();
121 }
122 
124  return at(i-1);
125 }
126 
127 
128 
130  public:
132 
133  LuaFieldSearcher ( GameMap* _gamemap ) : SearchFields ( _gamemap ) {
134 
135  };
136 
137  protected:
138  void testfield ( const MapCoordinate& pos ) {
139  fields.push_back(pos);
140  };
141 
142 };
143 
144 
145 FieldVector getFieldsInDistance( GameMap* map, const MapCoordinate& position, int distance )
146 {
147  LuaFieldSearcher lfs ( map );
148  lfs.initsearch( position, distance, distance );
149  lfs.startsearch();
150  return lfs.fields;
151 }
152 
154 {
156  SelectFromMap sfm( list, actmap, true );
157  sfm.Show();
158  sfm.RunModal();
159  if ( list.size () )
160  return *list.begin();
161  else
162  return MapCoordinate(-1,-1);
163 
164 }
165 
166 Resources putResources( ContainerBase* container, const Resources& resources )
167 {
168  return container->putResource( resources, false, 0, container->getOwner() );
169 }
170 
171 void setReactionFire( Vehicle* vehicle, bool state )
172 {
173  if ( state )
174  vehicle->reactionfire.enable();
175  else
176  vehicle->reactionfire.disable();
177 }
178 
180 {
181  return selection.getPlayer();
182 }
183 
185 {
186  return selection.brushSize;
187 }
188 
189 
191 {
192  return EditingEnvironment();
193 }
TerrainType::Weather * typ
the terraintype of the field
Definition: mapfield.h:38
The type of a field.
Definition: terraintype.h:75
int getPlayer()
Definition: edglobal.h:162
Object * placeObject(GameMap *map, const MapCoordinate &pos, const ObjectType *obj, bool force)
virtual int putResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)=0
scope: 0 = local 1 = resource network 2 = global in all buildings 3 = map wide pool( used only intern...
FieldVector getFieldsInDistance(GameMap *map, const MapCoordinate &position, int distance)
const BuildingType * typ
Definition: buildings.h:48
Vehicle * vehicle
Definition: mapfield.h:89
Vehicle * placeUnit(GameMap *map, const MapCoordinate &pos, const VehicleType *veh, int owner)
Resources putResources(ContainerBase *container, const Resources &resources)
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
Weather * weather[cwettertypennum]
Definition: terraintype.h:140
EditingEnvironment getEditingEnvironment()
FieldVector fields
int getOwner() const
returns the number of the player this vehicle/building belongs to
void calculateobject(const MapCoordinate &pos, bool mof, const ObjectType *obj, GameMap *gamemap)
Definition: spfst.cpp:462
a single field of the map
Definition: mapfield.h:26
int selectPlayer(GameMap *map)
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
virtual int place(const MapCoordinate &mc) const
Definition: edselfnt.cpp:186
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
class Vehicle::ReactionFire reactionfire
int getSelectedPlayerPosition() const
The class describing properties that are common to all buildings of a certain kind.
Definition: buildingtype.h:35
void clearField(GameMap *map, const MapCoordinate &pos)
void Show(bool fade=false)
int enable()
enables the reaction fire or returns an error code ( result < 0 = -errorNr )
Definition: vehicle.cpp:689
char * strrr(int a)
converts a to a string.
Definition: misc.cpp:66
void initsearch(const MapCoordinate &startPosition, int _firstDistance, int _lastDistance)
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
Coordinate on the twodimensional map.
Definition: typen.h:202
void setparams(ObjectRemovalStrategy *objectRemovalStrategy)
recalculates the terrain properties, movemalus etc from the terraintype and the objects,
Definition: mapfield.cpp:605
searches fields in hexagonal "circles" around a field and calls testfield for each field ...
Definition: mapalgorithms.h:28
virtual void startsearch(void)
bool addobject(const ObjectType *obj, int dir=-1, bool force=false, ObjectRemovalStrategy *objectRemovalStrategy=NULL)
add an object to the field
Definition: mapfield.cpp:212
void putbuilding(GameMap *actmap, const MapCoordinate &entryPosition, int color, const BuildingType *buildingtyp, int completion, int ignoreunits)
puts a building onto the map. To be used by the map editor! For ingame usage, see ConstructBuildingCo...
Definition: spfst.cpp:210
Player player[9]
Definition: gamemap.h:253
MapCoordinate selectPosition()
MapCoordinate getItem(int i)
SelectionHolder selection
Definition: edglobal.cpp:189
void setWeather(int weather)
Definition: mapfield.cpp:380
vector< MapCoordinate > CoordinateList
Definition: fieldmarker.h:45
Building * placeBuilding(GameMap *map, const MapCoordinate &pos, const BuildingType *bld, int owner)
int construction_steps
the number of stages that are required to construct a building using a construction unit...
Definition: buildingtype.h:89
Building * building
Definition: mapfield.h:102
GameMap * actmap
Definition: spfst.cpp:64
int getBrushSize() const
unsigned int size()
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
An actual building on the map, which references a BuildingType Buildings have an owner,.
Definition: buildings.h:38
an instance of an object type (ObjectType) on the map
Definition: objects.h:46
LuaFieldSearcher(GameMap *_gamemap)
Resources are basically the currency of ASC.
Definition: typen.h:97
Object * checkForObject(const ObjectType *o)
checks if there are objects from the given type on the field and returns them
Definition: mapfield.cpp:648
bool removeObject(const ObjectType *obj, bool force=false, ObjectRemovalStrategy *objectRemovalStrategy=NULL)
removes all objects of the given type from the field
Definition: mapfield.cpp:256
bool placeTerrain(GameMap *map, const MapCoordinate &pos, const TerrainType *terrain, int weather)
int chooseString(const ASCString &title, const vector< ASCString > &entries, int defaultEntry)
displays a dialogbox which lets you choose one of a number of strings.
Definition: dlg_box.cpp:3788
void testfield(const MapCoordinate &pos)
MapCoordinate3D getNeighbouringFieldCoordinate(const MapCoordinate3D &pos, int direc)
returns the coordinate of the field that is adjecent to the given field in the direction of direc ...
ObjectContainer objects
Definition: mapfield.h:124
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
void setReactionFire(Vehicle *vehicle, bool state)
MapField * getField(int x, int y)
Definition: gamemap.h:465