forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapgenformat.h
88 lines (76 loc) · 3.09 KB
/
mapgenformat.h
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
#pragma once
#ifndef CATA_SRC_MAPGENFORMAT_H
#define CATA_SRC_MAPGENFORMAT_H
#include <cstddef>
#include <string>
#include <utility>
#include <vector>
#include "type_id.h"
class map;
struct point;
namespace mapf
{
template<typename ID>
class format_effect;
/**
* Set terrain and furniture on the supplied map.
* @param m The supplied map
* @param ter_b,furn_b The lookup table for placing terrain / furniture
* (result of @ref ter_bind / @ref furn_bind).
* @param cstr Contains the ASCII representation of the map. Each character in it represents
* one tile on the map. It will be looked up in \p ter_b and \p furn_b to get the terrain/
* furniture to place there (if that lookup returns a null id, nothing is set on the map).
* A newline character continues on the next line (resets `x` to \p startx and increments `y`).
* @param start Coordinates in the map where to start drawing \p cstr.
*/
void formatted_set_simple( map *m, point start, const char *cstr,
const format_effect<ter_id> &ter_b, const format_effect<furn_id> &furn_b );
template<typename ID>
class format_effect
{
private:
std::string characters;
std::vector<ID> determiners;
public:
format_effect( const std::string &chars,
std::vector<ID> dets );
ID translate( char c ) const;
};
/**
* The functions create a mapping of characters to ids, usable with @ref formatted_set_simple.
* The first parameter must a string literal, containing the mapped characters.
* Only every second character of it is mapped:
* `"a b c"` maps `a` to the first id, `b` to the second and `c` to the third id.
* The further parameters form an array of suitable size with ids to map to.
*
* \code
* ter_bind( "a", t_dirt );
* ter_bind( "a b", t_dirt, t_wall );
* // This does not work (t_wall is not mapped to any character):
* ter_bind( "a", t_dirt, t_wall );
* // This does not work (character b is not mapped to any id):
* ter_bind( "a b", t_dirt );
* \endcode
*/
/**@{*/
template<size_t N, typename ...Args>
inline format_effect<ter_id> ter_bind( const char ( &characters )[N], Args... ids )
{
// Note to self: N contains the 0-char at the end of a string literal!
static_assert( N % 2 == 0, "list of characters to bind to must be odd, e.g. \"a b c\"" );
static_assert( N / 2 == sizeof...( Args ),
"list of characters to bind to must match the size of the remaining arguments" );
return format_effect<ter_id>( characters, { std::forward<Args>( ids )... } );
}
template<size_t N, typename ...Args>
inline format_effect<furn_id> furn_bind( const char ( &characters )[N], Args... ids )
{
// Note to self: N contains the 0-char at the end of a string literal!
static_assert( N % 2 == 0, "list of characters to bind to must be odd, e.g. \"a b c\"" );
static_assert( N / 2 == sizeof...( Args ),
"list of characters to bind to must match the size of the remaining arguments" );
return format_effect<furn_id>( characters, { std::forward<Args>( ids )... } );
}
/**@}*/
} //END NAMESPACE mapf
#endif // CATA_SRC_MAPGENFORMAT_H