File: adv_chk.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 (146 lines) | stat: -rw-r--r-- 4,059 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* 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 "m4/adv_r/adv_chk.h"
#include "m4/core/errors.h"
#include "m4/core/imath.h"
#include "m4/fileio/sys_file.h"
#include "m4/vars.h"

namespace M4 {

static HotSpotRec *read_hotspots(SysFile *fpdef, HotSpotRec *h, int32 num) {
	int32 str_len;
	char s[MAX_FILENAME_SIZE];
	int32 x1, x2, y1, y2;
	HotSpotRec *head = nullptr;

	for (int32 i = 0; i < num; i++) {
		x1 = fpdef->readSint32LE();
		y1 = fpdef->readSint32LE();
		x2 = fpdef->readSint32LE();
		y2 = fpdef->readSint32LE();

		h = hotspot_new(x1, y1, x2, y2);
		if (!head)
			head = h;
		else
			head = hotspot_add(head, h, false);

		h->feet_x = fpdef->readSint32LE();
		h->feet_y = fpdef->readSint32LE();
		h->facing = fpdef->readSByte();
		h->active = fpdef->readSByte();
		h->cursor_number = fpdef->readSByte();
		h->syntax = fpdef->readSByte();
		h->vocabID = fpdef->readSint32LE();
		h->verbID = fpdef->readSint32LE();

		// -------

		str_len = fpdef->readSint32LE();

		if (str_len) {
			if (!fpdef->read((byte *)s, str_len))
				error_show(FL, 0, "Could not read vocab");
			hotspot_newVocab(h, s);
		}

		str_len = fpdef->readSint32LE();

		if (str_len) {
			if (!fpdef->read((byte *)s, str_len))
				error_show(FL, 0, "Could not read verb");
			hotspot_newVerb(h, s);
		}

		str_len = fpdef->readSint32LE();

		if (str_len) {
			if (!fpdef->read((byte *)s, str_len))
				error_show(FL, 0, "Could not read prep");
			hotspot_newPrep(h, s);
		}

		str_len = fpdef->readSint32LE();

		if (str_len) {
			if (!fpdef->read((byte *)s, str_len))
				error_show(FL, 0, "Could not read sprite");
			hotspot_new_sprite(h, s);
		}

		h->hash = fpdef->readSint16LE();
	}

	return head;
}

static void load_def(SysFile *fpdef) {
	int32 x, y;
	char s[MAX_FILENAME_SIZE];

	fpdef->read((byte *)s, MAX_FILENAME_SIZE);
	Common::strlcpy(_G(myDef)->art_base, s, MAX_FILENAME_SIZE);

	fpdef->read((byte *)s, MAX_FILENAME_SIZE);
	Common::strlcpy(_G(myDef)->picture_base, s, MAX_FILENAME_SIZE);

	_G(myDef)->num_hotspots = fpdef->readSint32LE();
	_G(myDef)->num_parallax = fpdef->readSint32LE();
	_G(myDef)->num_props = fpdef->readSint32LE();
	_G(myDef)->front_y = fpdef->readSint32LE();
	_G(myDef)->back_y = fpdef->readSint32LE();
	_G(myDef)->front_scale = fpdef->readSint32LE();
	_G(myDef)->back_scale = fpdef->readSint32LE();

	for (int32 i = 0; i < 16; i++) {
		_G(myDef)->depth_table[i] = fpdef->readSint16LE();
	}

	_G(myDef)->numRailNodes = fpdef->readSint32LE();

	for (int32 i = 0; i < _G(myDef)->numRailNodes; i++) {
		x = fpdef->readSint32LE();
		y = fpdef->readSint32LE();

		if (AddRailNode(x, y, nullptr, true) < 0)
			error_show(FL, 0, "more than %d (defn. in intrrail.h) nodes", MAXRAILNODES);
	}

	_G(myDef)->hotspots = read_hotspots(fpdef, nullptr, _G(myDef)->num_hotspots);
	_G(myDef)->parallax = read_hotspots(fpdef, nullptr, _G(myDef)->num_parallax);
	_G(myDef)->props = read_hotspots(fpdef, nullptr, _G(myDef)->num_props);
}

int db_def_chk_read(int16 room_code, SceneDef *rdef) {
	_G(myDef) = rdef;

	_G(def_filename) = Common::String::format("%03d.chk", room_code);
	SysFile fpdef(_G(def_filename), BINARY);

	load_def(&fpdef);
	fpdef.close();

	return -1; // everything happy code
}

} // End of namespace M4