Advanced Strategic Command
objects.cpp
Go to the documentation of this file.
1 
5 /***************************************************************************
6  gamemap.cpp - description
7  -------------------
8  begin : Tue May 21 2005
9  copyright : (C) 2005 by Martin Bickel
10  email : bickel@asc-hq.org
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #include <algorithm>
23 #include <ctime>
24 #include <cmath>
25 
26 #include "global.h"
27 #include "misc.h"
28 #include "typen.h"
29 #include "vehicletype.h"
30 #include "buildingtype.h"
31 #include "itemrepository.h"
32 #include "graphics/blitter.h"
33 #include "iconrepository.h"
34 #include "objects.h"
35 #include "graphics/blitter.h"
36 
37 
38 const char* MineNames[cminenum] = {"antipersonnel mine", "antitank mine", "antisub mine", "antiship mine"};
39 const int MineBasePunch[cminenum] = { 60, 120, 180, 180 };
40 
41 void MineType :: paint ( Surface& surface, const SPoint& pos ) const
42 {
43  paint( type, 0, surface, pos );
44 }
45 
46 void MineType::paint( MineTypes type, int player, Surface& surf, const SPoint& pos )
47 {
48  static Surface* images[5] = { NULL, NULL, NULL, NULL, NULL };
49  if ( !images[type] ) {
50  switch ( type ) {
51  case cmantipersonnelmine: images[type] = & IconRepository::getIcon( "antipersonellmine.png" );
52  break;
53  case cmantitankmine: images[type] = & IconRepository::getIcon( "antitankmine.png" );
54  break;
55  case cmfloatmine:
56  case cmmooredmine: images[type] = & IconRepository::getIcon( "antishipmine.png" );
57  break;
58  };
59  }
60  if ( images[type] ) {
61  if ( type != cmmooredmine )
62  megaBlitter< ColorTransform_None, ColorMerger_AlphaOverwrite, SourcePixelSelector_Plain, TargetPixelSelector_All >
63  ( *images[type], surf, pos, nullParam,nullParam, nullParam,nullParam);
64  else
65  megaBlitter< ColorTransform_None, ColorMerger_AlphaMixer, SourcePixelSelector_Plain, TargetPixelSelector_All >
66  ( *images[type], surf, pos, nullParam,nullParam, nullParam,nullParam);
67  }
68 }
69 
70 
72 {
73  if ( obj.lifetimer > 0 ) {
74  --obj.lifetimer;
75  return obj.lifetimer==0;
76  } else
77  return false;
78 }
79 
80 
82 {
83  typ = NULL;
84  dir = 0;
85  damage = 0;
87 }
88 
90 {
91  lifetimer = o->lifetime;
92  typ = o;
93  dir = 0;
94  damage = 0;
96 }
97 
98 
99 void Object :: setDir ( int direc )
100 {
101  dir = direc;
102 }
103 
104 int Object :: getDir() const
105 {
106  return dir;
107 }
108 
109 void Object :: display ( Surface& surface, const SPoint& pos, int weather ) const
110 {
111  typ->display ( surface, pos, dir, weather );
112 }
113 
115 {
116  return typ->getOverviewMapImage( dir, weather );
117 }
118 
119 const int objectVersion = 1;
120 
121 void Object::write ( tnstream& stream )
122 {
123  stream.writeInt( objectVersion );
124  stream.writeInt( lifetimer );
125  stream.writeInt( damage );
126  stream.writeInt( dir );
127  stream.writeInt( remainingGrowthTime );
128 }
129 
130 void Object::read ( tnstream& stream )
131 {
132  int version = stream.readInt();
133  if ( version < 1 || version > objectVersion )
134  throw tinvalidversion ( "Object", 1, version );
135 
136  lifetimer = stream.readInt();
137  damage = stream.readInt();
138  dir = stream.readInt();
139  remainingGrowthTime = stream.readInt();
140 }
141 
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
miscellaneous functions which are used by ASC and all its tools
const int objectVersion
Definition: objects.cpp:119
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
NullParamType nullParam
Definition: blitter.cpp:30
int lifetime
the object is removed when it is lifetime turns old. -1 disables removal
Definition: objecttype.h:187
int damage
Definition: objects.h:49
const char * MineNames[cminenum]
Definition: objects.cpp:38
void read(tnstream &stream)
Definition: objects.cpp:130
Object()
Definition: objects.cpp:81
void display(Surface &surface, const SPoint &pos) const
displays the objecttype at x/y on the screen
Definition: objecttype.cpp:289
Global platform dependant definitions. This file just branches to the platform specific files in thei...
The interface for all kinds of IO stream.
const OverviewMapImage * getOverviewMapImage(int picnum, int weather) const
Definition: objecttype.cpp:111
MineTypes
Definition: objects.h:70
void setDir(int dir)
Definition: objects.cpp:99
const ObjectType * typ
Definition: objects.h:48
void write(tnstream &stream)
Definition: objects.cpp:121
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
int lifetimer
Definition: objects.h:37
void paint(Surface &surface, const SPoint &pos) const
Definition: objects.cpp:41
The interface for the buildingtype class.
const int MineBasePunch[cminenum]
Definition: objects.cpp:39
int dir
Definition: objects.h:51
void display(Surface &surface, const SPoint &pos, int weather=0) const
Definition: objects.cpp:109
int growthDuration
the time after which any growth stops.
Definition: objecttype.h:191
SDLmm::SPoint SPoint
Definition: surface.h:27
const OverviewMapImage * getOverviewMapImage(int weather)
Definition: objects.cpp:114
int remainingGrowthTime
Definition: objects.h:52
int getDir() const
Definition: objects.cpp:104
static Surface & getIcon(const ASCString &name)
Mine and Objects which can be placed on a map field.
static bool age(AgeableItem &obj)
ages the object by one turn. Returns true if the object shall be removed
Definition: objects.cpp:71
the image for a TerrainType that is shown on the small map
const int cminenum
Definition: objects.h:66