ttrts/game/unitv.cpp
Marc Di Luzio 008739dee6 Various work towards a basic game implementation
Get rid of some virtual functions that weren't needed.
Fix some functions to work during static init if need be.
Units now have unique incremental IDs
2014-12-16 13:13:00 +00:00

63 lines
No EOL
1.1 KiB
C++

#include "unitv.h"
#include <map> // for std::map
CUnitV::CUnitV()
: dir(dir_t::S)
{
updateMyVisual();
}
// Map of visual representation of unitv
namespace
{
typedef std::map< dir_t, unitVis_c > dir_to_vis_map;
// Helper function to get the vis map during static init
const dir_to_vis_map& get_vis_map()
{
static const dir_to_vis_map sk_visMap =
{
{dir_t::N,'^'},
{dir_t::E,'>'},
{dir_t::S,'v'},
{dir_t::W,'<'},
};
return sk_visMap;
}
}
// Update the visual representation of the unit
unitVis_c CUnitV::updateMyVisual()
{
// Start at invalid
setVisual(unitVis_invalid);
dir_to_vis_map::const_iterator it = get_vis_map().find(dir);
// If found set to new vis
if( it != get_vis_map().end() )
setVisual(it->second);
return getVisual();
}
bool CUnitV::setFromVisual( unitVis_c& vis )
{
dir_to_vis_map::const_iterator it;
for( it = get_vis_map().begin(); it != get_vis_map().end(); it++ )
{
if( it->second == vis )
{
dir == it->first;
updateMyVisual();
return true;
}
}
// No matching direction to visual
return false;
}