Advanced Strategic Command
vehiclepropertyeditor.cpp
Go to the documentation of this file.
1 
2 /*
3  This file is part of Advanced Strategic Command; http://www.asc-hq.de
4  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; see the file COPYING. If not, write to the
18  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19  Boston, MA 02111-1307 USA
20 */
21 
22 #include <pgpropertyeditor.h>
23 #include <pgpropertyfield_integer.h>
24 #include <pgpropertyfield_intdropdown.h>
25 #include <pgpropertyfield_string.h>
26 #include <pgpropertyfield_checkbox.h>
27 
28 #include "../gamemap.h"
29 #include "../paradialog.h"
30 #include "../edmisc.h"
31 
32 #include "vehiclepropertyeditor.h"
33 
34 static const char* cdirnames[7] = { "north", "north-east", "south-east", "south", "south-west", "north-west", NULL };
35 
37  private:
38  PG_PropertyEditor* propertyEditor;
39  Vehicle* veh;
40  bool reactionFire;
41  int owner;
42  ASCString playerNames[8];
43  const char* cplayerNames[9];
44  int experienceOffensive;
45  int experienceDefensive;
46  Resources tank;
47 
48 
49  const char* cheightNames[choehenstufennum+1];
50  int heightMapping[choehenstufennum];
51  int unitHeight;
52 
53  bool getReactionfireStatus() {
55  }
56 
57  bool ok()
58  {
59  if ( propertyEditor->Apply() ) {
60 
61  if ( reactionFire != getReactionfireStatus() ) {
62  if ( reactionFire )
63  veh->reactionfire.enable();
64  else
65  veh->reactionfire.disable();
66  mapsaved = false;
67  }
68 
69  if ( owner != veh->getOwner() ) {
70  veh->convert(owner, true);
71  mapsaved = false;
72  }
73 
74  if ( heightMapping[unitHeight] != getFirstBit( veh->height )) {
75  veh->height = 1 << heightMapping[unitHeight];
76  veh->resetMovement();
77  mapsaved = false;
78  }
79 
80  if ( experienceOffensive != veh->getExperience_offensive() ) {
81  veh->setExperience_offensive( experienceOffensive );
82  mapsaved = false;
83  }
84 
85  if ( experienceDefensive != veh->getExperience_defensive() ) {
86  veh->setExperience_defensive( experienceDefensive );
87  mapsaved = false;
88  }
89 
90  if ( tank.material != veh->getTank().material ) {
91  veh->putResource( tank.material-veh->getTank().material, 1, false, 1, veh->getOwner() );
92  mapsaved = false;
93  }
94 
95  if ( tank.fuel != veh->getTank().fuel ) {
96  veh->putResource( tank.fuel-veh->getTank().fuel, 2, false, 1, veh->getOwner() );
97  mapsaved = false;
98  }
99 
100  quitModalLoop(0);
101 
102  return true;
103  } else
104  return false;
105  }
106 
107  public:
108  VehiclePropertyEditor( PG_Widget* parent, Vehicle* veh ) : ASC_PG_Dialog( parent, PG_Rect( 50, 50, 500, 550 ), "Edit Unit Properties")
109  {
110  this->veh = veh;
111  propertyEditor = new ASC_PropertyEditor( this, PG_Rect( 10, GetTitlebarHeight(), Width() - 20, Height() - GetTitlebarHeight() - 50 ), "PropertyEditor", 70 );
112 
113  new PG_PropertyField_String<ASCString>( propertyEditor, "Name", &veh->name );
114  new PG_PropertyField_Integer<int>( propertyEditor , "Damage", &veh->damage );
115 
116  experienceOffensive = veh->getExperience_offensive();
117  (new PG_PropertyField_Integer<int>( propertyEditor , "Experience offensive", &experienceOffensive ))
118  ->SetRange(0,1000);
119 
120  experienceDefensive = veh->getExperience_defensive();
121  (new PG_PropertyField_Integer<int>( propertyEditor , "Experience defensive", &experienceDefensive ))
122  ->SetRange(0,1000);
123 
124  reactionFire = getReactionfireStatus();
125  new PG_PropertyField_Checkbox<bool>( propertyEditor, "ReactionFire", &reactionFire );
126 
127  tank = veh->getTank();
128 
129  if ( veh->getStorageCapacity().material )
130  ( new PG_PropertyField_Integer<int>( propertyEditor , "Material", &tank.material ))
131  ->SetRange(0, veh->getStorageCapacity().material);
132 
133  if ( veh->getStorageCapacity().fuel )
134  ( new PG_PropertyField_Integer<int>( propertyEditor , "Fuel", &tank.fuel ))
135  ->SetRange( 0, veh->getStorageCapacity().fuel);
136 
137  for ( int i = 0; i < 8; ++i) {
138  playerNames[i] = ASCString("(") + ASCString::toString(i) + ") " + veh->getMap()->player[i].getName();
139  cplayerNames[i] = playerNames[i].c_str();
140  }
141  cplayerNames[8] = NULL;
142  owner = veh->getOwner();
143  new PG_PropertyField_IntDropDown<int>( propertyEditor, "Owner", &owner, cplayerNames );
144 
145  for ( int w =0; w < veh->typ->weapons.count; w++)
146  (new PG_PropertyField_Integer<int>( propertyEditor , "Ammo Weapon " + ASCString::toString(w) + " " + veh->typ->weapons.weapon[w].getName() , &veh->ammo[w] ))
147  ->SetRange( 0, veh->typ->weapons.weapon[w].count );
148 
149 
150  int count = 0;
151  for ( int h = 0; h < choehenstufennum; ++h ) {
152  if ( veh->typ->height & (1 << h )) {
153  cheightNames[count] = choehenstufen[h];
154  heightMapping[count] = h;
155  if ( h == getFirstBit( veh->height )) {
156  unitHeight = count;
157  }
158  ++count;
159  }
160  }
161  cheightNames[count] = NULL;
162  new PG_PropertyField_IntDropDown<int>( propertyEditor, "Level of height", &unitHeight, cheightNames );
163 
164  new PG_PropertyField_IntDropDown<Uint8>( propertyEditor, "Orientation", &veh->direction, cdirnames );
165 
166  PG_Button* ok = new PG_Button( this, PG_Rect( Width() - 100, Height() - 40, 90, 30), "OK" );
167  ok->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &VehiclePropertyEditor::ok )));
168  };
169 
170 };
171 
172 
174 {
175  if ( !ae )
176  return;
177 
178  VehiclePropertyEditor units ( NULL, ae );
179  units.Show();
180  units.RunModal();
181 }
int fuel
Definition: typen.h:101
int getExperience_defensive() const
Definition: vehicle.cpp:258
ASCString getName(void) const
int damage
Damage. 0 is no damage, when damage reaches 100 the container is destroyed.
const int choehenstufennum
The number of levels of height.
Definition: typen.h:67
ASCString name
a name given by the user or the map creator
int ammo[16]
Definition: vehicle.h:87
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
int getFirstBit(int zahl)
Count the number of zero bits on the LSB side of "zahl".
Definition: misc.cpp:45
UnitWeapon weapons
The weapons.
Definition: vehicletype.h:248
Resources getStorageCapacity() const
returns the local storage capacity for the given resource, which depends on the resource mode of the ...
int getOwner() const
returns the number of the player this vehicle/building belongs to
void setExperience_defensive(int experience)
Definition: vehicle.cpp:279
void changeUnitPropertyDialog(Vehicle *ae)
int count
amount of ammunition the unit having this weapon can carry
Definition: vehicletype.h:117
SingleWeapon weapon[16]
Definition: vehicletype.h:170
Resources getTank() const
returns the resources that the unit is carrying
Definition: vehicle.cpp:378
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
int height
the current level of height ( BITMAPPED ! )
Definition: vehicle.h:118
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
class Vehicle::ReactionFire reactionfire
bool mapsaved
Definition: edmisc.cpp:66
int enable()
enables the reaction fire or returns an error code ( result < 0 = -errorNr )
Definition: vehicle.cpp:689
int putResource(int amount, int resourcetype, bool queryonly, int scope=1, int player=-1)
scope: 0 = local 1 = resource network 2 = global in all buildings 3 = map wide pool( used only intern...
Definition: vehicle.cpp:297
bool quitModalLoop(int value)
Definition: paradialog.cpp:545
void setExperience_offensive(int experience)
Definition: vehicle.cpp:274
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
int material
Definition: typen.h:100
Player player[9]
Definition: gamemap.h:253
int height
the levels of height which this unit can enter
const char * choehenstufen[choehenstufennum]
The different levels of height.
Definition: typen.cpp:39
void convert(int player, bool recursive=true)
converts the unit so it is owned by 'player'.
Definition: vehicle.cpp:843
const VehicleType * typ
Definition: vehicle.h:83
Uint8 direction
the direction in which the unit is facing
Definition: vehicle.h:121
pvehicle ae
Definition: history.cpp:95
GameMap * getMap() const
Status getStatus() const
for each player that can still be attacked one bit is set
Definition: vehicle.h:155
Resources are basically the currency of ASC.
Definition: typen.h:97
void resetMovement(void)
resets a units movement. This is called at the beginning of each turn.
Definition: vehicle.cpp:518
static const char * cdirnames[7]
VehiclePropertyEditor(PG_Widget *parent, Vehicle *veh)
int getExperience_offensive() const
Definition: vehicle.cpp:253