File: overworld_monster.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (127 lines) | stat: -rw-r--r-- 4,141 bytes parent folder | download | duplicates (2)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "ultima/ultima1/widgets/overworld_monster.h"
#include "ultima/ultima1/widgets/attack_effect.h"
#include "ultima/ultima1/core/party.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/game.h"
#include "ultima/shared/maps/map_widget.h"
#include "ultima/shared/core/utils.h"

namespace Ultima {
namespace Ultima1 {
namespace Widgets {

OverworldMonster::OverworldMonster(Shared::Game *game, Shared::Maps::MapBase *map, uint tileNum, int hitPoints,
		const Point &pt, Shared::Maps::Direction dir) : OverworldWidget(game, map, tileNum, pt, dir),
		Shared::Maps::Creature(game, map, hitPoints) {
	_monsterId = (OverworldMonsterId)((tileNum - 19) / 2);

	Ultima1Game *g = static_cast<Ultima1Game *>(game);
	_name = g->_res->OVERWORLD_MONSTER_NAMES[_monsterId];
	_attackStrength = g->_res->OVERWORLD_MONSTER_DAMAGE[_monsterId];
}

void OverworldMonster::synchronize(Common::Serializer &s) {
	OverworldWidget::synchronize(s);
	Creature::synchronize(s);
	s.syncAsUint16LE(_monsterId);
	s.syncAsUint16LE(_attackStrength);
}

uint OverworldMonster::attackDistance() const {
	Point playerPos = _map->_playerWidget->_position;
	Point diff = playerPos - _position;

	int threshold = _tileNum == 23 || _tileNum == 25 || _tileNum == 31 || _tileNum == 47 ? 3 : 1;
	int distance = MIN(diff.x, diff.y);
	return distance <= threshold ? threshold : 0;
}

void OverworldMonster::movement() {
	// TODO
}

void OverworldMonster::attackParty() {
	Ultima1Game *game = dynamic_cast<Ultima1Game *>(_game);
	assert(game);
	Point playerPos = _map->_playerWidget->_position;
	Point diff = playerPos - _position;
	Point delta(SGN(diff.x), SGN(diff.y));
	//Point tempDiff;
	//int maxDistance = attackDistance();
	Shared::Maps::MapTile mapTile;
	//Shared::Character &c = *_game->_party;
	//uint threshold, damage;

	// Print out the monster attacking

	addInfoMsg(Common::String::format("%s %s %s", _name.c_str(), game->_res->ATTACKS, _name.c_str()), false);

	/* TODO: Refactor to use attack effects
	// Set up widget for displaying the moving hit circle
	Hit *hit = new Hit(_game, _map);
	_map->addWidget(hit);

	//
	int distance = 1;
	do {
		tempDiff.x = delta.x * distance + diff.x;
		tempDiff.y = delta.y * distance + diff.y;
		hit->_position = playerPos + tempDiff;
		_game->sleep(50);

	} while (++distance <= maxDistance && mapTile._tileId != 3 && (tempDiff.x != 0 || tempDiff.y != 0));


	// Calculate damage threshold
	threshold = (c._stamina / 2) + (c._equippedArmour * 8) + 56;

	if (tempDiff.x == 0 && tempDiff.y == 0 && _game->getRandomNumber(1, 255) > threshold) {
		hit->_position = playerPos;
		_game->playFX(2);

		damage = _game->getRandomNumber(1, _attackStrength * 2 + 1);
		c._hitPoints -= damage;

		if (_name.size() > 8) {
			addInfoMsg("");
			addInfoMsg(Common::String::format("%s %2d %s", game->_res->HIT, damage, game->_res->DAMAGE));
		} else {
			addInfoMsg(Common::String::format(" %s", game->_res->HIT));
			addInfoMsg(Common::String::format("%2d %s", damage, game->_res->DAMAGE));
		}
	} else {
		if (_name.size() > 8)
			addInfoMsg("", true);
		else
			addInfoMsg(" ", false);
		addInfoMsg(game->_res->MISSED);
	}

	_map->removeWidget(hit);
	*/
}

} // End of namespace Widgets
} // End of namespace Ultima1
} // End of namespace Ultima