2014-12-16 13:12:54 +00:00
|
|
|
#include "unitv.h"
|
|
|
|
|
2014-12-16 13:12:55 +00:00
|
|
|
#include <map> // for std::map
|
|
|
|
|
|
|
|
CUnitV::CUnitV()
|
|
|
|
: dir(dir_t::S)
|
2014-12-16 13:12:54 +00:00
|
|
|
{
|
2014-12-16 13:13:00 +00:00
|
|
|
updateMyVisual();
|
2014-12-16 13:12:55 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 13:12:56 +00:00
|
|
|
|
|
|
|
// Map of visual representation of unitv
|
2014-12-16 13:13:00 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-12-16 13:12:55 +00:00
|
|
|
|
2014-12-16 13:13:00 +00:00
|
|
|
// Update the visual representation of the unit
|
|
|
|
unitVis_c CUnitV::updateMyVisual()
|
2014-12-16 13:12:56 +00:00
|
|
|
{
|
2014-12-16 13:13:00 +00:00
|
|
|
// Start at invalid
|
|
|
|
setVisual(unitVis_invalid);
|
2014-12-16 13:12:55 +00:00
|
|
|
|
2014-12-16 13:13:00 +00:00
|
|
|
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);
|
2014-12-16 13:12:54 +00:00
|
|
|
|
2014-12-16 13:13:00 +00:00
|
|
|
return getVisual();
|
2014-12-16 13:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CUnitV::setFromVisual( unitVis_c& vis )
|
|
|
|
{
|
2014-12-16 13:13:00 +00:00
|
|
|
dir_to_vis_map::const_iterator it;
|
2014-12-16 13:12:56 +00:00
|
|
|
|
2014-12-16 13:13:00 +00:00
|
|
|
for( it = get_vis_map().begin(); it != get_vis_map().end(); it++ )
|
2014-12-16 13:12:56 +00:00
|
|
|
{
|
|
|
|
if( it->second == vis )
|
|
|
|
{
|
|
|
|
dir == it->first;
|
2014-12-16 13:13:00 +00:00
|
|
|
updateMyVisual();
|
2014-12-16 13:12:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching direction to visual
|
|
|
|
return false;
|
2014-12-16 13:12:55 +00:00
|
|
|
}
|