]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Devtools/ConsoleCmds.cpp
Devtools: Improve fixtype cmd and document it
[lugaru.git] / Source / Devtools / ConsoleCmds.cpp
index 10f37e81398eb6cbdf3a0a9701911d38cb04f848..63063ed24ec9508a922d34548749d40c43cb9d20 100644 (file)
@@ -580,7 +580,7 @@ void ch_hs(const char* args)
     strcat(Hotspot::hotspots.back().text, "\n");
 }
 
-void ch_dialogue(const char* args)
+void ch_dialog(const char* args)
 {
     int type;
     char buf1[32];
@@ -595,22 +595,23 @@ void ch_dialogue(const char* args)
     Dialog::whichdialogue = Dialog::dialogs.size();
 }
 
-void ch_fixdialogue(const char* args)
+void ch_fixdialog(const char* args)
 {
     char buf1[32];
-    int whichdi;
+    int whichdlg = 0;
 
-    sscanf(args, "%d %31s", &whichdi, buf1);
+    sscanf(args, "%d %31s", &whichdlg, buf1);
     std::string filename = std::string("Dialogues/") + buf1 + ".txt";
 
-    Dialog::dialogs[whichdi] = Dialog(Dialog::dialogs[whichdi].type, filename);
+    Dialog::dialogs[whichdlg] = Dialog(Dialog::dialogs[whichdlg].type, filename);
 }
 
 void ch_fixtype(const char* args)
 {
-    int dlg;
-    sscanf(args, "%d", &dlg);
-    Dialog::dialogs[0].type = dlg;
+    int whichdlg = 0;
+    int type = 0;
+    sscanf(args, "%d %d", &whichdlg, &type);
+    Dialog::dialogs[whichdlg].type = type;
 }
 
 void ch_fixrotation(const char*)
@@ -619,11 +620,27 @@ void ch_fixrotation(const char*)
     Dialog::currentDialog().participantyaw[playerId] = Person::players[playerId]->yaw;
 }
 
-void ch_ddialogue(const char*)
+void ch_ddialog(const char* args)
 {
-    if (!Dialog::dialogs.empty()) {
+    if (Dialog::dialogs.empty() || Dialog::inDialog()) {
+        return;
+    }
+
+    int dlg = -1;
+    sscanf(args, "%d", &dlg);
+    if (dlg == -1) {
+        // Remove last entry
         Dialog::dialogs.pop_back();
+        return;
     }
+
+    if (dlg >= int(Dialog::dialogs.size())) {
+        // Invalid index, abort
+        return;
+    }
+
+    // Erase given index, higher indexes will be decreased by 1
+    Dialog::dialogs.erase(Dialog::dialogs.begin() + dlg);
 }
 
 void ch_dhs(const char*)