1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "ultima/ultima1/widgets/princess.h"
24 #include "ultima/ultima1/maps/map_city_castle.h"
25 #include "ultima/shared/core/utils.h"
26 
27 namespace Ultima {
28 namespace Ultima1 {
29 namespace Widgets {
30 
movement()31 void Princess::movement() {
32 	if (!areGuardsHostile()) {
33 		// Until guards turn hostile, the princesses exhibit standard wench behaviour
34 		Wench::movement();
35 	} else {
36 		// When the guards are hostile, keep the princess moving towards the player
37 		Point playerPos = _map->_playerWidget->_position;
38 		Point delta(SGN(_position.x - playerPos.x), SGN(_position.y - playerPos.y));
39 		bool moved = false;
40 
41 		// Randomly choose whether to give precedence to a X or Y move
42 		if (_game->getRandomNumber(1, 100) >= 50) {
43 			// Delta X comes first
44 			if (delta.x != 0)
45 				moved = canMoveTo(Point(delta.x, 0));
46 			if (!moved && delta.y != 0)
47 				moved = canMoveTo(Point(0, delta.y));
48 		} else {
49 			// Delta Y comes first
50 			if (delta.y != 0)
51 				moved = canMoveTo(Point(0, delta.y));
52 			if (!moved && delta.x != 0)
53 				moved = canMoveTo(Point(delta.x, 0));
54 		}
55 
56 		if (moved)
57 			_game->playFX(4);
58 	}
59 }
60 
subtractHitPoints(uint amount)61 bool Princess::subtractHitPoints(uint amount) {
62 	bool result = Person::subtractHitPoints(amount);
63 	if (result)
64 		// Princess is dead, you monster. So you can no longer be credited with freeing them
65 		static_cast<Maps::MapCastle *>(_map)->_freeingPrincess = false;
66 
67 	return result;
68 }
69 
70 } // End of namespace Widgets
71 } // End of namespace Ultima1
72 } // End of namespace Ultima
73