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/>.
21 #include "Devtools/ConsoleCmds.hpp"
24 #include "Level/Dialog.hpp"
25 #include "Level/Hotspot.hpp"
26 #include "Utils/Folders.hpp"
28 const char *cmd_names[cmd_count] = {
29 #define DECLARE_COMMAND(cmd) #cmd,
30 #include "ConsoleCmds.def"
31 #undef DECLARE_COMMAND
34 console_handler cmd_handlers[cmd_count] = {
35 #define DECLARE_COMMAND(cmd) ch_##cmd,
36 #include "ConsoleCmds.def"
37 #undef DECLARE_COMMAND
45 extern bool cellophane;
46 extern int editoractive;
47 extern int editorpathtype;
48 extern int environment;
49 extern float fadestart;
50 extern float slomospeed;
51 extern float slomofreq;
52 extern int tutoriallevel;
56 extern float slomodelay;
57 extern bool skyboxtexture;
61 extern float skyboxlightr;
62 extern float skyboxlightg;
63 extern float skyboxlightb;
64 extern Terrain terrain;
65 extern float viewdistance;
67 /* defined in GameTick.cpp */
69 extern int whichlevel;
71 float tintr = 1, tintg = 1, tintb = 1;
73 /* Helpers used in console commands */
75 /* Return true if PFX is a prefix of STR (case-insensitive). */
76 static bool stripfx(const char *str, const char *pfx)
78 return !strncasecmp(str, pfx, strlen(pfx));
81 static void set_proportion(int pnum, const char *args)
83 float headprop, bodyprop, armprop, legprop;
85 sscanf(args, "%f%f%f%f", &headprop, &bodyprop, &armprop, &legprop);
87 if (Person::players[pnum]->creature == wolftype) {
88 Person::players[pnum]->proportionhead = 1.1 * headprop;
89 Person::players[pnum]->proportionbody = 1.1 * bodyprop;
90 Person::players[pnum]->proportionarms = 1.1 * armprop;
91 Person::players[pnum]->proportionlegs = 1.1 * legprop;
92 } else if (Person::players[pnum]->creature == rabbittype) {
93 Person::players[pnum]->proportionhead = 1.2 * headprop;
94 Person::players[pnum]->proportionbody = 1.05 * bodyprop;
95 Person::players[pnum]->proportionarms = 1.00 * armprop;
96 Person::players[pnum]->proportionlegs = 1.1 * legprop;
97 Person::players[pnum]->proportionlegs.y = 1.05 * legprop;
101 static void set_protection(int pnum, const char *args)
103 float head, high, low;
104 sscanf(args, "%f%f%f", &head, &high, &low);
106 Person::players[pnum]->protectionhead = head;
107 Person::players[pnum]->protectionhigh = high;
108 Person::players[pnum]->protectionlow = low;
111 static void set_armor(int pnum, const char *args)
113 float head, high, low;
114 sscanf(args, "%f%f%f", &head, &high, &low);
116 Person::players[pnum]->armorhead = head;
117 Person::players[pnum]->armorhigh = high;
118 Person::players[pnum]->armorlow = low;
121 static void set_metal(int pnum, const char *args)
123 float head, high, low;
124 sscanf(args, "%f%f%f", &head, &high, &low);
126 Person::players[pnum]->metalhead = head;
127 Person::players[pnum]->metalhigh = high;
128 Person::players[pnum]->metallow = low;
131 static void set_noclothes(int pnum, const char *args)
133 Person::players[pnum]->numclothes = 0;
134 Person::players[pnum]->skeleton.drawmodel.textureptr.load(
135 creatureskin[Person::players[pnum]->creature][Person::players[pnum]->whichskin], 1,
136 &Person::players[pnum]->skeleton.skinText[0], &Person::players[pnum]->skeleton.skinsize);
139 static void set_clothes(int pnum, const char *args)
142 snprintf(buf, 63, "Textures/%s.png", args);
144 int id = Person::players[pnum]->numclothes;
145 strcpy(Person::players[pnum]->clothes[id], buf);
146 Person::players[pnum]->clothestintr[id] = tintr;
147 Person::players[pnum]->clothestintg[id] = tintg;
148 Person::players[pnum]->clothestintb[id] = tintb;
149 Person::players[pnum]->numclothes++;
151 if (!Person::players[pnum]->addClothes(id))
154 Person::players[pnum]->DoMipmaps();
157 /* Console commands themselves */
159 void ch_quit(const char *args)
164 void ch_map(const char *args)
171 void ch_save(const char *args)
173 std::string map_path = Folders::getUserDataPath() + "/Maps/" + args;
178 tfile = fopen( map_path.c_str(), "wb" );
179 fpackf(tfile, "Bi", mapvers);
180 fpackf(tfile, "Bi", maptype);
181 fpackf(tfile, "Bi", hostile);
182 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
183 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
184 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
185 fpackf(tfile, "Bf Bf Bf Bf Bf Bi", Person::players[0]->coords.x, Person::players[0]->coords.y, Person::players[0]->coords.z,
186 Person::players[0]->yaw, Person::players[0]->targetyaw, Person::players[0]->num_weapons);
187 if (Person::players[0]->num_weapons > 0 && Person::players[0]->num_weapons < 5)
188 for (int j = 0; j < Person::players[0]->num_weapons; j++)
189 fpackf(tfile, "Bi", weapons[Person::players[0]->weaponids[j]].getType());
191 fpackf(tfile, "Bf Bf Bf", Person::players[0]->armorhead, Person::players[0]->armorhigh, Person::players[0]->armorlow);
192 fpackf(tfile, "Bf Bf Bf", Person::players[0]->protectionhead, Person::players[0]->protectionhigh, Person::players[0]->protectionlow);
193 fpackf(tfile, "Bf Bf Bf", Person::players[0]->metalhead, Person::players[0]->metalhigh, Person::players[0]->metallow);
194 fpackf(tfile, "Bf Bf", Person::players[0]->power, Person::players[0]->speedmult);
196 fpackf(tfile, "Bi", Person::players[0]->numclothes);
198 fpackf(tfile, "Bi Bi", Person::players[0]->whichskin, Person::players[0]->creature);
200 Dialog::saveDialogs(tfile);
202 for (int k = 0; k < Person::players[0]->numclothes; k++) {
203 int templength = strlen(Person::players[0]->clothes[k]);
204 fpackf(tfile, "Bi", templength);
205 for (int l = 0; l < templength; l++)
206 fpackf(tfile, "Bb", Person::players[0]->clothes[k][l]);
207 fpackf(tfile, "Bf Bf Bf", Person::players[0]->clothestintr[k], Person::players[0]->clothestintg[k], Person::players[0]->clothestintb[k]);
210 fpackf(tfile, "Bi", environment);
212 fpackf(tfile, "Bi", Object::objects.size());
214 for (int k = 0; k < Object::objects.size(); k++)
215 fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", Object::objects[k]->type, Object::objects[k]->yaw, Object::objects[k]->pitch,
216 Object::objects[k]->position.x, Object::objects[k]->position.y, Object::objects[k]->position.z, Object::objects[k]->scale);
218 fpackf(tfile, "Bi", Hotspot::hotspots.size());
219 for (unsigned i = 0; i < Hotspot::hotspots.size(); i++) {
220 fpackf(tfile, "Bi Bf Bf Bf Bf", Hotspot::hotspots[i].type, Hotspot::hotspots[i].size, Hotspot::hotspots[i].position.x, Hotspot::hotspots[i].position.y, Hotspot::hotspots[i].position.z);
221 int templength = strlen(Hotspot::hotspots[i].text);
222 fpackf(tfile, "Bi", templength);
223 for (int l = 0; l < templength; l++)
224 fpackf(tfile, "Bb", Hotspot::hotspots[i].text[l]);
227 fpackf(tfile, "Bi", Person::players.size());
228 if (Person::players.size() > maxplayers) {
229 cout << "Warning: this level contains more players than allowed" << endl;
231 for (unsigned j = 1; j < Person::players.size(); j++) {
232 fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", Person::players[j]->whichskin, Person::players[j]->creature,
233 Person::players[j]->coords.x, Person::players[j]->coords.y, Person::players[j]->coords.z,
234 Person::players[j]->num_weapons, Person::players[j]->howactive, Person::players[j]->scale, Person::players[j]->immobile, Person::players[j]->yaw);
235 if (Person::players[j]->num_weapons < 5)
236 for (int k = 0; k < Person::players[j]->num_weapons; k++)
237 fpackf(tfile, "Bi", weapons[Person::players[j]->weaponids[k]].getType());
238 if (Person::players[j]->numwaypoints < 30) {
239 fpackf(tfile, "Bi", Person::players[j]->numwaypoints);
240 for (int k = 0; k < Person::players[j]->numwaypoints; k++) {
241 fpackf(tfile, "Bf", Person::players[j]->waypoints[k].x);
242 fpackf(tfile, "Bf", Person::players[j]->waypoints[k].y);
243 fpackf(tfile, "Bf", Person::players[j]->waypoints[k].z);
244 fpackf(tfile, "Bi", Person::players[j]->waypointtype[k]);
246 fpackf(tfile, "Bi", Person::players[j]->waypoint);
248 Person::players[j]->numwaypoints = 0;
249 Person::players[j]->waypoint = 0;
250 fpackf(tfile, "Bi Bi Bi", Person::players[j]->numwaypoints, Person::players[j]->waypoint, Person::players[j]->waypoint);
253 fpackf(tfile, "Bf Bf Bf", Person::players[j]->armorhead, Person::players[j]->armorhigh, Person::players[j]->armorlow);
254 fpackf(tfile, "Bf Bf Bf", Person::players[j]->protectionhead, Person::players[j]->protectionhigh, Person::players[j]->protectionlow);
255 fpackf(tfile, "Bf Bf Bf", Person::players[j]->metalhead, Person::players[j]->metalhigh, Person::players[j]->metallow);
256 fpackf(tfile, "Bf Bf", Person::players[j]->power, Person::players[j]->speedmult);
258 float headprop, bodyprop, armprop, legprop;
259 if (Person::players[j]->creature == wolftype) {
260 headprop = Person::players[j]->proportionhead.x / 1.1;
261 bodyprop = Person::players[j]->proportionbody.x / 1.1;
262 armprop = Person::players[j]->proportionarms.x / 1.1;
263 legprop = Person::players[j]->proportionlegs.x / 1.1;
266 headprop = Person::players[j]->proportionhead.x / 1.2;
267 bodyprop = Person::players[j]->proportionbody.x / 1.05;
268 armprop = Person::players[j]->proportionarms.x / 1.00;
269 legprop = Person::players[j]->proportionlegs.x / 1.1;
272 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
274 fpackf(tfile, "Bi", Person::players[j]->numclothes);
275 if (Person::players[j]->numclothes)
276 for (int k = 0; k < Person::players[j]->numclothes; k++) {
278 templength = strlen(Person::players[j]->clothes[k]);
279 fpackf(tfile, "Bi", templength);
280 for (int l = 0; l < templength; l++)
281 fpackf(tfile, "Bb", Person::players[j]->clothes[k][l]);
282 fpackf(tfile, "Bf Bf Bf", Person::players[j]->clothestintr[k], Person::players[j]->clothestintg[k], Person::players[j]->clothestintb[k]);
286 fpackf(tfile, "Bi", numpathpoints);
287 for (int j = 0; j < numpathpoints; j++) {
288 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
289 for (int k = 0; k < numpathpointconnect[j]; k++)
290 fpackf(tfile, "Bi", pathpointconnect[j][k]);
293 fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
298 void ch_cellar(const char *args)
300 Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Furdarko.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
303 void ch_tint(const char *args)
305 sscanf(args, "%f%f%f", &tintr, &tintg, &tintb);
308 void ch_tintr(const char *args)
313 void ch_tintg(const char *args)
318 void ch_tintb(const char *args)
323 void ch_speed(const char *args)
325 Person::players[0]->speedmult = atof(args);
328 void ch_strength(const char *args)
330 Person::players[0]->power = atof(args);
333 void ch_power(const char *args)
335 Person::players[0]->power = atof(args);
338 void ch_size(const char *args)
340 Person::players[0]->scale = atof(args) * .2;
343 void ch_sizenear(const char *args)
345 int closest = findClosestPlayer();
347 Person::players[closest]->scale = atof(args) * .2;
350 void ch_proportion(const char *args)
352 set_proportion(0, args);
355 void ch_proportionnear(const char *args)
357 int closest = findClosestPlayer();
359 set_proportion(closest, args);
362 void ch_protection(const char *args)
364 set_protection(0, args);
367 void ch_protectionnear(const char *args)
369 int closest = findClosestPlayer();
371 set_protection(closest, args);
374 void ch_armor(const char *args)
379 void ch_armornear(const char *args)
381 int closest = findClosestPlayer();
383 set_armor(closest, args);
386 void ch_protectionreset(const char *args)
388 set_protection(0, "1 1 1");
389 set_armor(0, "1 1 1");
392 void ch_metal(const char *args)
397 void ch_noclothes(const char *args)
399 set_noclothes(0, args);
402 void ch_noclothesnear(const char *args)
404 int closest = findClosestPlayer();
406 set_noclothes(closest, args);
409 void ch_clothes(const char *args)
411 set_clothes(0, args);
414 void ch_clothesnear(const char *args)
416 int closest = findClosestPlayer();
418 set_clothes(closest, args);
421 void ch_belt(const char *args)
423 Person::players[0]->skeleton.clothes = !Person::players[0]->skeleton.clothes;
427 void ch_cellophane(const char *args)
429 cellophane = !cellophane;
430 float mul = (cellophane ? 0 : 1);
432 for (auto player : Person::players) {
433 player->proportionhead.z = player->proportionhead.x * mul;
434 player->proportionbody.z = player->proportionbody.x * mul;
435 player->proportionarms.z = player->proportionarms.x * mul;
436 player->proportionlegs.z = player->proportionlegs.x * mul;
440 void ch_funnybunny(const char *args)
442 Person::players[0]->creature = rabbittype;
443 Person::players[0]->skeletonLoad(true);
444 Person::players[0]->scale = .2;
445 Person::players[0]->headless = 0;
446 Person::players[0]->damagetolerance = 200;
447 set_proportion(0, "1 1 1 1");
450 void ch_wolfie(const char *args)
452 Person::players[0]->creature = wolftype;
453 Person::players[0]->skeletonLoad();
454 Person::players[0]->damagetolerance = 300;
455 set_proportion(0, "1 1 1 1");
458 void ch_wolfieisgod(const char *args)
463 void ch_wolf(const char *args)
465 Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Wolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
468 void ch_snowwolf(const char *args)
470 Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/SnowWolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
473 void ch_darkwolf(const char *args)
475 Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/DarkWolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
478 void ch_lizardwolf(const char *args)
480 Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/LizardWolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
483 void ch_white(const char *args)
485 Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Fur.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
488 void ch_brown(const char *args)
490 Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Fur3.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
493 void ch_black(const char *args)
495 Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Fur2.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
498 void ch_sizemin(const char *args)
500 for (unsigned i = 1; i < Person::players.size(); i++)
501 if (Person::players[i]->scale < 0.8 * 0.2)
502 Person::players[i]->scale = 0.8 * 0.2;
505 void ch_tutorial(const char *args)
507 tutoriallevel = atoi(args);
510 void ch_hostile(const char *args)
512 hostile = atoi(args);
515 void ch_type(const char *args)
517 int n = sizeof(editortypenames) / sizeof(editortypenames[0]);
518 for (int i = 0; i < n; i++)
519 if (stripfx(args, editortypenames[i])) {
525 void ch_path(const char *args)
527 int n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
528 for (int i = 0; i < n; i++)
529 if (stripfx(args, pathtypenames[i])) {
535 void ch_hs(const char *args)
539 sscanf(args, "%f%d %n", &size, &type, &shift);
541 Hotspot::hotspots.emplace_back(Person::players[0]->coords, type, size);
543 strcpy(Hotspot::hotspots.back().text, args + shift);
544 strcat(Hotspot::hotspots.back().text, "\n");
547 void ch_dialogue(const char *args)
552 sscanf(args, "%d %31s", &type, buf1);
553 std::string filename = std::string("Dialogues/") + buf1 + ".txt";
555 Dialog::dialogs.push_back(Dialog(type, filename));
557 Dialog::directing = true;
558 Dialog::indialogue = 0;
559 Dialog::whichdialogue = Dialog::dialogs.size();
562 void ch_fixdialogue(const char *args)
567 sscanf(args, "%d %31s", &whichdi, buf1);
568 std::string filename = std::string("Dialogues/") + buf1 + ".txt";
570 Dialog::dialogs[whichdi] = Dialog(Dialog::dialogs[whichdi].type, filename);
573 void ch_fixtype(const char *args)
576 sscanf(args, "%d", &dlg);
577 Dialog::dialogs[0].type = dlg;
580 void ch_fixrotation(const char *args)
582 int playerId = Dialog::currentScene().participantfocus;
583 Dialog::currentDialog().participantyaw[playerId] = Person::players[playerId]->yaw;
586 void ch_ddialogue(const char *args)
588 if (!Dialog::dialogs.empty()) {
589 Dialog::dialogs.pop_back();
593 void ch_dhs(const char *args)
595 if (!Hotspot::hotspots.empty()) {
596 Hotspot::hotspots.pop_back();
600 void ch_immobile(const char *args)
602 Person::players[0]->immobile = 1;
605 void ch_allimmobile(const char *args)
607 for (unsigned i = 1; i < Person::players.size(); i++)
608 Person::players[i]->immobile = 1;
611 void ch_mobile(const char *args)
613 Person::players[0]->immobile = 0;
616 void ch_default(const char *args)
618 Person::players[0]->armorhead = 1;
619 Person::players[0]->armorhigh = 1;
620 Person::players[0]->armorlow = 1;
621 Person::players[0]->protectionhead = 1;
622 Person::players[0]->protectionhigh = 1;
623 Person::players[0]->protectionlow = 1;
624 Person::players[0]->metalhead = 1;
625 Person::players[0]->metalhigh = 1;
626 Person::players[0]->metallow = 1;
627 Person::players[0]->power = 1;
628 Person::players[0]->speedmult = 1;
629 Person::players[0]->scale = 1;
631 if (Person::players[0]->creature == wolftype) {
632 Person::players[0]->proportionhead = 1.1;
633 Person::players[0]->proportionbody = 1.1;
634 Person::players[0]->proportionarms = 1.1;
635 Person::players[0]->proportionlegs = 1.1;
636 } else if (Person::players[0]->creature == rabbittype) {
637 Person::players[0]->proportionhead = 1.2;
638 Person::players[0]->proportionbody = 1.05;
639 Person::players[0]->proportionarms = 1.00;
640 Person::players[0]->proportionlegs = 1.1;
641 Person::players[0]->proportionlegs.y = 1.05;
644 Person::players[0]->numclothes = 0;
645 Person::players[0]->skeleton.drawmodel.textureptr.load(
646 creatureskin[Person::players[0]->creature][Person::players[0]->whichskin], 1,
647 &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
649 editoractive = typeactive;
650 Person::players[0]->immobile = 0;
653 void ch_play(const char *args)
656 sscanf(args, "%d", &dlg);
657 Dialog::whichdialogue = dlg;
659 if (Dialog::whichdialogue >= int(Dialog::dialogs.size())) {
663 Dialog::currentDialog().play();
666 void ch_mapkilleveryone(const char *args)
668 maptype = mapkilleveryone;
671 void ch_mapkillmost(const char *args)
673 maptype = mapkillmost;
676 void ch_mapkillsomeone(const char *args)
678 maptype = mapkillsomeone;
681 void ch_mapgosomewhere(const char *args)
683 maptype = mapgosomewhere;
686 void ch_viewdistance(const char *args)
688 viewdistance = atof(args) * 100;
691 void ch_fadestart(const char *args)
693 fadestart = atof(args);
696 void ch_slomo(const char *args)
698 slomospeed = atof(args);
703 void ch_slofreq(const char *args)
705 slomofreq = atof(args);
708 void ch_skytint(const char *args)
710 sscanf(args, "%f%f%f", &skyboxr, &skyboxg, &skyboxb);
712 skyboxlightr = skyboxr;
713 skyboxlightg = skyboxg;
714 skyboxlightb = skyboxb;
722 void ch_skylight(const char *args)
724 sscanf(args, "%f%f%f", &skyboxlightr, &skyboxlightg, &skyboxlightb);
732 void ch_skybox(const char *args)
734 skyboxtexture = !skyboxtexture;