lsnes rr2-β24
[lsnes.git] / src / emulation / sky / tile.cpp
blob1bfde27b3201785c23ad73bf7a05bc11e6c0fdd5
1 #include "tile.hpp"
3 namespace sky
5 const uint16_t _floorheights[6] = {0, 12800, 15360, 17000, 20000, 25000 };
7 const uint8_t _floor_height[256] = {
8 0, 1, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 5
9 };
11 const uint8_t _tunnel_inner[38] = {
12 16, 16, 16, 16, 15, 14, 13, 11,
13 8, 7, 6, 5, 3, 3, 3, 3,
14 3, 3, 2, 1, 0, 0, 0, 0,
15 0, 0, 1, 2, 3, 3, 3, 3,
16 3, 3, 5, 6, 7, 8
19 const uint8_t _tunnel_outer[38] = {
20 32, 32, 32, 32, 32, 32, 32, 32,
21 32, 32, 32, 32, 32, 32, 32, 32,
22 32, 31, 31, 31, 31, 31, 30, 30,
23 30, 29, 29, 29, 28, 27, 26, 25,
24 24, 22, 20, 18, 17, 14
27 int tile::apparent_height() throw()
29 if((_tile & 0xE00) <= 0x400)
30 return (_tile & 0xF00) >> 9;
31 else
32 return -1;
34 bool tile::is_colliding_floor(int16_t hchunk, int16_t vpos)
36 return has_lower_floor() && vpos > 7808 && vpos < 10240;
38 bool tile::is_colliding(int16_t hchunk, int16_t vpos)
40 if(hchunk <= 0)
41 hchunk = 1 - hchunk;
42 if(vpos <= 8576 || hchunk > 37)
43 return false;
44 //Glitched tiles
45 if((_tile & 0xE00) >= 0x600)
46 return true;
47 //Tunnels.
48 if((_tile & 0x100) != 0) {
49 int16_t rvpos = vpos - 8704;
50 if(rvpos >= 0 && rvpos < (128 * _tunnel_inner[hchunk]))
51 return false;
53 //Upper limits.
54 if((_tile & 0xE00) == 0x400 && vpos >= 15360)
55 return false;
56 if((_tile & 0xE00) == 0x200 && vpos >= 12800)
57 return false;
58 if((_tile & 0xF00) == 0 && vpos >= 10240)
59 return false;
60 //The bare turnnel special.
61 if((_tile & 0xF00) == 0x100) {
62 int16_t rvpos = vpos - 8704;
63 if(rvpos >= 0 && rvpos >= (128 * _tunnel_outer[hchunk]))
64 return false;
66 return true;
68 int16_t tile::upper_level()
70 return _floorheights[_floor_height[_tile >> 8]];
72 unsigned tile::surface_type(int16_t vpos)
74 if(vpos == 10240)
75 return lower_floor();
76 else if(vpos == upper_level())
77 return upper_floor();
78 else
79 return 16; //None.
81 bool tile::is_dangerous()
83 if((_tile & 0xF00) == 0)
84 return ((_tile & 0xF) == 0x00 || (_tile & 0xF) == 0xC);
85 if((_tile & 0xF00) == 0x100)
86 return false;
87 return ((_tile & 0xF0) == 0xC0);
89 bool tile::in_pipe(uint16_t hchunk, int16_t vpos)
91 if(hchunk > 23 || !is_tunnel())
92 return false;
93 return (vpos - 8704 < ((_tunnel_inner[hchunk] + _tunnel_outer[hchunk]) / 2) * 128);