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
|
/***************************************************************************
* *
* 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 "weaponrangelayer.h"
#include "gamemap.h"
#include "spfst.h"
#include "iconrepository.h"
void UnitWeaponRangeLayer::markField( const MapCoordinate& pos )
{
fields[pos] |= 1;
}
bool UnitWeaponRangeLayer::fieldVisible( const MapCoordinate& pos )
{
#ifdef karteneditor
return true;
#else
return fieldvisiblenow ( gamemap->getField( pos ));
#endif
}
bool UnitWeaponRangeLayer::addUnit( Vehicle* veh )
{
if ( fieldVisible( MapCoordinate(veh->xpos, veh->ypos ))) {
int found = 0;
for ( int i = 0; i < veh->typ->weapons.count; i++ ) {
if ( veh->typ->weapons.weapon[i].shootable() ) {
circularFieldIterator( gamemap,veh->getPosition(), veh->typ->weapons.weapon[i].maxdistance/minmalq, (veh->typ->weapons.weapon[i].mindistance+maxmalq-1)/maxmalq, FieldIterationFunctor( this, &UnitWeaponRangeLayer::markField ) );
found++;
}
}
if ( found )
fields[veh->getPosition()] |= 2;
return found;
} else
return false;
};
void UnitWeaponRangeLayer::reset()
{
fields.clear();
}
void UnitWeaponRangeLayer::operateField( GameMap* actmap, const MapCoordinate& pos )
{
if ( !pos.valid() )
return;
if ( gamemap && gamemap != actmap )
reset();
gamemap = actmap;
if ( fields.find( pos ) != fields.end() ) {
if ( fields[pos] & 2 ) {
reset();
setActive(false);
statusMessage("Weapon range layer disabled");
repaintMap();
return;
}
}
if ( actmap->getField( pos )->vehicle ) {
if ( addUnit( actmap->getField( pos )->vehicle ) ) {
setActive(true);
statusMessage("Weapon range layer enabled");
repaintMap();
}
}
}
UnitWeaponRangeLayer::UnitWeaponRangeLayer() : icon1 ( IconRepository::getIcon( "markedfield-red.png")), icon2 ( IconRepository::getIcon( "markedfield-red2.png")), gamemap(NULL) {
// cursorMoved.connect( sigc::mem_fun( *this, UnitWeaponRangeLayer::cursorMoved ));
}
void UnitWeaponRangeLayer::paintSingleField( const MapRenderer::FieldRenderInfo& fieldInfo, int layer, const SPoint& pos )
{
if ( fieldInfo.gamemap != gamemap && gamemap) {
reset();
gamemap = NULL;
return;
}
if ( fieldInfo.visibility >= visible_ago) {
if ( fields.find( fieldInfo.pos ) != fields.end() ) {
int p = fields[fieldInfo.pos];
if ( p & 1 )
fieldInfo.surface.Blit( icon1, pos );
if ( p & 2 )
fieldInfo.surface.Blit( icon2, pos );
}
}
}
|