ttrts/game/orders.cpp
Marc Di Luzio 8a486fdd40 Use snprintf and sscanf instead of std::string tomfoolery
Rename order_c to command_c for better readability
2014-12-16 13:13:02 +00:00

35 lines
565 B
C++

#include <string.h>
#include "orders.h"
#include "mathtypes.h"
// Convert an order to a string
std::string GetStringFromOrder(const COrder& order )
{
static char buff[128];
memset(buff,0,sizeof(buff));
snprintf(buff,128, ORDER_FORMATTER,
order.command,
order.unit);
return buff;
}
// Convert a string to an order
COrder GetOrderFromString( const std::string& order )
{
COrder ret;
char corder;
unsigned int unit;
sscanf(order.c_str(), ORDER_FORMATTER,
&corder,
&unit);
ret.command = (command_c)corder;
ret.unit = unit;
return ret;
}