registerunitrftarget.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
00019 */
00020 
00021 
00022 #include "registerunitrftarget.h"
00023 #include "action-registry.h"
00024 #include "../vehicle.h"
00025      
00026      
00027 RegisterUnitRFTarget::RegisterUnitRFTarget( GameMap* gamemap, int vehicleID, int weapon, int targetUnitID )
00028    : UnitAction( gamemap, vehicleID )
00029 {
00030    this->weapon= weapon;
00031    this->targetUnitID = targetUnitID;
00032 }
00033       
00034       
00035 ASCString RegisterUnitRFTarget::getDescription() const
00036 {
00037    ASCString res = "Register Unit RF Target ";
00038    if ( getUnit(false) ) 
00039       res += " of unit " + getUnit(false)->getName();
00040    
00041    return  res;
00042 }
00043       
00044       
00045 void RegisterUnitRFTarget::readData ( tnstream& stream ) 
00046 {
00047    UnitAction::readData( stream );
00048    int version = stream.readInt();
00049    if ( version != 1 )
00050       throw tinvalidversion ( "ChangeUnitMovement", 1, version );
00051    
00052    targetUnitID = stream.readInt();
00053    weapon = stream.readInt();
00054 };
00055       
00056       
00057 void RegisterUnitRFTarget::writeData ( tnstream& stream ) const
00058 {
00059    UnitAction::writeData( stream );
00060    stream.writeInt( 1 );
00061    stream.writeInt( targetUnitID );
00062    stream.writeInt( weapon );
00063 };
00064 
00065 
00066 GameActionID RegisterUnitRFTarget::getID() const
00067 {
00068    return ActionRegistry::RegisterUnitRFTarget;
00069 }
00070 
00071 ActionResult RegisterUnitRFTarget::runAction( const Context& context )
00072 {
00073    Vehicle* veh = getUnit();
00074    veh->reactionfire.weaponShots[weapon]--;
00075    veh->reactionfire.nonattackableUnits.push_back ( targetUnitID );
00076    
00077    return ActionResult(0);
00078 }
00079 
00080 
00081 ActionResult RegisterUnitRFTarget::undoAction( const Context& context )
00082 {
00083    Vehicle* veh = getUnit();
00084    veh->reactionfire.weaponShots[weapon]++;
00085    
00086    veh->reactionfire.nonattackableUnits.erase ( find( veh->reactionfire.nonattackableUnits.begin(), veh->reactionfire.nonattackableUnits.end(), targetUnitID ));
00087    return ActionResult(0);
00088 }
00089 
00090 
00091 
00092 namespace {
00093    const bool r1 = registerAction<RegisterUnitRFTarget> ( ActionRegistry::RegisterUnitRFTarget );
00094 }
00095 

Generated on Mon May 21 01:26:36 2012 for Advanced Strategic Command by  doxygen 1.5.1