forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoordinates.h
90 lines (76 loc) · 2.51 KB
/
coordinates.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
89
90
#ifndef _COORDINATES_H_
#define _COORDINATES_H_
#include <stdlib.h>
#include <vector>
#include <string>
#include <set>
#include <map>
#include "mapdata.h"
#include "overmap.h"
/* find appropriate subdivided coordinates for absolute tile coordinate.
* This is less obvious than one might think, for negative coordinates, so this
* was created to give a definitive answer.
*
* 'absolute' is defined as the -actual- submap x,y * 12 + position in submap, and
* can be obtained from map.getabs(x, y);
* usage:
* real_coords rc( g->m.getabs(g->u.posx, g->u.posy ) );
*/
struct real_coords {
static const int subsize = SEEX;
static const int subsizen = subsize - 1;
static const int omsize = OMAPX * 2;
static const int omsizen = omsize - 1;
point abs_pos; // 1 per tile, starting from tile 0,0 of submap 0,0 of overmap 0,0
point abs_sub; // submap: 12 tiles.
point abs_om; // overmap: 360 submaps.
point sub_pos; // coordinate (0-11) in submap / abs_pos constrained to % 12.
point om_pos; // overmap tile: 2x2 submaps.
point om_sub; // submap (0-359) in overmap / abs_sub constrained to % 360. equivalent to g->levx
real_coords() {
}
real_coords(point ap) {
fromabs( ap.x, ap.y );
}
void fromabs(const int absx, const int absy) {
const int normx = abs(absx);
const int normy = abs(absy);
abs_pos = point(absx, absy);
if ( absx < 0 ) {
abs_sub.x = (absx-11)/12;
sub_pos.x = 11-((normx-1) % 12);
abs_om.x = (abs_sub.x-omsizen)/omsize;
om_sub.x = omsizen-(((normx-1)/12) % omsize);
om_pos.x = om_sub.x / 2;
} else {
abs_sub.x = normx/12;
sub_pos.x = absx % 12;
abs_om.x = abs_sub.x/omsize;
om_sub.x = abs_sub.x % omsize;
om_pos.x = om_sub.x / 2;
}
if ( absy < 0 ) {
abs_sub.y = (absy-11)/12;
sub_pos.y = 11-((normy-1) % 12);
abs_om.y = (abs_sub.y-omsizen)/omsize;
om_sub.y = omsizen-(((normy-1)/12) % omsize);
om_pos.y = om_sub.y / 2;
} else {
abs_sub.y = normy/12;
sub_pos.y = absy % 12;
abs_om.y=abs_sub.y/omsize;
om_sub.y = abs_sub.y % omsize;
om_pos.y = om_sub.y / 2;
}
}
void fromabs(point absolute) {
fromabs(absolute.x, absolute.y);
}
// specifically for the subjective position returned by overmap::draw
void fromomap( int rel_omx, int rel_omy, int rel_om_posx, int rel_om_posy ) {
int ax=(rel_omx*OMAPX) + rel_om_posx;
int ay=(rel_omy*OMAPY) + rel_om_posy;
fromabs(ax*24, ay*24);
}
};
#endif