explosivemines.cpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003                           gamemap.cpp  -  description
00004                              -------------------
00005     begin                : Tue May 21 2005
00006     copyright            : (C) 2005 by Martin Bickel
00007     email                : bickel@asc-hq.org
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #include <algorithm>
00020 #include <ctime>
00021 #include <cmath>
00022 
00023 #include "global.h"
00024 #include "misc.h"
00025 #include "typen.h"
00026 #include "vehicletype.h"
00027 #include "buildingtype.h"
00028 #include "itemrepository.h"
00029 #include "graphics/blitter.h"
00030 #include "iconrepository.h"
00031 #include "objects.h"
00032 #include "graphics/blitter.h"
00033 
00034 #include "spfst.h"
00035 #include "gamemap.h"
00036 
00037 
00038 
00039 
00040 bool Mine :: attacksunit ( const Vehicle* veh ) const
00041 {
00042    #ifndef converter
00043    if  (!( ( veh->typ->hasFunction( ContainerBaseType::ImmuneToMines  ) ) ||
00044               ( veh->height > chfahrend ) ||
00045               ( veh->getMap()->getPlayer(player).diplomacy.getState(veh->getOwner()) >= PEACE ) ||
00046               ( (veh->typ->movemalustyp ==  cmm_trooper) && (type != cmantipersonnelmine)) || 
00047               ( veh->height <= chgetaucht && type != cmmooredmine ) || 
00048               ( veh->height == chschwimmend && type != cmfloatmine ) ||
00049               ( veh->height == chfahrend && type != cmantipersonnelmine  && type != cmantitankmine )
00050             ))
00051          return true;
00052 #endif
00053      return false;
00054 }
00055 
00056 
00057 
00058 void Mine::paint( Surface& surf, SPoint pos ) const
00059 {
00060    MineType::paint( type, player, surf, pos );   
00061 }
00062 
00063 
00064 
00065 Mine::Mine( MineTypes type, int strength, int player, GameMap* gamemap )
00066 {
00067    this->type = type;
00068    this->strength = strength;
00069    this->player = player;
00070    this->identifier = gamemap->idManager.getNewNetworkID();
00071    #ifndef converter
00072    lifetimer = gamemap->getgameparameter( GameParameter(cgp_antipersonnelmine_lifetime + type - 1));
00073    #endif
00074 }
00075 
00076 Mine::Mine( MineTypes type, int strength, int player, GameMap* gamemap, int identifier )
00077 {
00078    this->type = type;
00079    this->strength = strength;
00080    this->player = player;
00081    this->identifier = identifier;
00082    #ifndef converter
00083    lifetimer = gamemap->getgameparameter( GameParameter(cgp_antipersonnelmine_lifetime + type - 1));
00084    #endif
00085 }
00086 
00087 const int mineVersion = 1;
00088 void Mine::read ( tnstream& stream )
00089 {
00090    int version = stream.readInt();
00091    if ( version < 1 || version > mineVersion ) 
00092       throw tinvalidversion ( "Mine", mineVersion, version );
00093       
00094    identifier = stream.readInt();
00095    type = MineTypes( stream.readInt() );
00096    strength = stream.readInt();
00097    player = stream.readInt();
00098 }
00099 
00100 void Mine::write ( tnstream& stream ) const
00101 {
00102    stream.writeInt( mineVersion );
00103    stream.writeInt( identifier );
00104    stream.writeInt( type );
00105    stream.writeInt( strength );
00106    stream.writeInt( player );
00107 }
00108 
00109 Mine::Mine()
00110 {
00111 }
00112 
00113 Mine Mine::newFromStream ( tnstream& stream )
00114 {
00115    Mine m;
00116    m.read( stream );
00117    return m;  
00118 }

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