2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru 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.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
29 int Dialog::indialogue;
30 int Dialog::whichdialogue;
31 bool Dialog::directing;
32 float Dialog::dialoguetime;
33 std::vector<Dialog> Dialog::dialogs;
35 void Dialog::loadDialogs(FILE* tfile)
38 funpackf(tfile, "Bi", &numdialogues);
39 for (int k = 0; k < numdialogues; k++) {
40 dialogs.push_back(Dialog(tfile));
44 Dialog::Dialog(FILE* tfile) : gonethrough(0)
47 funpackf(tfile, "Bi", &numdialogscenes);
48 funpackf(tfile, "Bi", &type);
49 for (int l = 0; l < 10; l++) {
50 funpackf(tfile, "Bf Bf Bf", &participantlocation[l].x, &participantlocation[l].y, &participantlocation[l].z);
51 funpackf(tfile, "Bf", &participantyaw[l]);
53 for (int l = 0; l < numdialogscenes; l++) {
54 scenes.push_back(DialogScene(tfile));
58 std::string funpackf_string(FILE* tfile, int maxlength)
61 funpackf(tfile, "Bi", &templength);
62 if ((templength > maxlength) || (templength <= 0)) {
63 templength = maxlength;
66 char* text = new char[maxlength];
67 for (m = 0; m < templength; m++) {
68 funpackf(tfile, "Bb", &text[m]);
73 std::string result(text);
78 void fpackf_string(FILE* tfile, std::string text)
80 fpackf(tfile, "Bi", text.size());
81 for (int m = 0; m < text.size(); m++) {
82 fpackf(tfile, "Bb", text[m]);
88 DialogScene::DialogScene(FILE* tfile)
90 funpackf(tfile, "Bi", &location);
91 funpackf(tfile, "Bf", &color[0]);
92 funpackf(tfile, "Bf", &color[1]);
93 funpackf(tfile, "Bf", &color[2]);
94 funpackf(tfile, "Bi", &sound);
96 text = funpackf_string(tfile, 128);
97 name = funpackf_string(tfile, 64);
99 funpackf(tfile, "Bf Bf Bf", &camera.x, &camera.y, &camera.z);
100 funpackf(tfile, "Bi", &participantfocus);
101 funpackf(tfile, "Bi", &participantaction);
103 for (int m = 0; m < 10; m++)
104 funpackf(tfile, "Bf Bf Bf", &participantfacing[m].x, &participantfacing[m].y, &participantfacing[m].z);
106 funpackf(tfile, "Bf Bf", &camerayaw, &camerapitch);
109 /* Load dialog from txt file, used by console */
110 Dialog::Dialog(int type, std::string filename) : type(type)
112 ifstream ipstream(ConvertFileName(filename.c_str()));
113 ipstream.ignore(256, ':');
115 ipstream >> numscenes;
116 for (int i = 0; i < numscenes; i++) {
117 scenes.push_back(DialogScene(ipstream));
118 for (unsigned j = 0; j < Person::players.size(); j++) {
119 scenes.back().participantfacing[j] = Person::players[j]->facing;
125 DialogScene::DialogScene(ifstream &ipstream)
127 ipstream.ignore(256, ':');
128 ipstream.ignore(256, ':');
129 ipstream.ignore(256, ' ');
130 ipstream >> location;
131 ipstream.ignore(256, ':');
132 ipstream >> color[0];
133 ipstream >> color[1];
134 ipstream >> color[2];
135 ipstream.ignore(256, ':');
136 getline(ipstream, name);
137 ipstream.ignore(256, ':');
138 ipstream.ignore(256, ' ');
139 getline(ipstream, text);
140 for (int j = 0; j < 128; j++) {
144 ipstream.ignore(256, ':');
148 void Dialog::tick(int id)
150 unsigned playerId = type % 10;
151 bool special = (type > 9);
153 if ((!hostile || (type > 40) && (type < 50)) &&
154 (playerId < Person::players.size()) &&
156 ((gonethrough == 0) || !special) &&
157 (special || Input::isKeyPressed(Game::attackkey))) {
158 if ((distsq(&Person::players[0]->coords, &Person::players[playerId]->coords) < 6) ||
159 (Person::players[playerId]->howactive >= typedead1) ||
160 (type > 40) && (type < 50)) {
171 for (int i = 0; i < scenes.size(); i++) {
172 int playerId = scenes[i].participantfocus;
173 Person::players[playerId]->coords = participantlocation[playerId];
174 Person::players[playerId]->yaw = participantyaw[playerId];
175 Person::players[playerId]->targetyaw = participantyaw[playerId];
176 Person::players[playerId]->velocity = 0;
177 Person::players[playerId]->animTarget = Person::players[playerId]->getIdle();
178 Person::players[playerId]->frameTarget = 0;
181 Dialog::directing = false;
182 Dialog::indialogue = 0;
184 if (scenes[indialogue].sound != 0) {
185 Game::playdialoguescenesound();
189 void Dialog::saveDialogs(FILE* tfile)
191 fpackf(tfile, "Bi", dialogs.size());
193 for (int k = 0; k < dialogs.size(); k++) {
194 dialogs[k].save(tfile);
198 void Dialog::save(FILE* tfile)
200 fpackf(tfile, "Bi", scenes.size());
201 fpackf(tfile, "Bi", type);
202 for (int l = 0; l < 10; l++) {
203 fpackf(tfile, "Bf Bf Bf", participantlocation[l].x, participantlocation[l].y, participantlocation[l].z);
204 fpackf(tfile, "Bf", participantyaw[l]);
206 for (int l = 0; l < scenes.size(); l++) {
207 scenes[l].save(tfile);
211 void DialogScene::save(FILE* tfile)
213 fpackf(tfile, "Bi", location);
214 fpackf(tfile, "Bf", color[0]);
215 fpackf(tfile, "Bf", color[1]);
216 fpackf(tfile, "Bf", color[2]);
217 fpackf(tfile, "Bi", sound);
219 fpackf_string(tfile, text);
220 fpackf_string(tfile, name);
222 fpackf(tfile, "Bf Bf Bf", camera.x, camera.y, camera.z);
223 fpackf(tfile, "Bi", participantfocus);
224 fpackf(tfile, "Bi", participantaction);
226 for (int m = 0; m < 10; m++)
227 fpackf(tfile, "Bf Bf Bf", participantfacing[m].x, participantfacing[m].y, participantfacing[m].z);
229 fpackf(tfile, "Bf Bf", camerayaw, camerapitch);