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
24 #include "ultima/ultima8/world/egg.h"
25 #include "ultima/ultima8/ultima8.h"
26 #include "ultima/ultima8/world/get_object.h"
27 #include "ultima/ultima8/usecode/uc_machine.h"
28
29 namespace Ultima {
30 namespace Ultima8 {
31
DEFINE_RUNTIME_CLASSTYPE_CODE(Egg)32 DEFINE_RUNTIME_CLASSTYPE_CODE(Egg)
33
34 Egg::Egg() : _hatched(false) {
35 }
36
37
~Egg()38 Egg::~Egg() {
39 }
40
hatch()41 uint16 Egg::hatch() {
42 if (_hatched) return 0;
43 _hatched = true;
44 return callUsecodeEvent_hatch();
45 }
46
unhatch()47 uint16 Egg::unhatch() {
48 if (GAME_IS_CRUSADER) {
49 if (!_hatched) return 0;
50 _hatched = false;
51 return callUsecodeEvent_unhatch();
52 }
53 return 0;
54 }
55
dumpInfo() const56 void Egg::dumpInfo() const {
57 Item::dumpInfo();
58 pout << "range: " << getXRange() << "," << getYRange()
59 << ", hatched=" << _hatched << Std::endl;
60 }
61
leaveFastArea()62 void Egg::leaveFastArea() {
63 reset();
64 Item::leaveFastArea();
65 }
66
saveData(Common::WriteStream * ws)67 void Egg::saveData(Common::WriteStream *ws) {
68 Item::saveData(ws);
69
70 uint8 h = _hatched ? 1 : 0;
71 ws->writeByte(h);
72 }
73
loadData(Common::ReadStream * rs,uint32 version)74 bool Egg::loadData(Common::ReadStream *rs, uint32 version) {
75 if (!Item::loadData(rs, version)) return false;
76
77 _hatched = (rs->readByte() != 0);
78
79 return true;
80 }
81
I_getEggXRange(const uint8 * args,unsigned int)82 uint32 Egg::I_getEggXRange(const uint8 *args, unsigned int /*argsize*/) {
83 ARG_EGG_FROM_PTR(egg);
84 if (!egg) return 0;
85
86 return static_cast<uint32>(egg->getXRange());
87 }
88
I_getEggYRange(const uint8 * args,unsigned int)89 uint32 Egg::I_getEggYRange(const uint8 *args, unsigned int /*argsize*/) {
90 ARG_EGG_FROM_PTR(egg);
91 if (!egg) return 0;
92
93 return static_cast<uint32>(egg->getYRange());
94 }
95
I_setEggXRange(const uint8 * args,unsigned int)96 uint32 Egg::I_setEggXRange(const uint8 *args, unsigned int /*argsize*/) {
97 ARG_EGG_FROM_PTR(egg);
98 ARG_UINT16(xr);
99 if (!egg) return 0;
100
101 egg->setXRange(xr);
102 return 0;
103 }
104
I_setEggYRange(const uint8 * args,unsigned int)105 uint32 Egg::I_setEggYRange(const uint8 *args, unsigned int /*argsize*/) {
106 ARG_EGG_FROM_PTR(egg);
107 ARG_UINT16(yr);
108 if (!egg) return 0;
109
110 egg->setYRange(yr);
111 return 0;
112 }
113
I_getEggId(const uint8 * args,unsigned int)114 uint32 Egg::I_getEggId(const uint8 *args, unsigned int /*argsize*/) {
115 ARG_EGG_FROM_PTR(egg);
116 if (!egg) return 0;
117
118 return egg->getMapNum();
119 }
120
I_setEggId(const uint8 * args,unsigned int)121 uint32 Egg::I_setEggId(const uint8 *args, unsigned int /*argsize*/) {
122 ARG_EGG_FROM_PTR(egg);
123 ARG_UINT16(eggid);
124 if (!egg) return 0;
125
126 egg->setMapNum(eggid);
127
128 return 0;
129 }
130
131 } // End of namespace Ultima8
132 } // End of namespace Ultima
133