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
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#include "IPathDrawer.h"
#include "DefaultPathDrawer.h"
#include "QTPFSPathDrawer.h"
#include "Game/SelectedUnitsHandler.h"
#include "Sim/MoveTypes/MoveDefHandler.h"
#include "Sim/Path/IPathManager.h"
#include "Sim/Path/Default/PathManager.h"
#include "Sim/Path/QTPFS/PathManager.hpp"
#include "Sim/Units/Unit.h"
#include "Sim/Units/UnitDef.h"
#include "System/EventHandler.h"
IPathDrawer* pathDrawer = NULL;
IPathDrawer* IPathDrawer::GetInstance() {
static IPathDrawer* pd = NULL;
if (pd == NULL) {
if (dynamic_cast<QTPFS::PathManager*>(pathManager) != NULL) {
return (pd = new QTPFSPathDrawer());
}
if (dynamic_cast<CPathManager*>(pathManager) != NULL) {
return (pd = new DefaultPathDrawer());
}
pd = new IPathDrawer();
}
return pd;
}
void IPathDrawer::FreeInstance(IPathDrawer* pd) {
delete pd;
}
IPathDrawer::IPathDrawer(): CEventClient("[IPathDrawer]", 271991, false), enabled(false) {
eventHandler.AddClient(this);
}
IPathDrawer::~IPathDrawer() {
eventHandler.RemoveClient(this);
}
const MoveDef* IPathDrawer::GetSelectedMoveDef() {
const MoveDef* md = NULL;
const CUnitSet& unitSet = selectedUnitsHandler.selectedUnits;
if (!unitSet.empty()) {
const CUnit* unit = *(unitSet.begin());
md = unit->moveDef;
}
return md;
}
SColor IPathDrawer::GetSpeedModColor(const float sm) {
SColor col(120, 0, 80);
if (sm > 0.0f) {
col.r = 255 - std::min(sm * 255.0f, 255.0f);
col.g = 255 - col.r;
col.b = 0;
}
return col;
}
#if 0
float IPathDrawer::GetSpeedModNoObstacles(const MoveDef* md, int sqx, int sqz) {
float m = 0.0f;
const int hmIdx = sqz * gs->mapxp1 + sqx;
const int cnIdx = sqz * gs->mapx + sqx;
const float height = hm[hmIdx];
const float slope = 1.0f - cn[cnIdx].y;
if (md->speedModClass == MoveDef::Ship) {
// only check water depth
m = (height >= (-md->depth))? 0.0f: m;
} else {
// check depth and slope (if hover, only over land)
m = std::max(0.0f, 1.0f - (slope / (md->maxSlope + 0.1f)));
m = (height < (-md->depth))? 0.0f: m;
m = (height <= 0.0f && md->speedModClass == MoveDef::Hover)? 1.0f: m;
}
return m;
}
#endif
|