From e7b76642d8998c250272a8313ad8aa7c7efff319 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Wed, 30 Nov 2016 23:44:50 +0700 Subject: [PATCH] Cleaned up dialog handling using a Dialog class The fixdialogue command will behave a tiny bit differently as it will set participantfacing value as the dialogue would. The previous behavior would crash if the number of boxes changed so I could not keep it. I kept the limitation of participants of 10 for now, does not seem like a big deal. --- CMakeLists.txt | 2 + Source/ConsoleCmds.cpp | 156 ++++--------------------- Source/Dialog.cpp | 230 ++++++++++++++++++++++++++++++++++++ Source/Dialog.h | 77 +++++++++++++ Source/Game.cpp | 23 +--- Source/Game.h | 24 ---- Source/GameDraw.cpp | 82 ++++--------- Source/GameInitDispose.cpp | 15 --- Source/GameTick.cpp | 231 +++++++++++-------------------------- Source/Person.cpp | 5 +- 10 files changed, 425 insertions(+), 420 deletions(-) create mode 100644 Source/Dialog.cpp create mode 100644 Source/Dialog.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f11cf9..c59fa3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ set(LUGARU_SRCS ${SRCDIR}/Frustum.cpp ${SRCDIR}/Account.cpp ${SRCDIR}/ConsoleCmds.cpp + ${SRCDIR}/Dialog.cpp ${SRCDIR}/Game.cpp ${SRCDIR}/GameDraw.cpp ${SRCDIR}/GameInitDispose.cpp @@ -71,6 +72,7 @@ set(LUGARU_H ${SRCDIR}/Frustum.h ${SRCDIR}/Account.h ${SRCDIR}/ConsoleCmds.h + ${SRCDIR}/Dialog.h ${SRCDIR}/Game.h ${SRCDIR}/Lights.h ${SRCDIR}/Menu.h diff --git a/Source/ConsoleCmds.cpp b/Source/ConsoleCmds.cpp index 32e9c1c..46b5938 100644 --- a/Source/ConsoleCmds.cpp +++ b/Source/ConsoleCmds.cpp @@ -20,6 +20,7 @@ along with Lugaru. If not, see . #include "ConsoleCmds.h" #include "Game.h" +#include "Dialog.h" const char *cmd_names[cmd_count] = { #define DECLARE_COMMAND(cmd) #cmd, @@ -200,48 +201,7 @@ void ch_save(const char *args) fpackf(tfile, "Bi Bi", Person::players[0]->whichskin, Person::players[0]->creature); - fpackf(tfile, "Bi", numdialogues); - - for (int k = 0; k < numdialogues; k++) { - fpackf(tfile, "Bi", numdialogueboxes[k]); - fpackf(tfile, "Bi", dialoguetype[k]); - for (int l = 0; l < 10; l++) { - fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z); - fpackf(tfile, "Bf", participantyaw[k][l]); - } - for (int l = 0; l < numdialogueboxes[k]; l++) { - fpackf(tfile, "Bi", dialogueboxlocation[k][l]); - fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]); - fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]); - fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]); - fpackf(tfile, "Bi", dialogueboxsound[k][l]); - - int templength = strlen(dialoguetext[k][l]); - fpackf(tfile, "Bi", (templength)); - for (int m = 0; m < templength; m++) { - fpackf(tfile, "Bb", dialoguetext[k][l][m]); - if (dialoguetext[k][l][m] == '\0') - break; - } - - templength = strlen(dialoguename[k][l]); - fpackf(tfile, "Bi", templength); - for (int m = 0; m < templength; m++) { - fpackf(tfile, "Bb", dialoguename[k][l][m]); - if (dialoguename[k][l][m] == '\0') - break; - } - - fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z); - fpackf(tfile, "Bi", participantfocus[k][l]); - fpackf(tfile, "Bi", participantaction[k][l]); - - for (int m = 0; m < 10; m++) - fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z); - - fpackf(tfile, "Bf Bf", dialoguecamerayaw[k][l], dialoguecamerapitch[k][l]); - } - } + Dialog::saveDialogs(tfile); for (int k = 0; k < Person::players[0]->numclothes; k++) { int templength = strlen(Person::players[0]->clothes[k]); @@ -608,111 +568,46 @@ void ch_hs(const char *args) void ch_dialogue(const char *args) { - int dlg; - char buf1[32], buf2[64]; - - sscanf(args, "%d %31s", &dlg, buf1); - snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1); - - dialoguetype[numdialogues] = dlg; - - memset(dialoguetext[numdialogues], 0, sizeof(dialoguetext[numdialogues])); - memset(dialoguename[numdialogues], 0, sizeof(dialoguename[numdialogues])); - - ifstream ipstream(ConvertFileName(buf2)); - ipstream.ignore(256, ':'); - ipstream >> numdialogueboxes[numdialogues]; - for (int i = 0; i < numdialogueboxes[numdialogues]; i++) { - ipstream.ignore(256, ':'); - ipstream.ignore(256, ':'); - ipstream.ignore(256, ' '); - ipstream >> dialogueboxlocation[numdialogues][i]; - ipstream.ignore(256, ':'); - ipstream >> dialogueboxcolor[numdialogues][i][0]; - ipstream >> dialogueboxcolor[numdialogues][i][1]; - ipstream >> dialogueboxcolor[numdialogues][i][2]; - ipstream.ignore(256, ':'); - ipstream.getline(dialoguename[numdialogues][i], 64); - ipstream.ignore(256, ':'); - ipstream.ignore(256, ' '); - ipstream.getline(dialoguetext[numdialogues][i], 128); - for (int j = 0; j < 128; j++) { - if (dialoguetext[numdialogues][i][j] == '\\') - dialoguetext[numdialogues][i][j] = '\n'; - } - ipstream.ignore(256, ':'); - ipstream >> dialogueboxsound[numdialogues][i]; - } + int type; + char buf1[32], filename[64]; - for (int i = 0; i < numdialogueboxes[numdialogues]; i++) { - for (unsigned j = 0; j < Person::players.size(); j++) { - participantfacing[numdialogues][i][j] = Person::players[j]->facing; - } - } - ipstream.close(); + sscanf(args, "%d %31s", &type, buf1); + snprintf(filename, 63, ":Data:Dialogues:%s.txt", buf1); - directing = 1; - indialogue = 0; - whichdialogue = numdialogues; + Dialog::dialogs.push_back(Dialog(type, filename)); - numdialogues++; + Dialog::directing = true; + Dialog::indialogue = 0; + Dialog::whichdialogue = Dialog::dialogs.size(); } void ch_fixdialogue(const char *args) { - char buf1[32], buf2[64]; + char buf1[32], filename[64]; int whichdi; sscanf(args, "%d %31s", &whichdi, buf1); - snprintf(buf2, 63, ":Data:Dialogues:%s.txt", buf1); - - memset(dialoguetext[whichdi], 0, sizeof(dialoguetext[whichdi])); - memset(dialoguename[whichdi], 0, sizeof(dialoguename[whichdi])); - - ifstream ipstream(ConvertFileName(buf2)); - ipstream.ignore(256, ':'); - ipstream >> numdialogueboxes[whichdi]; - for (int i = 0; i < numdialogueboxes[whichdi]; i++) { - ipstream.ignore(256, ':'); - ipstream.ignore(256, ':'); - ipstream.ignore(256, ' '); - ipstream >> dialogueboxlocation[whichdi][i]; - ipstream.ignore(256, ':'); - ipstream >> dialogueboxcolor[whichdi][i][0]; - ipstream >> dialogueboxcolor[whichdi][i][1]; - ipstream >> dialogueboxcolor[whichdi][i][2]; - ipstream.ignore(256, ':'); - ipstream.getline(dialoguename[whichdi][i], 64); - ipstream.ignore(256, ':'); - ipstream.ignore(256, ' '); - ipstream.getline(dialoguetext[whichdi][i], 128); - for (int j = 0; j < 128; j++) { - if (dialoguetext[whichdi][i][j] == '\\') - dialoguetext[whichdi][i][j] = '\n'; - } - ipstream.ignore(256, ':'); - ipstream >> dialogueboxsound[whichdi][i]; - } + snprintf(filename, 63, ":Data:Dialogues:%s.txt", buf1); - ipstream.close(); + Dialog::dialogs[whichdi] = Dialog(Dialog::dialogs[whichdi].type, filename); } void ch_fixtype(const char *args) { int dlg; sscanf(args, "%d", &dlg); - dialoguetype[0] = dlg; + Dialog::dialogs[0].type = dlg; } void ch_fixrotation(const char *args) { - participantyaw[whichdialogue][participantfocus[whichdialogue][indialogue]] = Person::players[participantfocus[whichdialogue][indialogue]]->yaw; + int playerId = Dialog::currentBox().participantfocus; + Dialog::currentDialog().participantyaw[playerId] = Person::players[playerId]->yaw; } void ch_ddialogue(const char *args) { - if (numdialogues) - numdialogues--; + Dialog::dialogs.pop_back(); } void ch_dhs(const char *args) @@ -778,24 +673,13 @@ void ch_play(const char *args) { int dlg; sscanf(args, "%d", &dlg); - whichdialogue = dlg; + Dialog::whichdialogue = dlg; - if (whichdialogue >= numdialogues) + if (Dialog::whichdialogue >= Dialog::dialogs.size()) { return; - - for (int i = 0; i < numdialogueboxes[whichdialogue]; i++) { - Person::players[participantfocus[whichdialogue][i]]->coords = participantlocation[whichdialogue][participantfocus[whichdialogue][i]]; - Person::players[participantfocus[whichdialogue][i]]->yaw = participantyaw[whichdialogue][participantfocus[whichdialogue][i]]; - Person::players[participantfocus[whichdialogue][i]]->targetyaw = participantyaw[whichdialogue][participantfocus[whichdialogue][i]]; - Person::players[participantfocus[whichdialogue][i]]->velocity = 0; - Person::players[participantfocus[whichdialogue][i]]->animTarget = Person::players[participantfocus[whichdialogue][i]]->getIdle(); - Person::players[participantfocus[whichdialogue][i]]->frameTarget = 0; } - directing = 0; - indialogue = 0; - - playdialogueboxsound(); + Dialog::currentDialog().play(); } void ch_mapkilleveryone(const char *args) diff --git a/Source/Dialog.cpp b/Source/Dialog.cpp new file mode 100644 index 0000000..1f7698d --- /dev/null +++ b/Source/Dialog.cpp @@ -0,0 +1,230 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru 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 2 of the License, or +(at your option) any later version. + +Lugaru 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 Lugaru. If not, see . +*/ + +#include "Dialog.h" +#include "Person.h" +#include "Input.h" +#include "Game.h" +#include "binio.h" + +extern int hostile; + +int Dialog::indialogue; +int Dialog::whichdialogue; +bool Dialog::directing; +float Dialog::dialoguetime; +std::vector Dialog::dialogs; + +void Dialog::loadDialogs(FILE* tfile) +{ + int numdialogues; + funpackf(tfile, "Bi", &numdialogues); + for (int k = 0; k < numdialogues; k++) { + dialogs.push_back(Dialog(tfile)); + } +} + +Dialog::Dialog(FILE* tfile) : gonethrough(0) +{ + int numdialogboxes; + funpackf(tfile, "Bi", &numdialogboxes); + funpackf(tfile, "Bi", &type); + for (int l = 0; l < 10; l++) { + funpackf(tfile, "Bf Bf Bf", &participantlocation[l].x, &participantlocation[l].y, &participantlocation[l].z); + funpackf(tfile, "Bf", &participantyaw[l]); + } + for (int l = 0; l < numdialogboxes; l++) { + boxes.push_back(DialogBox(tfile)); + } +} + +std::string funpackf_string(FILE* tfile, int maxlength) +{ + int templength; + funpackf(tfile, "Bi", &templength); + if ((templength > maxlength) || (templength <= 0)) { + templength = maxlength; + } + int m; + char* text = new char[maxlength]; + for (m = 0; m < templength; m++) { + funpackf(tfile, "Bb", &text[m]); + if (text[m] == '\0') + break; + } + text[m] = 0; + std::string result(text); + delete[] text; + return result; +} + +void fpackf_string(FILE* tfile, std::string text) +{ + fpackf(tfile, "Bi", text.size()); + for (int m = 0; m < text.size(); m++) { + fpackf(tfile, "Bb", text[m]); + if (text[m] == '\0') + break; + } +} + +DialogBox::DialogBox(FILE* tfile) +{ + funpackf(tfile, "Bi", &location); + funpackf(tfile, "Bf", &color[0]); + funpackf(tfile, "Bf", &color[1]); + funpackf(tfile, "Bf", &color[2]); + funpackf(tfile, "Bi", &sound); + + text = funpackf_string(tfile, 128); + name = funpackf_string(tfile, 64); + + funpackf(tfile, "Bf Bf Bf", &camera.x, &camera.y, &camera.z); + funpackf(tfile, "Bi", &participantfocus); + funpackf(tfile, "Bi", &participantaction); + + for (int m = 0; m < 10; m++) + funpackf(tfile, "Bf Bf Bf", &participantfacing[m].x, &participantfacing[m].y, &participantfacing[m].z); + + funpackf(tfile, "Bf Bf", &camerayaw, &camerapitch); +} + +/* Load dialog from txt file, used by console */ +Dialog::Dialog(int type, std::string filename) : type(type) +{ + ifstream ipstream(ConvertFileName(filename.c_str())); + ipstream.ignore(256, ':'); + int numboxes; + ipstream >> numboxes; + for (int i = 0; i < numboxes; i++) { + boxes.push_back(DialogBox(ipstream)); + for (unsigned j = 0; j < Person::players.size(); j++) { + boxes.back().participantfacing[j] = Person::players[j]->facing; + } + } + ipstream.close(); +} + +DialogBox::DialogBox(ifstream &ipstream) +{ + ipstream.ignore(256, ':'); + ipstream.ignore(256, ':'); + ipstream.ignore(256, ' '); + ipstream >> location; + ipstream.ignore(256, ':'); + ipstream >> color[0]; + ipstream >> color[1]; + ipstream >> color[2]; + ipstream.ignore(256, ':'); + getline(ipstream, name); + ipstream.ignore(256, ':'); + ipstream.ignore(256, ' '); + getline(ipstream, text); + for (int j = 0; j < 128; j++) { + if (text[j] == '\\') + text[j] = '\n'; + } + ipstream.ignore(256, ':'); + ipstream >> sound; +} + +void Dialog::tick(int id) +{ + unsigned playerId = type % 10; + bool special = (type > 9); + + if ((!hostile || (type > 40) && (type < 50)) && + (playerId < Person::players.size()) && + (playerId > 0) && + ((gonethrough == 0) || !special) && + (special || Input::isKeyPressed(Game::attackkey))) { + if ((distsq(&Person::players[0]->coords, &Person::players[playerId]->coords) < 6) || + (Person::players[playerId]->howactive >= typedead1) || + (type > 40) && (type < 50)) { + whichdialogue = id; + play(); + dialoguetime = 0; + gonethrough++; + } + } +} + +void Dialog::play() +{ + for (int i = 0; i < boxes.size(); i++) { + int playerId = boxes[i].participantfocus; + Person::players[playerId]->coords = participantlocation[playerId]; + Person::players[playerId]->yaw = participantyaw[playerId]; + Person::players[playerId]->targetyaw = participantyaw[playerId]; + Person::players[playerId]->velocity = 0; + Person::players[playerId]->animTarget = Person::players[playerId]->getIdle(); + Person::players[playerId]->frameTarget = 0; + } + + Dialog::directing = false; + Dialog::indialogue = 0; + + if (boxes[indialogue].sound != 0) { + Game::playdialogueboxsound(); + } +} + +void Dialog::saveDialogs(FILE* tfile) +{ + fpackf(tfile, "Bi", dialogs.size()); + + for (int k = 0; k < dialogs.size(); k++) { + dialogs[k].save(tfile); + } +} + +void Dialog::save(FILE* tfile) +{ + fpackf(tfile, "Bi", boxes.size()); + fpackf(tfile, "Bi", type); + for (int l = 0; l < 10; l++) { + fpackf(tfile, "Bf Bf Bf", participantlocation[l].x, participantlocation[l].y, participantlocation[l].z); + fpackf(tfile, "Bf", participantyaw[l]); + } + for (int l = 0; l < boxes.size(); l++) { + boxes[l].save(tfile); + } +} + +void DialogBox::save(FILE* tfile) +{ + fpackf(tfile, "Bi", location); + fpackf(tfile, "Bf", color[0]); + fpackf(tfile, "Bf", color[1]); + fpackf(tfile, "Bf", color[2]); + fpackf(tfile, "Bi", sound); + + fpackf_string(tfile, text); + fpackf_string(tfile, name); + + fpackf(tfile, "Bf Bf Bf", camera.x, camera.y, camera.z); + fpackf(tfile, "Bi", participantfocus); + fpackf(tfile, "Bi", participantaction); + + for (int m = 0; m < 10; m++) + fpackf(tfile, "Bf Bf Bf", participantfacing[m].x, participantfacing[m].y, participantfacing[m].z); + + fpackf(tfile, "Bf Bf", camerayaw, camerapitch); +} diff --git a/Source/Dialog.h b/Source/Dialog.h new file mode 100644 index 0000000..96186d3 --- /dev/null +++ b/Source/Dialog.h @@ -0,0 +1,77 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) + +This file is part of Lugaru. + +Lugaru 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 2 of the License, or +(at your option) any later version. + +Lugaru 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 Lugaru. If not, see . +*/ + +#ifndef _DIALOG_H_ +#define _DIALOG_H_ + +#include "stdio.h" +#include "Quaternions.h" +#include + +class DialogBox +{ +public: + DialogBox(FILE* tfile); + DialogBox(ifstream &ipstream); + void save(FILE* tfile); + + int location; + float color[3]; + int sound; + std::string text; + std::string name; + XYZ camera; + float camerayaw; + float camerapitch; + int participantfocus; + int participantaction; + XYZ participantfacing[10]; +}; + +class Dialog +{ +public: + Dialog(FILE* tfile); + Dialog(int type, std::string filename); + void tick(int id); + void play(); + void save(FILE* tfile); + + int type; + int gonethrough; + std::vector boxes; + XYZ participantlocation[10]; + float participantyaw[10]; + + static void loadDialogs(FILE*); + static void saveDialogs(FILE*); + + static bool inDialog() { return (indialogue != -1); } + static Dialog& currentDialog() { return dialogs[whichdialogue]; } + static DialogBox& currentBox() { return currentDialog().boxes[indialogue]; } + + static int indialogue; + static int whichdialogue; + static bool directing; + static float dialoguetime; + static std::vector dialogs; +}; + +#endif /*_DIALOG_H_*/ diff --git a/Source/Game.cpp b/Source/Game.cpp index 5b816b5..7efff10 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -21,31 +21,10 @@ along with Lugaru. If not, see . #include "Game.h" #include "openal_wrapper.h" #include "SDL_thread.h" +#include "Dialog.h" extern int mainmenu; -int numdialogues; -int numdialogueboxes[max_dialogues]; -int dialoguetype[max_dialogues]; -int dialogueboxlocation[max_dialogues][max_dialoguelength]; -float dialogueboxcolor[max_dialogues][max_dialoguelength][3]; -int dialogueboxsound[max_dialogues][max_dialoguelength]; -char dialoguetext[max_dialogues][max_dialoguelength][128]; -char dialoguename[max_dialogues][max_dialoguelength][64]; -XYZ dialoguecamera[max_dialogues][max_dialoguelength]; -XYZ participantlocation[max_dialogues][10]; -int participantfocus[max_dialogues][max_dialoguelength]; -int participantaction[max_dialogues][max_dialoguelength]; -float participantyaw[max_dialogues][10]; -XYZ participantfacing[max_dialogues][max_dialoguelength][10]; -float dialoguecamerayaw[max_dialogues][max_dialoguelength]; -float dialoguecamerapitch[max_dialogues][max_dialoguelength]; -int indialogue; -int whichdialogue; -int directing; -float dialoguetime; -int dialoguegonethrough[20]; - const char *pathtypenames[] = {"keepwalking", "pause"}; const char *editortypenames[] = { "active", "sitting", "sitting wall", "sleeping", diff --git a/Source/Game.h b/Source/Game.h index c531c02..7369204 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -193,30 +193,6 @@ extern "C" { #define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } } //#define STUBBED(x) -extern int numdialogues; -const int max_dialogues = 20; -const int max_dialoguelength = 20; -extern int numdialogueboxes[max_dialogues]; -extern int dialoguetype[max_dialogues]; -extern int dialogueboxlocation[max_dialogues][max_dialoguelength]; -extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3]; -extern int dialogueboxsound[max_dialogues][max_dialoguelength]; -extern char dialoguetext[max_dialogues][max_dialoguelength][128]; -extern char dialoguename[max_dialogues][max_dialoguelength][64]; -extern XYZ dialoguecamera[max_dialogues][max_dialoguelength]; -extern XYZ participantlocation[max_dialogues][10]; -extern int participantfocus[max_dialogues][max_dialoguelength]; -extern int participantaction[max_dialogues][max_dialoguelength]; -extern float participantyaw[max_dialogues][10]; -extern XYZ participantfacing[max_dialogues][max_dialoguelength][10]; -extern float dialoguecamerayaw[max_dialogues][max_dialoguelength]; -extern float dialoguecamerapitch[max_dialogues][max_dialoguelength]; -extern int indialogue; -extern int whichdialogue; -extern int directing; -extern float dialoguetime; -extern int dialoguegonethrough[20]; - enum maptypes { mapkilleveryone, mapgosomewhere, mapkillsomeone, mapkillmost // These two are unused diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index ae3c743..a37611b 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -23,6 +23,7 @@ along with Lugaru. If not, see . #include "Input.h" #include "Awards.h" #include "Menu.h" +#include "Dialog.h" extern XYZ viewer; extern int environment; @@ -565,7 +566,7 @@ int Game::DrawGLScene(StereoSide side) glColor4f(.5, .5, .5, 1); if (!console) { if (!tutoriallevel) - if (bonus > 0 && bonustime < 1 && !winfreeze && indialogue == -1/*bonustime<4*/) { + if (bonus > 0 && bonustime < 1 && !winfreeze && !Dialog::inDialog()) { const char *bonus_name; if (bonus < bonus_count) bonus_name = bonus_names[bonus]; @@ -938,48 +939,15 @@ int Game::DrawGLScene(StereoSide side) done = 1; i++; } - } else if (hotspottype[closest] >= 20 && dialoguegonethrough[hotspottype[closest] - 20] == 0) { - whichdialogue = hotspottype[closest] - 20; - for (int j = 0; j < numdialogueboxes[whichdialogue]; j++) { - Person::players[participantfocus[whichdialogue][j]]->coords = participantlocation[whichdialogue][participantfocus[whichdialogue][j]]; - Person::players[participantfocus[whichdialogue][j]]->yaw = participantyaw[whichdialogue][participantfocus[whichdialogue][j]]; - Person::players[participantfocus[whichdialogue][j]]->targetyaw = participantyaw[whichdialogue][participantfocus[whichdialogue][j]]; - Person::players[participantfocus[whichdialogue][j]]->velocity = 0; - Person::players[participantfocus[whichdialogue][j]]->animTarget = Person::players[participantfocus[whichdialogue][j]]->getIdle(); - Person::players[participantfocus[whichdialogue][j]]->frameTarget = 0; - } - directing = 0; - indialogue = 0; - dialoguegonethrough[whichdialogue]++; - if (dialogueboxsound[whichdialogue][indialogue] != 0) { - int whichsoundplay; - if (dialogueboxsound[whichdialogue][indialogue] == 1) whichsoundplay = rabbitchitter; - if (dialogueboxsound[whichdialogue][indialogue] == 2) whichsoundplay = rabbitchitter2; - if (dialogueboxsound[whichdialogue][indialogue] == 3) whichsoundplay = rabbitpainsound; - if (dialogueboxsound[whichdialogue][indialogue] == 4) whichsoundplay = rabbitpain1sound; - if (dialogueboxsound[whichdialogue][indialogue] == 5) whichsoundplay = rabbitattacksound; - if (dialogueboxsound[whichdialogue][indialogue] == 6) whichsoundplay = rabbitattack2sound; - if (dialogueboxsound[whichdialogue][indialogue] == 7) whichsoundplay = rabbitattack3sound; - if (dialogueboxsound[whichdialogue][indialogue] == 8) whichsoundplay = rabbitattack4sound; - if (dialogueboxsound[whichdialogue][indialogue] == 9) whichsoundplay = growlsound; - if (dialogueboxsound[whichdialogue][indialogue] == 10) whichsoundplay = growl2sound; - if (dialogueboxsound[whichdialogue][indialogue] == 11) whichsoundplay = snarlsound; - if (dialogueboxsound[whichdialogue][indialogue] == 12) whichsoundplay = snarl2sound; - if (dialogueboxsound[whichdialogue][indialogue] == 13) whichsoundplay = barksound; - if (dialogueboxsound[whichdialogue][indialogue] == 14) whichsoundplay = bark2sound; - if (dialogueboxsound[whichdialogue][indialogue] == 15) whichsoundplay = bark3sound; - if (dialogueboxsound[whichdialogue][indialogue] == 16) whichsoundplay = barkgrowlsound; - if (dialogueboxsound[whichdialogue][indialogue] == -1) whichsoundplay = fireendsound; - if (dialogueboxsound[whichdialogue][indialogue] == -2) whichsoundplay = firestartsound; - if (dialogueboxsound[whichdialogue][indialogue] == -3) whichsoundplay = consolesuccesssound; - if (dialogueboxsound[whichdialogue][indialogue] == -4) whichsoundplay = consolefailsound; - emit_sound_at(whichsoundplay, Person::players[participantfocus[whichdialogue][indialogue]]->coords); - } + } else if ((hotspottype[closest] >= 20) && (Dialog::dialogs[hotspottype[closest] - 20].gonethrough == 0)) { + Dialog::whichdialogue = hotspottype[closest] - 20; + Dialog::currentDialog().play(); + Dialog::currentDialog().gonethrough++; } } } - if (indialogue != -1 && !mainmenu) { + if (Dialog::inDialog() && !mainmenu) { glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); @@ -992,13 +960,13 @@ int Game::DrawGLScene(StereoSide side) glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - if (dialogueboxlocation[whichdialogue][indialogue] == 1) + if (Dialog::currentBox().location == 1) glTranslatef(0, screenheight * 3 / 4, 0); glScalef(screenwidth, screenheight / 4, 1); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); - glColor4f(dialogueboxcolor[whichdialogue][indialogue][0], dialogueboxcolor[whichdialogue][indialogue][1], dialogueboxcolor[whichdialogue][indialogue][2], 0.7); + glColor4f(Dialog::currentBox().color[0], Dialog::currentBox().color[1], Dialog::currentBox().color[2], 0.7); glBegin(GL_QUADS); glVertex3f(0, 0, 0.0f); glVertex3f(1, 0, 0.0f); @@ -1021,32 +989,28 @@ int Game::DrawGLScene(StereoSide side) float starty; startx = screenwidth * 1 / 5; - if (dialogueboxlocation[whichdialogue][indialogue] == 1) + if (Dialog::currentBox().location == 1) starty = screenheight / 16 + screenheight * 4 / 5; - if (dialogueboxlocation[whichdialogue][indialogue] == 2) + if (Dialog::currentBox().location == 2) starty = screenheight * 1 / 5 - screenheight / 16; char tempname[264]; - bool goodchar; int tempnum = 0; for (int i = 0; i < 264; i++) { tempname[i] = '\0'; } - for (int i = 0; i < (int)strlen(dialoguename[whichdialogue][indialogue]); i++) { - tempname[tempnum] = dialoguename[whichdialogue][indialogue][i]; - goodchar = 1; - if (dialoguename[whichdialogue][indialogue][i] == '#' || dialoguename[whichdialogue][indialogue][i] == '\0') - goodchar = 0; - if (goodchar) - tempnum++; - else + for (int i = 0; i < Dialog::currentBox().name.size(); i++) { + tempname[tempnum] = Dialog::currentBox().name[i]; + if (tempname[tempnum] == '#' || tempname[tempnum] == '\0') tempname[tempnum] = '\0'; + else + tempnum++; } sprintf (string, "%s: ", tempname); - if (dialogueboxcolor[whichdialogue][indialogue][0] + dialogueboxcolor[whichdialogue][indialogue][1] + dialogueboxcolor[whichdialogue][indialogue][2] < 1.5) { + if (Dialog::currentBox().color[0] + Dialog::currentBox().color[1] + Dialog::currentBox().color[2] < 1.5) { glColor4f(0, 0, 0, tutorialopac); text->glPrintOutline(startx - 2 * 7.6 * strlen(string)*screenwidth / 1024 - 4, starty - 4, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight); glColor4f(0.7, 0.7, 0.7, tutorialopac); @@ -1057,9 +1021,9 @@ int Game::DrawGLScene(StereoSide side) } tempnum = 0; - for (int i = 0; i < (int)strlen(dialoguetext[whichdialogue][indialogue]) + 1; i++) { - tempname[tempnum] = dialoguetext[whichdialogue][indialogue][i]; - if (dialoguetext[whichdialogue][indialogue][i] != '#') + for (int i = 0; i < Dialog::currentBox().text.size() + 1; i++) { + tempname[tempnum] = Dialog::currentBox().text[i]; + if (Dialog::currentBox().text[i] != '#') tempnum++; } @@ -1071,7 +1035,7 @@ int Game::DrawGLScene(StereoSide side) int i = 0; while (!done) { if (string[i] == '\n' || string[i] > 'z' || string[i] < ' ' || string[i] == '\0') { - if (dialogueboxcolor[whichdialogue][indialogue][0] + dialogueboxcolor[whichdialogue][indialogue][1] + dialogueboxcolor[whichdialogue][indialogue][2] < 1.5) { + if (Dialog::currentBox().color[0] + Dialog::currentBox().color[1] + Dialog::currentBox().color[2] < 1.5) { glColor4f(0, 0, 0, tutorialopac); text->glPrintOutline(startx/*-7.6*(i-lastline)*screenwidth/1024*/ - 4, starty - 4 - 20 * screenwidth / 1024 * line, string, 1, 1.5 * 1.25 * screenwidth / 1024, screenwidth, screenheight, lastline, i); glColor4f(1, 1, 1, tutorialopac); @@ -1091,7 +1055,7 @@ int Game::DrawGLScene(StereoSide side) } } - if (!tutoriallevel && !winfreeze && indialogue == -1 && !mainmenu) { + if (!tutoriallevel && !winfreeze && !Dialog::inDialog() && !mainmenu) { if (campaign) { if (scoreadded) sprintf (string, "Score: %d", (int)accountactive->getCampaignScore()); @@ -1403,7 +1367,7 @@ int Game::DrawGLScene(StereoSide side) } } - if (difficulty < 2 && indialogue == -1) { // minimap + if (difficulty < 2 && !Dialog::inDialog()) { // minimap float mapviewdist = 20000; glDisable(GL_DEPTH_TEST); diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index 6073246..3cbed4a 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -59,21 +59,6 @@ extern int difficulty; extern float slomospeed; extern bool gamestarted; -extern int numdialogues; -extern int numdialogueboxes[20]; -extern int dialoguetype[20]; -extern int dialogueboxlocation[20][20]; -extern float dialogueboxcolor[20][20][3]; -extern int dialogueboxsound[20][20]; -extern char dialoguetext[20][20][128]; -extern char dialoguename[20][20][64]; -extern XYZ dialoguecamera[20][20]; -extern float dialoguecamerayaw[20][20]; -extern float dialoguecamerapitch[20][20]; -extern int indialogue; -extern int whichdialogue; -extern float dialoguetime; - extern float accountcampaignhighscore[10]; extern float accountcampaignfasttime[10]; extern float accountcampaignscore[10]; diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 177cfe9..c688a5f 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -42,6 +42,7 @@ along with Lugaru. If not, see . #include "Awards.h" #include "Menu.h" #include "ConsoleCmds.h" +#include "Dialog.h" #include #include @@ -302,13 +303,13 @@ inline float stepTowardf(float from, float to, float by) void Game::playdialogueboxsound() { XYZ temppos; - temppos = Person::players[participantfocus[whichdialogue][indialogue]]->coords; + temppos = Person::players[Dialog::currentBox().participantfocus]->coords; temppos = temppos - viewer; Normalise(&temppos); temppos += viewer; int sound = -1; - switch (dialogueboxsound[whichdialogue][indialogue]) { + switch (Dialog::currentBox().sound) { case -6: sound = alarmsound; break; @@ -833,12 +834,9 @@ void Game::Loadlevel(const char *name) animation[bounceidleanim].Load((char *)"Idle", middleheight, neutral); - numdialogues = 0; + Dialog::dialogs.clear(); - for (int i = 0; i < 20; i++) - dialoguegonethrough[i] = 0; - - indialogue = -1; + Dialog::indialogue = -1; cameramode = 0; damagedealt = 0; @@ -981,53 +979,7 @@ void Game::Loadlevel(const char *name) //dialogues if (mapvers >= 8) { - funpackf(tfile, "Bi", &numdialogues); - for (int k = 0; k < numdialogues; k++) { - funpackf(tfile, "Bi", &numdialogueboxes[k]); - funpackf(tfile, "Bi", &dialoguetype[k]); - for (int l = 0; l < 10; l++) { - funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z); - funpackf(tfile, "Bf", &participantyaw[k][l]); - } - for (int l = 0; l < numdialogueboxes[k]; l++) { - funpackf(tfile, "Bi", &dialogueboxlocation[k][l]); - funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]); - funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]); - funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]); - funpackf(tfile, "Bi", &dialogueboxsound[k][l]); - - funpackf(tfile, "Bi", &templength); - if (templength > 128 || templength <= 0) - templength = 128; - int m; - for (m = 0; m < templength; m++) { - funpackf(tfile, "Bb", &dialoguetext[k][l][m]); - if (dialoguetext[k][l][m] == '\0') - break; - } - dialoguetext[k][l][m] = 0; - - funpackf(tfile, "Bi", &templength); - if (templength > 64 || templength <= 0) - templength = 64; - for (m = 0; m < templength; m++) { - funpackf(tfile, "Bb", &dialoguename[k][l][m]); - if (dialoguename[k][l][m] == '\0') - break; - } - dialoguename[k][l][m] = 0; - funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z); - funpackf(tfile, "Bi", &participantfocus[k][l]); - funpackf(tfile, "Bi", &participantaction[k][l]); - - for (m = 0; m < 10; m++) - funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z); - - funpackf(tfile, "Bf Bf", &dialoguecamerayaw[k][l], &dialoguecamerapitch[k][l]); - } - } - } else { - numdialogues = 0; + Dialog::loadDialogs(tfile); } for (int k = 0; k < Person::players[0]->numclothes; k++) { @@ -3046,11 +2998,11 @@ void doAttacks() } } - if (!hostile || indialogue != -1) + if (!hostile || Dialog::inDialog()) Person::players[0]->attackkeydown = 0; for (unsigned k = 0; k < Person::players.size(); k++) { - if (indialogue != -1) + if (Dialog::inDialog()) Person::players[k]->attackkeydown = 0; if (Person::players[k]->animTarget != rabbitrunninganim && Person::players[k]->animTarget != wolfrunninganim) { if (Person::players[k]->aitype != playercontrolled) @@ -3766,7 +3718,7 @@ void doPlayerCollisions() void doAI(unsigned i) { static bool connected; - if (Person::players[i]->aitype != playercontrolled && indialogue == -1) { + if (Person::players[i]->aitype != playercontrolled && !Dialog::inDialog()) { Person::players[i]->jumpclimb = 0; //disable movement in editor if (editorenabled) @@ -5558,61 +5510,15 @@ void Game::Tick() //dialogues static float talkdelay = 0; - if (indialogue != -1) + if (Dialog::inDialog()) talkdelay = 1; talkdelay -= multiplier; - if (talkdelay <= 0 && indialogue == -1 && animation[Person::players[0]->animTarget].height != highheight) - for (int i = 0; i < numdialogues; i++) { - unsigned realdialoguetype; - bool special; - /* FIXME - Seems like modulo done with ifs */ - if (dialoguetype[i] > 49) { - realdialoguetype = dialoguetype[i] - 50; - special = 1; - } else if (dialoguetype[i] > 39) { - realdialoguetype = dialoguetype[i] - 40; - special = 1; - } else if (dialoguetype[i] > 29) { - realdialoguetype = dialoguetype[i] - 30; - special = 1; - } else if (dialoguetype[i] > 19) { - realdialoguetype = dialoguetype[i] - 20; - special = 1; - } else if (dialoguetype[i] > 9) { - realdialoguetype = dialoguetype[i] - 10; - special = 1; - } else { - realdialoguetype = dialoguetype[i]; - special = 0; - } - if ((!hostile || dialoguetype[i] > 40 && dialoguetype[i] < 50) && - realdialoguetype < Person::players.size() && - realdialoguetype > 0 && - (dialoguegonethrough[i] == 0 || !special) && - (special || Input::isKeyPressed(attackkey))) { - if (distsq(&Person::players[0]->coords, &Person::players[realdialoguetype]->coords) < 6 || - Person::players[realdialoguetype]->howactive >= typedead1 || - dialoguetype[i] > 40 && dialoguetype[i] < 50) { - whichdialogue = i; - for (int j = 0; j < numdialogueboxes[whichdialogue]; j++) { - Person::players[participantfocus[whichdialogue][j]]->coords = participantlocation[whichdialogue][participantfocus[whichdialogue][j]]; - Person::players[participantfocus[whichdialogue][j]]->yaw = participantyaw[whichdialogue][participantfocus[whichdialogue][j]]; - Person::players[participantfocus[whichdialogue][j]]->targetyaw = participantyaw[whichdialogue][participantfocus[whichdialogue][j]]; - Person::players[participantfocus[whichdialogue][j]]->velocity = 0; - Person::players[participantfocus[whichdialogue][j]]->animTarget = Person::players[participantfocus[whichdialogue][j]]->getIdle(); - Person::players[participantfocus[whichdialogue][j]]->frameTarget = 0; - } - directing = 0; - indialogue = 0; - dialoguetime = 0; - dialoguegonethrough[i]++; - if (dialogueboxsound[whichdialogue][indialogue] != 0) { - playdialogueboxsound(); - } - } - } + if (talkdelay <= 0 && !Dialog::inDialog() && animation[Person::players[0]->animTarget].height != highheight) { + for (int i = 0; i < Dialog::dialogs.size(); i++) { + Dialog::dialogs[i].tick(i); } + } windvar += multiplier; smoketex += multiplier; @@ -5704,7 +5610,7 @@ void Game::Tick() static XYZ oldviewer; //control keys - if (indialogue == -1) { + if (!Dialog::inDialog()) { Person::players[0]->forwardkeydown = Input::isKeyDown(forwardkey); Person::players[0]->leftkeydown = Input::isKeyDown(leftkey); Person::players[0]->backkeydown = Input::isKeyDown(backkey); @@ -5728,9 +5634,9 @@ void Game::Tick() Person::players[0]->jumpclimb = 0; - if (indialogue != -1) { + if (Dialog::inDialog()) { cameramode = 1; - if (directing) { + if (Dialog::directing) { facing = 0; facing.z = -1; @@ -5779,30 +5685,31 @@ void Game::Tick() if (Input::isKeyPressed(SDL_SCANCODE_MINUS)) whichend = -1; if (whichend != -1) { - participantfocus[whichdialogue][indialogue] = whichend; - participantlocation[whichdialogue][whichend] = Person::players[whichend]->coords; - participantyaw[whichdialogue][whichend] = Person::players[whichend]->yaw; + Dialog::currentBox().participantfocus = whichend; + Dialog::currentDialog().participantlocation[whichend] = Person::players[whichend]->coords; + Dialog::currentDialog().participantyaw[whichend] = Person::players[whichend]->yaw; } if (whichend == -1) { - participantfocus[whichdialogue][indialogue] = -1; + Dialog::currentBox().participantfocus = -1; } - if (Person::players[participantfocus[whichdialogue][indialogue]]->dead) { - indialogue = -1; - directing = 0; + /* FIXME: potentially accessing -1 in Person::players! */ + if (Person::players[Dialog::currentBox().participantfocus]->dead) { + Dialog::indialogue = -1; + Dialog::directing = false; cameramode = 0; } - dialoguecamera[whichdialogue][indialogue] = viewer; - dialoguecamerayaw[whichdialogue][indialogue] = yaw; - dialoguecamerapitch[whichdialogue][indialogue] = pitch; - indialogue++; - if (indialogue < numdialogueboxes[whichdialogue]) { - if (dialogueboxsound[whichdialogue][indialogue] != 0) { + Dialog::currentBox().camera = viewer; + Dialog::currentBox().camerayaw = yaw; + Dialog::currentBox().camerapitch = pitch; + Dialog::indialogue++; + if (Dialog::indialogue < Dialog::currentDialog().boxes.size()) { + if (Dialog::currentBox().sound != 0) { playdialogueboxsound(); } } for (unsigned j = 0; j < Person::players.size(); j++) { - participantfacing[whichdialogue][indialogue][j] = participantfacing[whichdialogue][indialogue - 1][j]; + Dialog::currentBox().participantfacing[j] = Dialog::currentDialog().boxes[Dialog::indialogue - 1].participantfacing[j]; } } //TODO: should these be KeyDown or KeyPressed? @@ -5827,21 +5734,21 @@ void Game::Tick() if (Input::isKeyDown(SDL_SCANCODE_KP_8)) whichend = 8; if (Input::isKeyDown(SDL_SCANCODE_KP_9)) whichend = 9; if (Input::isKeyDown(SDL_SCANCODE_KP_0)) whichend = 0; - participantfacing[whichdialogue][indialogue][whichend] = facing; + Dialog::currentBox().participantfacing[whichend] = facing; } - if (indialogue >= numdialogueboxes[whichdialogue]) { - indialogue = -1; - directing = 0; + if (Dialog::indialogue >= Dialog::currentDialog().boxes.size()) { + Dialog::indialogue = -1; + Dialog::directing = false; cameramode = 0; } } - if (!directing) { + if (!Dialog::directing) { pause_sound(whooshsound); - viewer = dialoguecamera[whichdialogue][indialogue]; + viewer = Dialog::currentBox().camera; viewer.y = max((double)viewer.y, terrain.getHeight(viewer.x, viewer.z) + .1); - yaw = dialoguecamerayaw[whichdialogue][indialogue]; - pitch = dialoguecamerapitch[whichdialogue][indialogue]; - if (dialoguetime > 0.5) + yaw = Dialog::currentBox().camerayaw; + pitch = Dialog::currentBox().camerapitch; + if (Dialog::dialoguetime > 0.5) { if ( Input::isKeyPressed(SDL_SCANCODE_1) || Input::isKeyPressed(SDL_SCANCODE_2) || Input::isKeyPressed(SDL_SCANCODE_3) || @@ -5854,40 +5761,41 @@ void Game::Tick() Input::isKeyPressed(SDL_SCANCODE_0) || Input::isKeyPressed(SDL_SCANCODE_MINUS) || Input::isKeyPressed(attackkey)) { - indialogue++; - if (indialogue < numdialogueboxes[whichdialogue]) { - if (dialogueboxsound[whichdialogue][indialogue] != 0) { + Dialog::indialogue++; + if (Dialog::indialogue < Dialog::currentDialog().boxes.size()) { + if (Dialog::currentBox().sound != 0) { playdialogueboxsound(); - if (dialogueboxsound[whichdialogue][indialogue] == -5) { + if (Dialog::currentBox().sound == -5) { hotspot[numhotspots] = Person::players[0]->coords; hotspotsize[numhotspots] = 10; hotspottype[numhotspots] = -1; numhotspots++; } - if (dialogueboxsound[whichdialogue][indialogue] == -6) { + if (Dialog::currentBox().sound == -6) { hostile = 1; } - if (Person::players[participantfocus[whichdialogue][indialogue]]->dead) { - indialogue = -1; - directing = 0; + if (Person::players[Dialog::currentBox().participantfocus]->dead) { + Dialog::indialogue = -1; + Dialog::directing = false; cameramode = 0; } } } } - if (indialogue >= numdialogueboxes[whichdialogue]) { - indialogue = -1; - directing = 0; + } + if (Dialog::indialogue >= Dialog::currentDialog().boxes.size()) { + Dialog::indialogue = -1; + Dialog::directing = false; cameramode = 0; - if (dialoguetype[whichdialogue] > 19 && dialoguetype[whichdialogue] < 30) { + if (Dialog::currentDialog().type > 19 && Dialog::currentDialog().type < 30) { hostile = 1; } - if (dialoguetype[whichdialogue] > 29 && dialoguetype[whichdialogue] < 40) { + if (Dialog::currentDialog().type > 29 && Dialog::currentDialog().type < 40) { windialogue = true; } - if (dialoguetype[whichdialogue] > 49 && dialoguetype[whichdialogue] < 60) { + if (Dialog::currentDialog().type > 49 && Dialog::currentDialog().type < 60) { hostile = 1; for (unsigned i = 1; i < Person::players.size(); i++) { Person::players[i]->aitype = attacktypecutoff; @@ -5907,7 +5815,7 @@ void Game::Tick() Person::players[0]->jumptogglekeydown = 1; - dialoguetime += multiplier; + Dialog::dialoguetime += multiplier; hawkyaw += multiplier * 25; realhawkcoords = 0; realhawkcoords.x = 25; @@ -5970,7 +5878,7 @@ void Game::Tick() static float oldtargetyaw; if (!Person::players[i]->skeleton.free) { oldtargetyaw = Person::players[i]->targetyaw; - if (i == 0 && indialogue == -1) { + if (i == 0 && !Dialog::inDialog()) { //TODO: refactor repetitive code if (!animation[Person::players[0]->animTarget].attack && Person::players[0]->animTarget != staggerbackhighanim && @@ -6003,7 +5911,7 @@ void Game::Tick() Person::players[i]->targetheadyaw = yaw; Person::players[i]->targetheadpitch = pitch; } - if (i != 0 && Person::players[i]->aitype == playercontrolled && indialogue == -1) { + if (i != 0 && Person::players[i]->aitype == playercontrolled && !Dialog::inDialog()) { if (!animation[Person::players[i]->animTarget].attack && Person::players[i]->animTarget != staggerbackhighanim && Person::players[i]->animTarget != staggerbackhardanim && @@ -6027,9 +5935,9 @@ void Game::Tick() Person::players[i]->targetheadyaw = Person::players[i]->lookyaw; Person::players[i]->targetheadpitch = Person::players[i]->lookpitch; } - if (indialogue != -1) { - Person::players[i]->targetheadyaw = 180 - roughDirection(participantfacing[whichdialogue][indialogue][i]); - Person::players[i]->targetheadpitch = pitchOf(participantfacing[whichdialogue][indialogue][i]); + if (Dialog::inDialog()) { + Person::players[i]->targetheadyaw = 180 - roughDirection(Dialog::currentBox().participantfacing[i]); + Person::players[i]->targetheadpitch = pitchOf(Dialog::currentBox().participantfacing[i]); } if (leveltime < .5) @@ -6086,7 +5994,7 @@ void Game::Tick() Person::players[i]->throwkeydown = 0; } - if (indialogue != -1) { + if (Dialog::inDialog()) { Person::players[i]->forwardkeydown = 0; Person::players[i]->leftkeydown = 0; Person::players[i]->backkeydown = 0; @@ -6435,7 +6343,7 @@ void Game::Tick() } else absflatfacing = flatfacing; - if (indialogue != -1) { + if (Dialog::inDialog()) { Person::players[i]->forwardkeydown = 0; Person::players[i]->leftkeydown = 0; Person::players[i]->backkeydown = 0; @@ -6964,14 +6872,15 @@ void Game::Tick() void Game::TickOnce() { - if (mainmenu) + if (mainmenu) { yaw += multiplier * 5; - else if (directing || indialogue == -1) { + } else if (Dialog::directing || !Dialog::inDialog()) { yaw += deltah * .7; - if (!invertmouse) - pitch += deltav * .7; - if (invertmouse) + if (invertmouse) { pitch -= deltav * .7; + } else { + pitch += deltav * .7; + } if (pitch > 90) pitch = 90; if (pitch < -70) diff --git a/Source/Person.cpp b/Source/Person.cpp index 71c0660..9e2bc9f 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -25,6 +25,7 @@ along with Lugaru. If not, see . #include "Sounds.h" #include "Awards.h" #include "Game.h" +#include "Dialog.h" extern float multiplier; extern Terrain terrain; @@ -65,8 +66,6 @@ extern float damagedealt; extern int hostile; extern float hostiletime; -extern int indialogue; - extern bool gamestarted; std::vector> Person::players(1, std::shared_ptr(new Person())); @@ -504,7 +503,7 @@ void Person::CatchFire() */ int Person::getIdle() { - if (indialogue != -1 && howactive == typeactive && creature == rabbittype) + if (Dialog::inDialog() && (howactive == typeactive) && (creature == rabbittype)) return talkidleanim; if (hasvictim && (victim != this->shared_from_this())/*||(id==0&&attackkeydown)*/) if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype && -- 2.39.5