Advanced Strategic Command
registerunitrftarget.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 
22 #include "registerunitrftarget.h"
23 #include "action-registry.h"
24 #include "../vehicle.h"
25 
26 
27 RegisterUnitRFTarget::RegisterUnitRFTarget( GameMap* gamemap, int vehicleID, int weapon, int targetUnitID )
28  : UnitAction( gamemap, vehicleID )
29 {
30  this->weapon= weapon;
31  this->targetUnitID = targetUnitID;
32 }
33 
34 
36 {
37  ASCString res = "Register Unit RF Target ";
38  if ( getUnit(false) )
39  res += " of unit " + getUnit(false)->getName();
40 
41  return res;
42 }
43 
44 
46 {
47  UnitAction::readData( stream );
48  int version = stream.readInt();
49  if ( version != 1 )
50  throw tinvalidversion ( "ChangeUnitMovement", 1, version );
51 
52  targetUnitID = stream.readInt();
53  weapon = stream.readInt();
54 };
55 
56 
58 {
59  UnitAction::writeData( stream );
60  stream.writeInt( 1 );
61  stream.writeInt( targetUnitID );
62  stream.writeInt( weapon );
63 };
64 
65 
67 {
69 }
70 
72 {
73  Vehicle* veh = getUnit();
74  veh->reactionfire.weaponShots[weapon]--;
75  veh->reactionfire.nonattackableUnits.push_back ( targetUnitID );
76 
77  return ActionResult(0);
78 }
79 
80 
82 {
83  Vehicle* veh = getUnit();
84  veh->reactionfire.weaponShots[weapon]++;
85 
86  veh->reactionfire.nonattackableUnits.erase ( find( veh->reactionfire.nonattackableUnits.begin(), veh->reactionfire.nonattackableUnits.end(), targetUnitID ));
87  return ActionResult(0);
88 }
89 
90 
91 
92 namespace {
93  const bool r1 = registerAction<RegisterUnitRFTarget> ( ActionRegistry::RegisterUnitRFTarget );
94 }
95 
virtual void writeInt(int i)
Writes a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is p...
Definition: basestrm.cpp:363
int GameActionID
Definition: action.h:35
virtual int readInt(void)
Reads a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is pe...
Definition: basestrm.cpp:284
ASCString getDescription() const
void writeData(tnstream &stream) const
Definition: unitaction.cpp:75
vector< int > weaponShots
Definition: vehicle.h:165
The interface for all kinds of IO stream.
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
class Vehicle::ReactionFire reactionfire
Vehicle * getUnit(bool dontThrow=false)
Definition: unitaction.cpp:47
ASCString getName() const
returns the units name or, if it does not exist, the unit type's name or description ...
Definition: vehicle.cpp:1569
virtual GameActionID getID() const
virtual ActionResult undoAction(const Context &context)
virtual ActionResult runAction(const Context &context)
vector< int > nonattackableUnits
Definition: vehicle.h:166
virtual void writeData(tnstream &stream) const
virtual void readData(tnstream &stream)
void readData(tnstream &stream)
Definition: unitaction.cpp:65
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182