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
|
#include <iostream>
#include "../sg.h"
#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"
void clearField( GameMap* map, const MapCoordinate& pos )
{
tfield* 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 )
{
tfield* 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 ) {
tfield* fld = map->getField(pos);
if ( fld ) {
putbuilding( map, pos, owner*8, bld, bld->construction_steps );
if ( 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 ) {
tfield* 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 ) {
tfield* 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 );
tfield* fld = map->getField( pos2 );
if ( fld )
for ( tfield::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();
}
|