Pol  Revision:4b29d2b
testwalk.cpp
Go to the documentation of this file.
1 
6 #include "../../clib/logfacility.h"
7 #include "../globals/uvars.h"
8 #include "../realms/realm.h"
9 #include "../uconst.h"
10 #include "testenv.h"
11 
12 namespace Pol
13 {
14 namespace Testing
15 {
16 namespace
17 {
18 using namespace Items;
19 using namespace Multi;
20 using namespace Core;
21 
22 void test_walk( unsigned short /*oldx*/, unsigned short /*oldy*/, short oldz, unsigned short newx,
23  unsigned short newy, bool exp_result, short exp_z )
24 {
25  short newz;
26 
27  INFO_PRINT << "WalkHeight(" << newx << "," << newy << "," << oldz << "): "
28  << "Expect " << exp_result << "," << exp_z << ": ";
29  UMulti* multi;
30  Item* itm;
31  bool res = gamestate.main_realm->walkheight( newx, newy, oldz, &newz, &multi, &itm, true /*doors
32 block*/,
33  MOVEMODE_LAND );
34 
35  INFO_PRINT << "Got " << res << "," << newz << ": ";
36 
37  if ( exp_result != res )
38  {
39  INFO_PRINT << "Failure!\n";
40  inc_failures();
41  return;
42  }
43  if ( exp_result ) // Z is only defined if result is true
44  {
45  if ( exp_z != newz )
46  {
47  INFO_PRINT << "Failure!\n";
48  inc_failures();
49  return;
50  }
51  }
52  inc_successes();
53  INFO_PRINT << "Ok!\n";
54 }
55 
56 void test_walk2( unsigned short /*oldx*/, unsigned short /*oldy*/, short oldz, unsigned short newx,
57  unsigned short newy, bool doors_block, MOVEMODE movemode, bool exp_result,
58  short exp_z )
59 {
60  short newz;
61 
62  INFO_PRINT << "WalkHeight(" << newx << "," << newy << "," << oldz << "): "
63  << "Expect " << exp_result << "," << exp_z << ": ";
64  UMulti* multi;
65  Item* itm;
66  bool res = gamestate.main_realm->walkheight( newx, newy, oldz, &newz, &multi, &itm, doors_block,
67  movemode );
68 
69  INFO_PRINT << "Got " << res << "," << newz << ": ";
70 
71  if ( exp_result != res )
72  {
73  INFO_PRINT << "Failure!\n";
74  inc_failures();
75  return;
76  }
77  if ( exp_result ) // Z is only defined if result is true
78  {
79  if ( exp_z != newz )
80  {
81  INFO_PRINT << "Failure!\n";
82  inc_failures();
83  return;
84  }
85  }
86  inc_successes();
87  INFO_PRINT << "Ok!\n";
88 }
89 } // namespace
90 
91 void walk_test()
92 {
93  INFO_PRINT << "POL datafile tests:\n";
94  test_walk( 1344, 1637, 72, 1345, 1637, true, 72 );
95 
96  // walk down some stairs in Castle Britannia
97  test_walk( 1352, 1635, 72, 1352, 1634, true, 72 );
98  test_walk( 1352, 1634, 72, 1352, 1633, true, 72 );
99  test_walk( 1352, 1633, 72, 1352, 1632, true, 69 );
100  test_walk( 1352, 1632, 69, 1352, 1631, true, 64 );
101  test_walk( 1352, 1631, 64, 1352, 1630, true, 59 );
102  test_walk( 1352, 1630, 59, 1352, 1629, true, 54 );
103  test_walk( 1352, 1629, 54, 1352, 1628, true, 50 );
104  test_walk( 1352, 1628, 50, 1352, 1627, true, 50 );
105 
106  test_walk( 1381, 1625, 30, 1382, 1625, true, 30 );
107  test_walk( 1382, 1626, 30, 1383, 1625, true, 30 );
108 
109  test_walk( 1386, 1628, 30, 1386, 1629, true, 30 );
110 
111  // on the bridge
112  test_walk( 1402, 1626, 28, 1402, 1625, true, 28 );
113  // leaving the bridge
114  test_walk( 1408, 1625, 28, 1409, 1625, true, 28 );
115  test_walk( 1409, 1625, 28, 1410, 1625, true, 28 );
116  test_walk( 1410, 1625, 28, 1411, 1625, true, 26 );
117  test_walk( 1411, 1625, 26, 1412, 1625, true, 25 );
118  test_walk( 1412, 1625, 25, 1413, 1625, true, 24 );
119  test_walk( 1413, 1625, 25, 1414, 1625, true, 23 );
120  test_walk( 1414, 1625, 25, 1415, 1625, true, 22 );
121  test_walk( 1415, 1625, 25, 1416, 1625, true, 21 );
122  test_walk( 1416, 1625, 25, 1417, 1625, true, 20 );
123  test_walk( 1417, 1625, 25, 1418, 1625, true, 20 );
124  test_walk( 1418, 1625, 25, 1419, 1625, true, 20 );
125 
126  // static_debug_on = true;
127  test_walk( 1377, 1759, 1, 1378, 1759, true, 1 );
128 
129  // try walking through a static wall
130  test_walk( 1345, 1649, 72, 1346, 1649, false, 0 );
131 
132  // test the walking on a floor, with a dynamic below you, screwing up.
133  test_walk( 1347, 1659, 72, 1347, 1658, true, 72 );
134  test_walk( 1347, 1658, 72, 1347, 1657, true, 72 );
135 
136 
137  // back on the bridge
138  // static_debug_on = true;
139  test_walk( 1398, 1624, 29, 1399, 1624, true, 28 );
140 
141  // try walking through a portcullis
142  test_walk( 1399, 1625, 27, 1398, 1625, false, 0 );
143 
144  // try walking onto a stone step
145  test_walk( 1310, 1630, 30, 1309, 1630, true, 31 );
146 
147  // try walking onto a dungeon ramp
148  test_walk( 1311, 1637, 30, 1311, 1636, true, 32 );
149 
150  // try walking under a stone arch
151  test_walk( 1311, 1650, 30, 1311, 1649, true, 30 );
152 
153  // try walking through a secret door
154  test_walk( 1316, 1649, 30, 1316, 1648, true, 30 );
155 
156  // try walking through a hide-type door
157  test_walk( 1314, 1654, 30, 1313, 1654, true, 30 );
158 
159  // try walking under a dungeon arch
160  test_walk( 1313, 1658, 30, 1313, 1657, true, 30 );
161 
162  // try walking over a black pearl
163  test_walk( 1315, 1657, 30, 1315, 1658, true, 30 );
164 
165 
166  // walk down some stairs, um, somewhere
167  test_walk( 5920, 40, 44, 5920, 41, true, 41 );
168  test_walk( 5920, 41, 41, 5920, 42, true, 36 );
169  test_walk( 5920, 42, 36, 5920, 43, true, 31 );
170  test_walk( 5920, 43, 31, 5920, 44, true, 26 );
171  test_walk( 5920, 44, 26, 5920, 45, true, 22 );
172  test_walk( 5920, 45, 22, 5921, 45, true, 22 );
173  test_walk( 5921, 45, 22, 5922, 45, true, 22 );
174  // walk up those same stairs
175  test_walk( 5920, 45, 22, 5920, 44, true, 26 );
176  test_walk( 5920, 44, 26, 5920, 43, true, 31 );
177  test_walk( 5920, 43, 31, 5920, 42, true, 36 );
178  test_walk( 5920, 42, 36, 5920, 41, true, 41 );
179  test_walk( 5920, 41, 41, 5920, 40, true, 44 );
180  test_walk( 5920, 40, 44, 5920, 39, true, 44 );
181  test_walk( 5921, 40, 44, 5922, 40, true, 44 );
182 
183  // static_debug_on = true;
184  // walking onto a table?
185  test_walk( 3664, 2589, 0, 3664, 2588, false, 0 );
186  // walking onto a table
187  test_walk( 1594, 1588, 20, 1594, 1587, false, 0 );
188 
189  test_walk( 1262, 1246, 0, 1262, 1245, true, 0 );
190  test_walk( 1264, 1253, 0, 1264, 1252, true, 0 );
191 
192  test_walk( 1441, 1660, 9, 1442, 1660, true, 10 /*9*/ );
193 
194  // near the britain bank,a steep walk
195  test_walk( 1426, 1703, 3, 1425, 1704, true, 9 );
196 
197  // walk up into an orc fort
198  test_walk( 2163, 1330, 0, 2163, 1329, true, 7 );
199 
200  // walk through the gates of Cove
201  test_walk( 2284, 1209, 0, 2283, 1209, true, 0 );
202 
203  // weird stairs in a dungeon
204  test_walk( 5177, 188, 10, 5177, 187, true, 20 );
205 
206  // wind is pissinhg me off...
207  test_walk( 5166, 179, 17, 5166, 180, true, 25 );
208 
209  // a steep grade in ocllo
210  test_walk( 3773, 2654, 0, 3772, 2654, true, 14 );
211 
212  // walk onto a teleporter
213  test_walk( 1175, 2636, 0, 1175, 2635, true, 0 );
214 
215  // walking on a peninsula
216  test_walk( 1909, 51, 0, 1909, 50, true, 0 );
217  test_walk( 1909, 50, 0, 1910, 50, true, -2 );
218  test_walk( 1909, 50, 0, 1909, 49, true, -1 );
219  test_walk( 1909, 50, 0, 1908, 49, true, -2 );
220  test_walk( 1908, 49, -2, 1907, 49, true, -3 );
221 
222  // This is known to fail - diagonal movement here should fail, but is allowed.
223  test_walk( 1908, 51, 0, 1907, 50, false, 0 );
224 
225  test_walk( 1908, 51, 0, 1908, 50, true, 0 );
226  test_walk( 1908, 50, 0, 1907, 50, true, -1 );
227  test_walk( 1909, 51, 0, 1908, 50, true, 0 );
228  test_walk( 1908, 50, 0, 1907, 49, true, -3 );
229  test_walk( 1907, 49, -3, 1906, 49, true, -4 );
230 
231  // ladders
232  test_walk( 2069, 817, 20, 2068, 817, true, 26 );
233  test_walk( 2068, 817, 26, 2067, 817, true, 37 );
234  test_walk( 2043, 807, 20, 2042, 807, true, 26 );
235  test_walk( 2042, 807, 26, 2041, 807, true, 37 );
236 
237  // stairs in T2A
238  test_walk( 2675, 2280, -40, 2675, 2279, true, -35 );
239  test_walk( 2675, 2279, -35, 2675, 2278, true, -29 );
240  // this one asks to be able to step up 9 squares
241  test_walk( 2675, 2278, -29, 2675, 2277, true, -20 );
242 
243  // Ladder by Yew
244  test_walk( 968, 709, -40, 967, 709, true, -35 );
245  test_walk( 967, 709, -35, 966, 709, true, -24 );
246  test_walk( 966, 709, -24, 965, 709, true, -20 );
247 
248  // walking on water
249  test_walk2( 481, 306, -5, 481, 307, true, MOVEMODE_SEA, true, -5 );
250  test_walk2( 481, 306, -5, 481, 307, true, MOVEMODE_LAND, false, 0 );
251 
252  // try walking through a fence
253  test_walk( 1377, 1492, 10, 1377, 1493, false, 0 );
254 
255  // check a static roof tile (shouldn't be able to walk there)
256  test_walk( 1508, 1551, 45, 1508, 1552, false, 0 );
257 
258  // some odd brambles that shouldn't block movement.
259  test_walk( 1058, 1449, 0, 1059, 1449, true, 0 );
260 
261 
262  // an odd cave
263  test_walk( 2605, 458, 60, 2605, 457, true, 60 );
264  test_walk( 2605, 457, 60, 2605, 456, true, 60 );
265  test_walk( 2605, 456, 62, 2605, 455, true, 60 );
266  test_walk( 4723, 3814, 0, 4723, 3813, true, 0 );
267  test_walk( 4110, 431, 5, 4110, 430, true, 5 );
268  test_walk( 1661, 2938, 0, 1661, 2937, true, 0 );
269  test_walk( 1652, 2893, 0, 1651, 2893, true, 0 );
270 
271  // a secret door through the ground:
272  test_walk( 1146, 2228, 20, 1145, 2228, true, 20 );
273  test_walk( 1145, 2228, 20, 1144, 2228, true, 20 );
274  test_walk( 1144, 2228, 20, 1143, 2228, true, 20 );
275  test_walk( 1143, 2228, 20, 1142, 2228, true, 20 );
276  test_walk( 1142, 2228, 20, 1141, 2228, true, 20 );
277 }
278 
280 {
281  INFO_PRINT << "POL datafile multi walk tests:\n";
282  // now we have a small house in the hills
283  test_walk( 2016, 1332, 0, 2016, 1331, true, 4 );
284  test_walk( 2016, 1331, 4, 2017, 1331, true, 4 );
285  test_walk( 2017, 1331, 4, 2018, 1331, true, 0 );
286  test_walk( 2018, 1331, 0, 2018, 1330, false, 0 ); // walk N, blocked
287  test_walk( 2018, 1331, 0, 2019, 1331, true, 0 );
288  test_walk( 2019, 1331, 0, 2019, 1330, false, 0 );
289  test_walk( 2019, 1331, 0, 2020, 1331, true, 0 );
290  test_walk( 2020, 1331, 0, 2020, 1330, true, 0 );
291  test_walk( 2016, 1331, 4, 2016, 1330, true, 7 );
292  test_walk( 2016, 1330, 7, 2015, 1330, false, 0 );
293  test_walk( 2016, 1330, 7, 2017, 1330, false, 0 );
294 
295 
296  // try walking around on a boat
297  test_walk( 1487, 1770, -2, 1487, 1769, true, -2 );
298  test_walk( 1487, 1769, -2, 1487, 1768, false, 0 ); // try to walk into the mast
299  test_walk( 1487, 1769, -2, 1486, 1769, true, -2 );
300  test_walk( 1486, 1769, -2, 1486, 1768, true, -2 );
301  // this commented out because the planks are both retracted.
302  // test_walk( 1486, 1768, -2, 1485, 1768, true, -4 ); // on the gangplank
303  test_walk( 1485, 1768, -4, 1485, 1769, false, 0 ); // try to walk into the water
304  test_walk( 1485, 1768, -4, 1485, 1767, false, 0 ); // try to walk into the water
305  test_walk( 1485, 1768, -4, 1484, 1768, true, -2 );
306  test_walk( 1487, 1765, -2, 1487, 1764, true, -2 ); // try to walk onto the hold
307 
308  // try walking around on a boat in deeper water
309  test_walk( 1497, 1781, -2, 1497, 1780, true, -2 );
310  test_walk( 1497, 1780, -2, 1497, 1779, false, 0 ); // try to walk into the mast
311  test_walk( 1497, 1780, -2, 1496, 1780, true, -2 );
312  test_walk( 1496, 1780, -2, 1496, 1779, true, -2 );
313  test_walk( 1496, 1779, -2, 1495, 1779, true, -4 ); // on the gangplank
314  test_walk( 1495, 1779, -4, 1495, 1778, false, 0 ); // try to walk into the water
315  test_walk( 1495, 1779, -4, 1495, 1780, false, 0 ); // try to walk into the water
316  test_walk( 1495, 1779, -4, 1494, 1779, false, 0 );
317 
318  // try walking on a long boat, next to its plank
319  test_walk( 1496, 1817, -2, 1495, 1817, true, -2 );
320 }
321 } // namespace Testing
322 } // namespace Pol
void multiwalk_test()
Definition: testwalk.cpp:279
bool walkheight(unsigned short x, unsigned short y, short oldz, short *newz, Multi::UMulti **pmulti, Items::Item **pwalkon, bool doors_block, Core::MOVEMODE movemode, short *gradual_boost=nullptr)
Definition: realmfunc.cpp:340
void inc_failures()
Definition: testenv.cpp:33
MOVEMODE
Definition: uconst.h:79
GameState gamestate
Definition: uvars.cpp:74
void walk_test()
Definition: testwalk.cpp:91
void inc_successes()
Definition: testenv.cpp:38
#define INFO_PRINT
Definition: logfacility.h:223
Realms::Realm * main_realm
Definition: uvars.h:162
Definition: berror.cpp:12