1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/*! \file objects.cpp
\brief Mine and Objects which can be placed on a map field
*/
/***************************************************************************
gamemap.cpp - description
-------------------
begin : Tue May 21 2005
copyright : (C) 2005 by Martin Bickel
email : bickel@asc-hq.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <algorithm>
#include <ctime>
#include <cmath>
#include "global.h"
#include "misc.h"
#include "typen.h"
#include "vehicletype.h"
#include "buildingtype.h"
#include "itemrepository.h"
#include "graphics/blitter.h"
#include "iconrepository.h"
#include "objects.h"
#include "graphics/blitter.h"
const char* MineNames[cminenum] = {"antipersonnel mine", "antitank mine", "antisub mine", "antiship mine"};
const int MineBasePunch[cminenum] = { 60, 120, 180, 180 };
void MineType :: paint ( Surface& surface, const SPoint& pos ) const
{
paint( type, 0, surface, pos );
}
void MineType::paint( MineTypes type, int player, Surface& surf, const SPoint& pos )
{
static Surface* images[5] = { NULL, NULL, NULL, NULL, NULL };
if ( !images[type] ) {
switch ( type ) {
case cmantipersonnelmine: images[type] = & IconRepository::getIcon( "antipersonellmine.png" );
break;
case cmantitankmine: images[type] = & IconRepository::getIcon( "antitankmine.png" );
break;
case cmfloatmine:
case cmmooredmine: images[type] = & IconRepository::getIcon( "antishipmine.png" );
break;
};
}
if ( images[type] ) {
if ( type != cmmooredmine )
megaBlitter< ColorTransform_None, ColorMerger_AlphaOverwrite, SourcePixelSelector_Plain, TargetPixelSelector_All >
( *images[type], surf, pos, nullParam,nullParam, nullParam,nullParam);
else
megaBlitter< ColorTransform_None, ColorMerger_AlphaMixer, SourcePixelSelector_Plain, TargetPixelSelector_All >
( *images[type], surf, pos, nullParam,nullParam, nullParam,nullParam);
}
}
bool AgeableItem::age( AgeableItem& obj )
{
if ( obj.lifetimer > 0 ) {
--obj.lifetimer;
return obj.lifetimer==0;
} else
return false;
}
Object :: Object ( )
{
typ = NULL;
dir = 0;
damage = 0;
remainingGrowthTime = -1;
}
Object :: Object ( const ObjectType* o )
{
lifetimer = o->lifetime;
typ = o;
dir = 0;
damage = 0;
remainingGrowthTime = o->growthDuration;
}
void Object :: setDir ( int direc )
{
dir = direc;
}
int Object :: getDir() const
{
return dir;
}
void Object :: display ( Surface& surface, const SPoint& pos, int weather ) const
{
typ->display ( surface, pos, dir, weather );
}
const OverviewMapImage* Object :: getOverviewMapImage( int weather )
{
return typ->getOverviewMapImage( dir, weather );
}
const int objectVersion = 1;
void Object::write ( tnstream& stream )
{
stream.writeInt( objectVersion );
stream.writeInt( lifetimer );
stream.writeInt( damage );
stream.writeInt( dir );
stream.writeInt( remainingGrowthTime );
}
void Object::read ( tnstream& stream )
{
int version = stream.readInt();
if ( version < 1 || version > objectVersion )
throw tinvalidversion ( "Object", 1, version );
lifetimer = stream.readInt();
damage = stream.readInt();
dir = stream.readInt();
remainingGrowthTime = stream.readInt();
}
|