Advanced Strategic Command
explosivemines.cpp
Go to the documentation of this file.
1 
2 /***************************************************************************
3  gamemap.cpp - description
4  -------------------
5  begin : Tue May 21 2005
6  copyright : (C) 2005 by Martin Bickel
7  email : bickel@asc-hq.org
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include <algorithm>
20 #include <ctime>
21 #include <cmath>
22 
23 #include "global.h"
24 #include "misc.h"
25 #include "typen.h"
26 #include "vehicletype.h"
27 #include "buildingtype.h"
28 #include "itemrepository.h"
29 #include "graphics/blitter.h"
30 #include "iconrepository.h"
31 #include "objects.h"
32 #include "graphics/blitter.h"
33 
34 #include "spfst.h"
35 #include "gamemap.h"
36 
37 
38 
39 
40 bool Mine :: attacksunit ( const Vehicle* veh ) const
41 {
42  #ifndef converter
43  if (!( ( veh->typ->hasFunction( ContainerBaseType::ImmuneToMines ) ) ||
44  ( veh->height > chfahrend ) ||
45  ( veh->getMap()->getPlayer(player).diplomacy.getState(veh->getOwner()) >= PEACE ) ||
46  ( (veh->typ->movemalustyp == cmm_trooper) && (type != cmantipersonnelmine)) ||
47  ( veh->height <= chgetaucht && type != cmmooredmine ) ||
48  ( veh->height == chschwimmend && type != cmfloatmine ) ||
50  ))
51  return true;
52 #endif
53  return false;
54 }
55 
56 
57 
58 void Mine::paint( Surface& surf, SPoint pos ) const
59 {
60  MineType::paint( type, player, surf, pos );
61 }
62 
63 
64 
65 Mine::Mine( MineTypes type, int strength, int player, GameMap* gamemap )
66 {
67  this->type = type;
68  this->strength = strength;
69  this->player = player;
70  this->identifier = gamemap->idManager.getNewNetworkID();
71  #ifndef converter
73  #endif
74 }
75 
76 Mine::Mine( MineTypes type, int strength, int player, GameMap* gamemap, int identifier )
77 {
78  this->type = type;
79  this->strength = strength;
80  this->player = player;
81  this->identifier = identifier;
82  #ifndef converter
84  #endif
85 }
86 
87 const int mineVersion = 1;
88 void Mine::read ( tnstream& stream )
89 {
90  int version = stream.readInt();
91  if ( version < 1 || version > mineVersion )
92  throw tinvalidversion ( "Mine", mineVersion, version );
93 
94  identifier = stream.readInt();
95  type = MineTypes( stream.readInt() );
96  strength = stream.readInt();
97  player = stream.readInt();
98 }
99 
100 void Mine::write ( tnstream& stream ) const
101 {
102  stream.writeInt( mineVersion );
103  stream.writeInt( identifier );
104  stream.writeInt( type );
105  stream.writeInt( strength );
106  stream.writeInt( player );
107 }
108 
109 Mine::Mine()
110 {
111 }
112 
114 {
115  Mine m;
116  m.read( stream );
117  return m;
118 }
DiplomaticStates getState(PlayerID towardsPlayer) const
Definition: player.cpp:92
int identifier
a unique identifier that allows the identification of a single mine
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
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
map accessing and usage routines used by ASC and the mapeditor
miscellaneous functions which are used by ASC and all its tools
#define chschwimmend
Definition: typen.h:412
int getNewNetworkID()
returns a new and unique ID
Definition: gamemap.cpp:1139
bool attacksunit(const Vehicle *veh) const
can the mine attack this unit
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
DiplomaticStateVector diplomacy
Definition: player.h:209
bool hasFunction(ContainerFunctions function) const
int getOwner() const
returns the number of the player this vehicle/building belongs to
void write(tnstream &stream) const
Global platform dependant definitions. This file just branches to the platform specific files in thei...
The interface for all kinds of IO stream.
void paint(Surface &surf, SPoint pos) const
display the mine
int height
the current level of height ( BITMAPPED ! )
Definition: vehicle.h:118
MineTypes
Definition: objects.h:70
int lifetimer
Definition: objects.h:37
MineTypes type
int movemalustyp
The category of the unit. Original used only to distinguish only between different movement costs for...
Definition: vehicletype.h:206
Definition of THE central asc class: GameMap.
void paint(Surface &surface, const SPoint &pos) const
Definition: objects.cpp:41
int player
the player who placed the mine; range 0 .. 7
The interface for the buildingtype class.
int strength
the effective punch of the mine
#define chfahrend
Definition: typen.h:413
SDLmm::SPoint SPoint
Definition: surface.h:27
const int mineVersion
GameParameter
Definition: gamemap.h:77
int getgameparameter(GameParameter num) const
Definition: gamemap.cpp:1047
class GameMap::IDManager idManager
Definition: player.h:53
void read(tnstream &stream)
const VehicleType * typ
Definition: vehicle.h:83
Mine and Objects which can be placed on a map field.
GameMap * getMap() const
#define chgetaucht
Definition: typen.h:411
const int cmm_trooper
the movemalus type of a trooper.
Definition: typen.h:390
static Mine newFromStream(tnstream &stream)
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182