viewregistration.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 "viewregistration.h"
00023 #include "action-registry.h"
00024 
00025 #include "../vehicle.h"
00026 #include "../gamemap.h"
00027 #include "../viewcalculation.h"
00028      
00029 ViewRegistration::ViewRegistration( ContainerBase* container, Operation operation )
00030    : ContainerAction( container), resultingViewChanges(-1)
00031 {
00032    evalView = false;
00033    this->operation= operation;
00034 }
00035       
00036       
00037 ASCString ViewRegistration::getOpName() const 
00038 {
00039    switch ( operation ) {
00040       case AddView: return "AddView";
00041       case RemoveView: return "RemoveView"; 
00042    }
00043    return "";
00044 }
00045       
00046 ASCString ViewRegistration::getDescription() const
00047 {
00048    ASCString res = getOpName();
00049    if ( getContainer(true) ) 
00050       res += " " + getContainer(true)->getName();
00051 
00052    return  res;
00053 }
00054       
00055       
00056 void ViewRegistration::readData ( tnstream& stream ) 
00057 {
00058    ContainerAction::readData( stream );
00059    int version = stream.readInt();
00060    if ( version != 1 )
00061       throw tinvalidversion ( "ViewRegistration", 1, version );
00062    
00063    operation = (Operation) stream.readInt();
00064    evalView = stream.readInt();
00065    resultingViewChanges = stream.readInt();
00066 };
00067       
00068       
00069 void ViewRegistration::writeData ( tnstream& stream ) const
00070 {
00071    ContainerAction::writeData( stream );
00072    stream.writeInt( 1 );
00073    stream.writeInt( (int) operation );
00074    stream.writeInt( evalView );
00075    stream.writeInt( resultingViewChanges );
00076 };
00077 
00078 
00079 GameActionID ViewRegistration::getID() const
00080 {
00081    return ActionRegistry::ViewRegistration;
00082 }
00083 
00084 ActionResult ViewRegistration::runAction( const Context& context )
00085 {
00086    ContainerBase* veh = getContainer();
00087    
00088    
00089    switch ( operation ) {
00090       case AddView:
00091          veh->addview();
00092          break;
00093          
00094       case RemoveView:
00095          veh->removeview();
00096          break;
00097    }
00098    
00099    return ActionResult(0);
00100 }
00101 
00102 
00103 ActionResult ViewRegistration::undoAction( const Context& context )
00104 {
00105    ContainerBase* veh = getContainer();
00106    switch ( operation ) {
00107       case RemoveView:
00108          veh->addview();
00109          break;
00110          
00111       case AddView:
00112          veh->removeview();
00113          break;
00114          
00115    }
00116    
00117    return ActionResult(0);
00118 }
00119 
00120 ActionResult ViewRegistration::preCheck()
00121 {
00122    return ActionResult(0);
00123 }
00124 
00125 ActionResult ViewRegistration::postCheck()
00126 {
00127    return ActionResult(0);
00128 }
00129 
00130 
00131 
00132 namespace {
00133    const bool r1 = registerAction<ViewRegistration> ( ActionRegistry::ViewRegistration );
00134 }
00135 

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