1 #include "game_character.h"
2 #include "game_player.h"
3 #include "game_event.h"
4 #include "game_vehicle.h"
5 #include "doctest.h"
6 #include <climits>
7 
8 static_assert(Game_Character::GetMaxStopCountForStep(1) == 256, "StopCountBroken");
9 static_assert(Game_Character::GetMaxStopCountForStep(2) == 128, "StopCountBroken");
10 static_assert(Game_Character::GetMaxStopCountForStep(3) == 64, "StopCountBroken");
11 static_assert(Game_Character::GetMaxStopCountForStep(4) == 32, "StopCountBroken");
12 static_assert(Game_Character::GetMaxStopCountForStep(5) == 16, "StopCountBroken");
13 static_assert(Game_Character::GetMaxStopCountForStep(6) == 8, "StopCountBroken");
14 static_assert(Game_Character::GetMaxStopCountForStep(7) == 4, "StopCountBroken");
15 static_assert(Game_Character::GetMaxStopCountForStep(8) == 0, "StopCountBroken");
16 
17 static_assert(Game_Character::GetMaxStopCountForTurn(1) == 128, "StopCountBroken");
18 static_assert(Game_Character::GetMaxStopCountForTurn(2) == 64, "StopCountBroken");
19 static_assert(Game_Character::GetMaxStopCountForTurn(3) == 32, "StopCountBroken");
20 static_assert(Game_Character::GetMaxStopCountForTurn(4) == 16, "StopCountBroken");
21 static_assert(Game_Character::GetMaxStopCountForTurn(5) == 8, "StopCountBroken");
22 static_assert(Game_Character::GetMaxStopCountForTurn(6) == 4, "StopCountBroken");
23 static_assert(Game_Character::GetMaxStopCountForTurn(7) == 2, "StopCountBroken");
24 static_assert(Game_Character::GetMaxStopCountForTurn(8) == 0, "StopCountBroken");
25 
26 static_assert(Game_Character::GetMaxStopCountForWait(1) == 148, "StopCountBroken");
27 static_assert(Game_Character::GetMaxStopCountForWait(2) == 84, "StopCountBroken");
28 static_assert(Game_Character::GetMaxStopCountForWait(3) == 52, "StopCountBroken");
29 static_assert(Game_Character::GetMaxStopCountForWait(4) == 36, "StopCountBroken");
30 static_assert(Game_Character::GetMaxStopCountForWait(5) == 28, "StopCountBroken");
31 static_assert(Game_Character::GetMaxStopCountForWait(6) == 24, "StopCountBroken");
32 static_assert(Game_Character::GetMaxStopCountForWait(7) == 22, "StopCountBroken");
33 static_assert(Game_Character::GetMaxStopCountForWait(8) == 20, "StopCountBroken");
34 
35 // FIXME: Diagonals??
36 static_assert(Game_Character::GetDirection90DegreeLeft(Game_Character::Up) == Game_Character::Left, "90DegLeftBroken");
37 static_assert(Game_Character::GetDirection90DegreeLeft(Game_Character::Left) == Game_Character::Down, "90DegLeftBroken");
38 static_assert(Game_Character::GetDirection90DegreeLeft(Game_Character::Down) == Game_Character::Right, "90DegLeftBroken");
39 static_assert(Game_Character::GetDirection90DegreeLeft(Game_Character::Right) == Game_Character::Up, "90DegLeftBroken");
40 
41 // FIXME: Diagonals??
42 static_assert(Game_Character::GetDirection90DegreeRight(Game_Character::Up) == Game_Character::Right, "90DegRightBroken");
43 static_assert(Game_Character::GetDirection90DegreeRight(Game_Character::Right) == Game_Character::Down, "90DegRightBroken");
44 static_assert(Game_Character::GetDirection90DegreeRight(Game_Character::Down) == Game_Character::Left, "90DegRightBroken");
45 static_assert(Game_Character::GetDirection90DegreeRight(Game_Character::Left) == Game_Character::Up, "90DegRightBroken");
46 
47 // FIXME: Diagonals??
48 static_assert(Game_Character::GetDirection180Degree(Game_Character::Up) == Game_Character::Down, "180DegBroken");
49 static_assert(Game_Character::GetDirection180Degree(Game_Character::Right) == Game_Character::Left, "180DegBroken");
50 static_assert(Game_Character::GetDirection180Degree(Game_Character::Down) == Game_Character::Up, "180DegBroken");
51 static_assert(Game_Character::GetDirection180Degree(Game_Character::Left) == Game_Character::Right, "180DegBroken");
52 
53 
54 static_assert(Game_Character::GetDxFromDirection(Game_Character::Up) == 0, "DxBroken");
55 static_assert(Game_Character::GetDxFromDirection(Game_Character::Left) == -1, "DxBroken");
56 static_assert(Game_Character::GetDxFromDirection(Game_Character::Down) == 0, "DxBroken");
57 static_assert(Game_Character::GetDxFromDirection(Game_Character::Right) == 1, "DxBroken");
58 static_assert(Game_Character::GetDxFromDirection(Game_Character::UpRight) == 1, "DxBroken");
59 static_assert(Game_Character::GetDxFromDirection(Game_Character::DownRight) == 1, "DxBroken");
60 static_assert(Game_Character::GetDxFromDirection(Game_Character::DownLeft) == -1, "DxBroken");
61 static_assert(Game_Character::GetDxFromDirection(Game_Character::UpLeft) == -1, "DxBroken");
62 
63 static_assert(Game_Character::GetDyFromDirection(Game_Character::Up) == -1, "DyBroken");
64 static_assert(Game_Character::GetDyFromDirection(Game_Character::Left) == 0, "DyBroken");
65 static_assert(Game_Character::GetDyFromDirection(Game_Character::Down) == 1, "DyBroken");
66 static_assert(Game_Character::GetDyFromDirection(Game_Character::Right) == 0, "DyBroken");
67 static_assert(Game_Character::GetDyFromDirection(Game_Character::UpRight) == -1, "DyBroken");
68 static_assert(Game_Character::GetDyFromDirection(Game_Character::DownRight) == 1, "DyBroken");
69 static_assert(Game_Character::GetDyFromDirection(Game_Character::DownLeft) == 1, "DyBroken");
70 static_assert(Game_Character::GetDyFromDirection(Game_Character::UpLeft) == -1, "DyBroken");
71 
72 static_assert(!Game_Character::IsDirectionFixedAnimationType(lcf::rpg::EventPage::AnimType_non_continuous), "DirFixedBroken");
73 static_assert(!Game_Character::IsDirectionFixedAnimationType(lcf::rpg::EventPage::AnimType_continuous), "DirFixedBroken");
74 static_assert(Game_Character::IsDirectionFixedAnimationType(lcf::rpg::EventPage::AnimType_fixed_non_continuous), "DirFixedBroken");
75 static_assert(Game_Character::IsDirectionFixedAnimationType(lcf::rpg::EventPage::AnimType_fixed_continuous), "DirFixedBroken");
76 static_assert(Game_Character::IsDirectionFixedAnimationType(lcf::rpg::EventPage::AnimType_fixed_graphic), "DirFixedBroken");
77 static_assert(!Game_Character::IsDirectionFixedAnimationType(lcf::rpg::EventPage::AnimType_spin), "DirFixedBroken");
78 static_assert(!Game_Character::IsDirectionFixedAnimationType(lcf::rpg::EventPage::AnimType_step_frame_fix), "DirFixedBroken");
79 
80 #if 0
81 
82 	/** @return the direction we would need to face the hero. */
83 	int GetDirectionToHero();
84 
85 	/** @return the direction we would need to face away from hero. */
86 	int GetDirectionAwayHero();
87 
88 	virtual int GetScreenZ(bool apply_shift = false) const;
89 
90 	int DistanceXfromPlayer() const;
91 	int DistanceYfromPlayer() const;
92 #endif
93 
94 TEST_SUITE_BEGIN("Game_Character");
95 
testInit(Game_Character & ch,int max_stop_count=0)96 static void testInit(Game_Character& ch, int max_stop_count = 0) {
97 	REQUIRE_EQ(ch.GetX(), 0);
98 	REQUIRE_EQ(ch.GetY(), 0);
99 	REQUIRE_EQ(ch.GetMapId(), 0);
100 	REQUIRE(!ch.IsFacingLocked());
101 	REQUIRE(!ch.IsOverlapForbidden());
102 
103 	// FIXME: Check move route
104 	REQUIRE_EQ(ch.GetMoveRouteIndex(), 0);
105 	REQUIRE(!ch.IsMoveRouteOverwritten());
106 	REQUIRE(!ch.IsMoveRouteRepeated());
107 	REQUIRE_EQ(ch.GetSpriteName(), "");
108 	REQUIRE(ch.HasTileSprite());
109 	REQUIRE_EQ(ch.GetSpriteIndex(), 0);
110 	REQUIRE_EQ(ch.GetAnimFrame(), 1);
111 	REQUIRE(!ch.IsAnimPaused());
112 	REQUIRE_EQ(ch.GetFlashColor(), Color());
113 	REQUIRE_EQ(ch.GetFlashLevel(), 0.0);
114 	REQUIRE_EQ(ch.GetFlashTimeLeft(), 0);
115 	REQUIRE_EQ(ch.GetStopCount(), 0);
116 	REQUIRE_EQ(ch.GetMaxStopCount(), max_stop_count);
117 	REQUIRE_EQ(ch.IsStopCountActive(), (max_stop_count != 0));
118 	REQUIRE_EQ(ch.GetAnimCount(), 0);
119 	REQUIRE(!ch.IsMoving());
120 	REQUIRE(!ch.IsJumping());
121 	REQUIRE_EQ(ch.GetBeginJumpX(), 0);
122 	REQUIRE_EQ(ch.GetBeginJumpY(), 0);
123 	REQUIRE(!ch.IsFlying());
124 	REQUIRE(!ch.IsProcessed());
125 	REQUIRE(!ch.IsPaused());
126 	REQUIRE(ch.IsActive());
127 	REQUIRE(ch.IsStopping());
128 	REQUIRE_EQ(ch.GetJumpHeight(), 0);
129 	REQUIRE_EQ(ch.GetTileId(), 0);
130 	REQUIRE_EQ(ch.GetSpriteX(), 0);
131 	REQUIRE_EQ(ch.GetSpriteY(), 0);
132 	REQUIRE_EQ(ch.GetRemainingStep(), 0);
133 	REQUIRE_EQ(ch.GetAnimationType(), Game_Character::AnimType(0));
134 	// FIXME: Map
135 	//REQUIRE(ch.IsInPosition(0, 0));
136 
137 	REQUIRE_EQ(ch.GetOpacity(), 255);
138 	REQUIRE_EQ(ch.GetTransparency(), 0);
139 	// FIXME: MAP
140 	//REQUIRE(ch.IsVisible());
141 	REQUIRE(!ch.IsSpriteHidden());
142 	REQUIRE(ch.IsAnimated());
143 	REQUIRE(!ch.IsContinuous());
144 	REQUIRE(!ch.IsSpinning());
145 	// FIXME: MAP
146 	// REQUIRE_EQ(ch.GetBushDepth(), 0);
147 
148 }
149 
testInitVehicle(Game_Vehicle::Type vt)150 static void testInitVehicle(Game_Vehicle::Type vt) {
151 	Game_Vehicle ch(vt);
152 
153 	testInit(ch);
154 
155 	REQUIRE_EQ(ch.GetDirection(), 3);
156 	REQUIRE_EQ(ch.GetFacing(), 3);
157 	if (vt == Game_Vehicle::Airship) {
158 		REQUIRE_EQ(ch.GetMoveSpeed(), 5);
159 	} else {
160 		REQUIRE_EQ(ch.GetMoveSpeed(), 4);
161 	}
162 	REQUIRE(!ch.GetThrough());
163 	REQUIRE_EQ(ch.GetLayer(), 1);
164 	REQUIRE_EQ(ch.GetMoveFrequency(), 2);
165 
166 	REQUIRE_EQ(ch.GetVehicleType(), vt);
167 	REQUIRE(!ch.IsAscending());
168 	REQUIRE(!ch.IsDescending());
169 	REQUIRE(!ch.IsAscendingOrDescending());
170 	REQUIRE_EQ(ch.GetAltitude(), 0);
171 	// FIXME: Player
172 	//REQUIRE(!ch.IsInUse());
173 	//REQUIRE(!ch.IsAboard());
174 	// FIXME: Map
175 	//REQUIRE(!ch.CanLand());
176 	REQUIRE_EQ(ch.GetOrigSpriteName(), "");
177 	REQUIRE_EQ(ch.GetOrigSpriteIndex(), 0);
178 
179 	REQUIRE_EQ(ch.GetMoveRoute(), lcf::rpg::MoveRoute());
180 }
181 
182 TEST_CASE("InitVehicle") {
183 	testInitVehicle(Game_Vehicle::Boat);
184 	testInitVehicle(Game_Vehicle::Ship);
185 	testInitVehicle(Game_Vehicle::Airship);
186 }
187 
188 TEST_CASE("InitPlayer") {
189 	Game_Player ch;
190 
191 	testInit(ch);
192 
193 	REQUIRE_EQ(ch.GetDirection(), 2);
194 	REQUIRE_EQ(ch.GetFacing(), 2);
195 	REQUIRE_EQ(ch.GetMoveSpeed(), 4);
196 	REQUIRE(!ch.GetThrough());
197 	REQUIRE_EQ(ch.GetVehicleType(), Game_Vehicle::None);
198 	REQUIRE_EQ(ch.GetLayer(), 1);
199 	REQUIRE_EQ(ch.GetMoveFrequency(), 2);
200 
201 	REQUIRE(!ch.IsPendingTeleport());
202 	REQUIRE(!ch.InVehicle());
203 	REQUIRE(!ch.InAirship());
204 	REQUIRE(!ch.IsAboard());
205 	REQUIRE(!ch.IsBoardingOrUnboarding());
206 	REQUIRE_EQ(ch.GetVehicle(), nullptr);
207 
208 	REQUIRE(!ch.IsEncounterCalling());
209 	REQUIRE_EQ(ch.GetEncounterSteps(), 0);
210 	REQUIRE(!ch.IsMenuCalling());
211 
212 	REQUIRE(!ch.IsPanActive());
213 	REQUIRE(!ch.IsPanLocked());
214 	REQUIRE_EQ(ch.GetPanX(), lcf::rpg::SavePartyLocation::kPanXDefault);
215 	REQUIRE_EQ(ch.GetPanY(), lcf::rpg::SavePartyLocation::kPanYDefault);
216 	REQUIRE_EQ(ch.GetTargetPanX(), lcf::rpg::SavePartyLocation::kPanXDefault);
217 	REQUIRE_EQ(ch.GetTargetPanY(), lcf::rpg::SavePartyLocation::kPanYDefault);
218 	REQUIRE_EQ(ch.GetPanWait(), 0);
219 
220 	REQUIRE(ch.IsMapCompatibleWithSave(0));
221 	REQUIRE(ch.IsDatabaseCompatibleWithSave(0));
222 }
223 
224 TEST_CASE("InitEventNoPage") {
225 	lcf::rpg::Event event;
226 	Game_Event ch(0, &event);
227 
228 	testInit(ch);
229 
230 	REQUIRE_EQ(ch.GetDirection(), 2);
231 	REQUIRE_EQ(ch.GetFacing(), 2);
232 	REQUIRE_EQ(ch.GetMoveSpeed(), 4);
233 	REQUIRE(ch.GetThrough());
234 	REQUIRE_EQ(ch.GetLayer(), 1);
235 	REQUIRE_EQ(ch.GetMoveFrequency(), 2);
236 
237 	REQUIRE_EQ(ch.GetId(), 0);
238 	REQUIRE_EQ(ch.GetName(), "");
239 
240 	REQUIRE(!ch.IsWaitingForegroundExecution());
241 	REQUIRE(!ch.WasStartedByDecisionKey());
242 	REQUIRE_EQ(ch.GetTrigger(), -1);
243 	REQUIRE_EQ(ch.GetOriginalMoveRouteIndex(), 0);
244 	REQUIRE_EQ(ch.GetPage(1), nullptr);
245 	REQUIRE_EQ(ch.GetActivePage(), nullptr);
246 }
247 
248 TEST_CASE("InitEventDefaultPage") {
249 	lcf::rpg::Event event;
250 	event.pages.push_back({});
251 	event.pages.back().move_type = lcf::rpg::EventPage::MoveType_stationary;
252 	Game_Event ch(0, &event);
253 
254 	testInit(ch, 64);
255 
256 	REQUIRE_EQ(ch.GetDirection(), 2);
257 	REQUIRE_EQ(ch.GetFacing(), 2);
258 	REQUIRE_EQ(ch.GetMoveSpeed(), 3);
259 	REQUIRE(!ch.GetThrough());
260 	REQUIRE_EQ(ch.GetLayer(), 0);
261 	REQUIRE_EQ(ch.GetMoveFrequency(), 3);
262 
263 	REQUIRE_EQ(ch.GetId(), 0);
264 	REQUIRE_EQ(ch.GetName(), "");
265 
266 	REQUIRE(!ch.IsWaitingForegroundExecution());
267 	REQUIRE(!ch.WasStartedByDecisionKey());
268 	REQUIRE_EQ(ch.GetTrigger(), 0);
269 	REQUIRE_EQ(ch.GetOriginalMoveRouteIndex(), 0);
270 	REQUIRE_EQ(ch.GetPage(1), event.pages.data());
271 	REQUIRE_EQ(ch.GetActivePage(), event.pages.data());
272 }
273 
testBasicSet(Game_Character & ch)274 static void testBasicSet(Game_Character& ch) {
275 	ch.SetX(55);
276 	REQUIRE_EQ(ch.GetX(), 55);
277 
278 	ch.SetY(66);
279 	REQUIRE_EQ(ch.GetY(), 66);
280 
281 	// FIXME: Remove this method.
282 	ch.SetMapId(44);
283 	REQUIRE_EQ(ch.GetMapId(), 44);
284 
285 	ch.SetDirection(Game_Character::UpLeft);
286 	REQUIRE_EQ(ch.GetDirection(), Game_Character::UpLeft);
287 
288 	ch.SetFacing(Game_Character::Up);
289 	REQUIRE_EQ(ch.GetFacing(), Game_Character::Up);
290 
291 	ch.SetFacingLocked(true);
292 	REQUIRE(ch.IsFacingLocked());
293 
294 	ch.SetLayer(2);
295 	REQUIRE_EQ(ch.GetLayer(), 2);
296 
297 	ch.SetMoveSpeed(6);
298 	REQUIRE_EQ(ch.GetMoveSpeed(), 6);
299 
300 	ch.SetMoveFrequency(7);
301 	REQUIRE_EQ(ch.GetMoveFrequency(), 7);
302 
303 	// FIXME: Test move routes
304 	// Should SetMoveRoute() and SetMoveRouteIndex() be public?
305 	ch.SetMoveRouteIndex(3);
306 	REQUIRE_EQ(ch.GetMoveRouteIndex(), 3);
307 
308 	ch.SetMoveRouteOverwritten(true);
309 	REQUIRE(ch.IsMoveRouteOverwritten());
310 
311 	ch.SetSpriteGraphic("SPRITE", 8);
312 	REQUIRE_EQ(ch.GetSpriteName(), "SPRITE");
313 	REQUIRE_EQ(ch.GetSpriteIndex(), 8);
314 	REQUIRE(!ch.HasTileSprite());
315 
316 	ch.SetAnimFrame(3);
317 	REQUIRE_EQ(ch.GetAnimFrame(), 3);
318 
319 	ch.SetAnimPaused(true);
320 	REQUIRE(ch.IsAnimPaused());
321 
322 	// FIXME: Test flashing
323 	ch.SetFlashLevel(99);
324 	REQUIRE_EQ(ch.GetFlashLevel(), 99);
325 
326 	ch.SetFlashTimeLeft(99);
327 	REQUIRE_EQ(ch.GetFlashTimeLeft(), 99);
328 
329 	ch.SetThrough(true);
330 	REQUIRE(ch.GetThrough());
331 
332 	//FIXME: Test ResetThrough
333 
334 	ch.SetAnimationType(lcf::rpg::EventPage::AnimType_step_frame_fix);
335 	REQUIRE_EQ(ch.GetAnimationType(), lcf::rpg::EventPage::AnimType_step_frame_fix);
336 
337 	ch.SetStopCount(78);
338 	REQUIRE_EQ(ch.GetStopCount(), 78);
339 
340 	ch.SetMaxStopCount(99);
341 	REQUIRE_EQ(ch.GetMaxStopCount(), 99);
342 
343 	// FIXME: Test Stop count IsStopCountActive
344 
345 	ch.SetAnimCount(78);
346 	REQUIRE_EQ(ch.GetAnimCount(), 78);
347 
348 	// FIXME: Test anim count basic increment logic
349 	// FIXME: Test anim count real
350 
351 	// FIXME: Test movement sequence
352 	ch.SetRemainingStep(889);
353 	REQUIRE_EQ(ch.GetRemainingStep(), 889);
354 
355 	ch.SetJumping(true);
356 	REQUIRE(ch.IsJumping());
357 	REQUIRE(!ch.IsMoving());
358 	REQUIRE(!ch.IsStopping());
359 
360 	ch.SetBeginJumpX(77);
361 	REQUIRE_EQ(ch.GetBeginJumpX(), 77);
362 
363 	ch.SetBeginJumpY(88);
364 	REQUIRE_EQ(ch.GetBeginJumpY(), 88);
365 
366 	ch.SetFlying(true);
367 	REQUIRE(ch.IsFlying());
368 
369 	// FIXME: Test Clamp
370 	ch.SetTransparency(3);
371 	REQUIRE_EQ(ch.GetTransparency(), 3);
372 
373 	ch.SetProcessed(true);
374 	REQUIRE(ch.IsProcessed());
375 
376 	ch.SetPaused(true);
377 	REQUIRE(ch.IsPaused());
378 
379 	ch.SetActive(false);
380 	REQUIRE(!ch.IsActive());
381 
382 	ch.SetSpriteHidden(true);
383 	REQUIRE(ch.IsSpriteHidden());
384 
385 	// FIXME: Visible test
386 }
387 
testBasicSetVehicle(Game_Vehicle::Type vt)388 static void testBasicSetVehicle(Game_Vehicle::Type vt) {
389 	Game_Vehicle ch(vt);
390 
391 	testBasicSet(ch);
392 
393 	ch.SetOrigSpriteGraphic("VSPRITE", 9);
394 	REQUIRE_EQ(ch.GetOrigSpriteName(), "VSPRITE");
395 	REQUIRE_EQ(ch.GetOrigSpriteIndex(), 9);
396 }
397 
398 TEST_CASE("BasicSetVehicle") {
399 	testBasicSetVehicle(Game_Vehicle::Boat);
400 	testBasicSetVehicle(Game_Vehicle::Ship);
401 	testBasicSetVehicle(Game_Vehicle::Airship);
402 }
403 
404 TEST_CASE("BasicSetPlayer") {
405 	Game_Player ch;
406 
407 	testBasicSet(ch);
408 
409 	ch.SetMenuCalling(true);
410 	REQUIRE(ch.IsMenuCalling());
411 
412 	ch.SetEncounterCalling(true);
413 	REQUIRE(ch.IsEncounterCalling());
414 
415 	ch.SetEncounterSteps(100);
416 	REQUIRE_EQ(ch.GetEncounterSteps(), 100);
417 
418 	// FIMXE: Test Panning
419 
420 	// FIXME: Test save counts
421 }
422 
423 TEST_CASE("BasicSetEvent") {
424 	lcf::rpg::Event event;
425 	Game_Event ch(0, &event);
426 
427 	testBasicSet(ch);
428 
429 	ch.SetOriginalMoveRouteIndex(100);
430 	REQUIRE_EQ(ch.GetOriginalMoveRouteIndex(), 100);
431 }
432 
433 TEST_CASE("TransparencyAndOpacity") {
434 	Game_Player ch;
435 
436 	ch.SetTransparency(-1);
437 	REQUIRE_EQ(ch.GetTransparency(), 0);
438 	REQUIRE_EQ(ch.GetOpacity(), 255);
439 	REQUIRE(ch.IsVisible());
440 
441 	ch.SetTransparency(0);
442 	REQUIRE_EQ(ch.GetTransparency(), 0);
443 	REQUIRE_EQ(ch.GetOpacity(), 255);
444 	REQUIRE(ch.IsVisible());
445 
446 	ch.SetTransparency(1);
447 	REQUIRE_EQ(ch.GetTransparency(), 1);
448 	REQUIRE_EQ(ch.GetOpacity(), 223);
449 	REQUIRE(ch.IsVisible());
450 
451 	ch.SetTransparency(2);
452 	REQUIRE_EQ(ch.GetTransparency(), 2);
453 	REQUIRE_EQ(ch.GetOpacity(), 191);
454 	REQUIRE(ch.IsVisible());
455 
456 	ch.SetTransparency(3);
457 	REQUIRE_EQ(ch.GetTransparency(), 3);
458 	REQUIRE_EQ(ch.GetOpacity(), 159);
459 	REQUIRE(ch.IsVisible());
460 
461 	ch.SetTransparency(4);
462 	REQUIRE_EQ(ch.GetTransparency(), 4);
463 	REQUIRE_EQ(ch.GetOpacity(), 127);
464 	REQUIRE(ch.IsVisible());
465 
466 	ch.SetTransparency(5);
467 	REQUIRE_EQ(ch.GetTransparency(), 5);
468 	REQUIRE_EQ(ch.GetOpacity(), 95);
469 	REQUIRE(ch.IsVisible());
470 
471 	ch.SetTransparency(6);
472 	REQUIRE_EQ(ch.GetTransparency(), 6);
473 	REQUIRE_EQ(ch.GetOpacity(), 63);
474 	REQUIRE(ch.IsVisible());
475 
476 	ch.SetTransparency(7);
477 	REQUIRE_EQ(ch.GetOpacity(), 31);
478 	REQUIRE_EQ(ch.GetTransparency(), 7);
479 	REQUIRE(ch.IsVisible());
480 
481 	ch.SetTransparency(8);
482 	REQUIRE_EQ(ch.GetTransparency(), 7);
483 	REQUIRE_EQ(ch.GetOpacity(), 31);
484 	REQUIRE(ch.IsVisible());
485 
486 	ch.SetTransparency(9);
487 	REQUIRE_EQ(ch.GetTransparency(), 7);
488 	REQUIRE_EQ(ch.GetOpacity(), 31);
489 	REQUIRE(ch.IsVisible());
490 }
491 
492 TEST_CASE("TileVsCharset") {
493 	Game_Player ch;
494 
495 	REQUIRE(ch.HasTileSprite());
496 	REQUIRE_EQ(ch.GetTileId(), 0);
497 	REQUIRE_EQ(ch.GetSpriteName(), "");
498 	REQUIRE_EQ(ch.GetSpriteIndex(), 0);
499 
500 	ch.SetSpriteGraphic("x", 2);
501 	REQUIRE(!ch.HasTileSprite());
502 	REQUIRE_EQ(ch.GetTileId(), 0);
503 	REQUIRE_EQ(ch.GetSpriteName(), "x");
504 	REQUIRE_EQ(ch.GetSpriteIndex(), 2);
505 
506 	ch.SetSpriteGraphic("", 3);
507 	REQUIRE(ch.HasTileSprite());
508 	REQUIRE_EQ(ch.GetTileId(), 3);
509 	REQUIRE_EQ(ch.GetSpriteName(), "");
510 	REQUIRE_EQ(ch.GetSpriteIndex(), 3);
511 }
512 
513 TEST_CASE("Animated") {
514 	Game_Player ch;
515 
516 	REQUIRE(!ch.IsAnimPaused());
517 
518 	ch.SetAnimationType(lcf::rpg::EventPage::AnimType_non_continuous);
519 	REQUIRE(ch.IsAnimated());
520 	REQUIRE(!ch.IsContinuous());
521 	REQUIRE(!ch.IsSpinning());
522 
523 	ch.SetAnimationType(lcf::rpg::EventPage::AnimType_continuous);
524 	REQUIRE(ch.IsAnimated());
525 	REQUIRE(ch.IsContinuous());
526 	REQUIRE(!ch.IsSpinning());
527 
528 	ch.SetAnimationType(lcf::rpg::EventPage::AnimType_fixed_non_continuous);
529 	REQUIRE(ch.IsAnimated());
530 	REQUIRE(!ch.IsContinuous());
531 	REQUIRE(!ch.IsSpinning());
532 
533 	ch.SetAnimationType(lcf::rpg::EventPage::AnimType_fixed_continuous);
534 	REQUIRE(ch.IsAnimated());
535 	REQUIRE(ch.IsContinuous());
536 	REQUIRE(!ch.IsSpinning());
537 
538 	ch.SetAnimationType(lcf::rpg::EventPage::AnimType_fixed_graphic);
539 	REQUIRE(!ch.IsAnimated());
540 	REQUIRE(!ch.IsContinuous());
541 	REQUIRE(!ch.IsSpinning());
542 
543 	ch.SetAnimationType(lcf::rpg::EventPage::AnimType_spin);
544 	REQUIRE(ch.IsAnimated());
545 	REQUIRE(!ch.IsContinuous());
546 	REQUIRE(ch.IsSpinning());
547 
548 	ch.SetAnimationType(lcf::rpg::EventPage::AnimType_step_frame_fix);
549 	REQUIRE(!ch.IsAnimated());
550 	REQUIRE(!ch.IsContinuous());
551 	REQUIRE(!ch.IsSpinning());
552 
553 	ch.SetAnimPaused(true);
554 	REQUIRE(ch.IsAnimPaused());
555 	for (int i = 0; i <= static_cast<int>(lcf::rpg::EventPage::AnimType_step_frame_fix); ++i) {
556 		ch.SetAnimationType(static_cast<lcf::rpg::EventPage::AnimType>(i));
557 		REQUIRE(!ch.IsAnimated());
558 	}
559 }
560 
561 
testVisible(Game_Character & ch)562 static void testVisible(Game_Character& ch) {
563 	REQUIRE(ch.IsVisible());
564 
565 	ch.SetActive(false);
566 	REQUIRE(!ch.IsVisible());
567 	ch.SetActive(true);
568 	REQUIRE(ch.IsVisible());
569 
570 	ch.SetSpriteHidden(true);
571 	REQUIRE(!ch.IsVisible());
572 	ch.SetSpriteHidden(false);
573 	REQUIRE(ch.IsVisible());
574 }
575 
576 TEST_CASE("VisiblePlayer") {
577 	Game_Player ch;
578 
579 	testVisible(ch);
580 
581 	// FIXME: Test aboard
582 }
583 
584 TEST_CASE("VisibleVehicle") {
585 	Game_Vehicle ch(Game_Vehicle::Boat);
586 
587 	// FIXME: Requires map loaded
588 	// testVisible(ch);
589 
590 	// FIXME: Test other map
591 }
592 
593 TEST_CASE("VisibleEvent") {
594 	lcf::rpg::Event event;
595 	Game_Event ch(0, &event);
596 
597 	// FIXME: Test pages
598 	//testVisible(ch);
599 
600 }
601 
602 TEST_CASE("LockFacingVsAnimType") {
603 	for (int i = 0; i <= static_cast<int>(lcf::rpg::EventPage::AnimType_step_frame_fix); ++i) {
604 		auto at = static_cast<lcf::rpg::EventPage::AnimType>(i);
605 
606 		Game_Player ch;
607 		ch.SetAnimationType(at);
608 
609 		if (Game_Character::IsDirectionFixedAnimationType(at)) {
610 			REQUIRE(ch.IsFacingLocked());
611 			ch.SetFacingLocked(false);
612 			REQUIRE(ch.IsFacingLocked());
613 			ch.SetFacingLocked(true);
614 			REQUIRE(ch.IsFacingLocked());
615 		} else {
616 			REQUIRE(!ch.IsFacingLocked());
617 			ch.SetFacingLocked(true);
618 			REQUIRE(ch.IsFacingLocked());
619 			ch.SetFacingLocked(false);
620 			REQUIRE(!ch.IsFacingLocked());
621 		}
622 	}
623 }
624 
625 TEST_SUITE_END();
626