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/ultima4/controllers/camp_controller.h"
24 #include "ultima/ultima4/core/utils.h"
25 #include "ultima/ultima4/filesys/savegame.h"
26 #include "ultima/ultima4/map/mapmgr.h"
27 #include "ultima/ultima4/ultima4.h"
28
29 namespace Ultima {
30 namespace Ultima4 {
31
CampController()32 CampController::CampController() {
33 MapId id;
34
35 /* setup camp (possible, but not for-sure combat situation */
36 if (g_context->_location->_context & CTX_DUNGEON)
37 id = MAP_CAMP_DNG;
38 else
39 id = MAP_CAMP_CON;
40
41 _map = getCombatMap(mapMgr->get(id));
42 g_game->setMap(_map, true, nullptr, this);
43 }
44
init(Creature * m)45 void CampController::init(Creature *m) {
46 CombatController::init(m);
47 _camping = true;
48 }
49
begin()50 void CampController::begin() {
51 // make sure everyone's asleep
52 for (int i = 0; i < g_context->_party->size(); i++)
53 g_context->_party->member(i)->putToSleep();
54
55 CombatController::begin();
56
57 g_music->camp();
58
59 g_screen->screenMessage("Resting...\n");
60 g_screen->screenDisableCursor();
61
62 EventHandler::wait_msecs(settings._campTime * 1000);
63
64 g_screen->screenEnableCursor();
65
66 /* Is the party ambushed during their rest? */
67 if (settings._campingAlwaysCombat || (xu4_random(8) == 0)) {
68 const Creature *m = creatureMgr->randomAmbushing();
69
70 g_music->playMapMusic();
71 g_screen->screenMessage("Ambushed!\n");
72
73 /* create an ambushing creature (so it leaves a chest) */
74 setCreature(g_context->_location->_prev->_map->addCreature(m, g_context->_location->_prev->_coords));
75
76 /* fill the creature table with creatures and place them */
77 fillCreatureTable(m);
78 placeCreatures();
79
80 /* creatures go first! */
81 finishTurn();
82 } else {
83 /* Wake everyone up! */
84 for (int i = 0; i < g_context->_party->size(); i++)
85 g_context->_party->member(i)->wakeUp();
86
87 /* Make sure we've waited long enough for camping to be effective */
88 bool healed = false;
89 if (((g_ultima->_saveGame->_moves / CAMP_HEAL_INTERVAL) >= 0x10000) ||
90 (((g_ultima->_saveGame->_moves / CAMP_HEAL_INTERVAL) & 0xffff) != g_ultima->_saveGame->_lastCamp))
91 healed = heal();
92
93 g_screen->screenMessage(healed ? "Party Healed!\n" : "No effect.\n");
94 g_ultima->_saveGame->_lastCamp = (g_ultima->_saveGame->_moves / CAMP_HEAL_INTERVAL) & 0xffff;
95
96 eventHandler->popController();
97 g_game->exitToParentMap();
98 g_music->fadeIn(CAMP_FADE_IN_TIME, true);
99 delete this;
100 }
101 }
102
end(bool adjustKarma)103 void CampController::end(bool adjustKarma) {
104 // wake everyone up!
105 for (int i = 0; i < g_context->_party->size(); i++)
106 g_context->_party->member(i)->wakeUp();
107 CombatController::end(adjustKarma);
108 }
109
heal()110 bool CampController::heal() {
111 // restore each party member to max mp, and restore some hp
112 bool healed = false;
113 for (int i = 0; i < g_context->_party->size(); i++) {
114 PartyMember *m = g_context->_party->member(i);
115 m->setMp(m->getMaxMp());
116 if ((m->getHp() < m->getMaxHp()) && m->heal(HT_CAMPHEAL))
117 healed = true;
118 }
119
120 return healed;
121 }
122
123 } // End of namespace Ultima4
124 } // End of namespace Ultima
125