forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapgenformat.cpp
62 lines (54 loc) · 1.53 KB
/
mapgenformat.cpp
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
#include "mapgenformat.h"
#include <cctype>
#include <algorithm>
#include "map.h"
#include "mapdata.h"
#include "point.h"
namespace mapf
{
void formatted_set_simple( map *m, const point &start, const char *cstr,
const format_effect<ter_id> &ter_b, const format_effect<furn_id> &furn_b )
{
const char *p = cstr;
point p2( start );
while( *p != 0 ) {
if( *p == '\n' ) {
p2.y++;
p2.x = start.x;
} else {
const ter_id ter = ter_b.translate( *p );
const furn_id furn = furn_b.translate( *p );
if( ter != t_null ) {
m->ter_set( p2, ter );
}
if( furn != f_null ) {
if( furn == f_toilet ) {
m->place_toilet( p2 );
} else {
m->furn_set( p2, furn );
}
}
p2.x++;
}
p++;
}
}
template<typename ID>
format_effect<ID>::format_effect( const std::string &chars, std::vector<ID> dets )
: characters( chars ), determiners( dets )
{
characters.erase( std::remove_if( characters.begin(), characters.end(), isspace ),
characters.end() );
}
template<typename ID>
ID format_effect<ID>::translate( const char c ) const
{
const auto index = characters.find( c );
if( index == std::string::npos ) {
return ID( 0 );
}
return determiners[index];
}
template class format_effect<furn_id>;
template class format_effect<ter_id>;
}//END NAMESPACE mapf