-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwkbre.cpp
More file actions
3631 lines (3406 loc) · 106 KB
/
wkbre.cpp
File metadata and controls
3631 lines (3406 loc) · 106 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// wkbre - WK (Battles) recreated game engine
// Copyright (C) 2015-2016 Adrien Geets
//
// 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 "global.h"
#include <time.h>
#include <process.h>
#include <mbstring.h>
#include <direct.h>
#include "imgui/imgui.h"
#include <functional>
#include <shellapi.h>
#include <string>
#include <commdlg.h>
HINSTANCE hInstance;
GEContainer *actualpage = 0;
int appexit = 0;
float walkstep = 1.0f, camwalkstep = 1.0f;
char *farg = 0;
uchar secret[] = {0xec,0xc9,0xdf,0xc4,0xc8,0xc3,0x8d,0xea,0xc8,0xc8,0xd9,0xde};
int bo = 0;
int playMode = 0, enableObjTooltips = 0;
ClientState *curclient = 0;
bool objmovalign = 0;
Cursor *defcursor;
bool mouseRot = 0; int msrotx, msroty;
bool multiSel = 0; int mselx, msely;
GrowList<GameObject*> msellist;
bool swSelObj = 0, swLevTree = 0, swLevInfo = 0, swObjCrea = 0, swAbout = 0, swMapEditor = 0, swCityCreator = 0, swTest = 0, swMinimap = 0;
bool mapeditmode = 0;
int mousetool = 0;
bool playAfterLoading = 0;
texture minimapTexture; Bitmap *minimapBitmap;
#ifdef WKBRE_RELEASE
int experimentalKeys = 1;
bool showTimeObjInfo = 0;
#else
int experimentalKeys = 1;
bool showTimeObjInfo = 1;
#endif
char *playercolorname[8] = {"Brown", "Blue", "Yellow", "Red", "Green", "Pink", "Orange", "Aqua"};
char *tooltip_str = "Hello!\nMy name is Mr. Tooltip!\nBye!"; int tooltip_x = 20, tooltip_y = 20;
// Variables needed for GUI:
GUIElement *getobringfront = 0; GESubmenu *actsubmenu = 0;
GUIElement *movingguielement = 0; int movge_rx, movge_ry;
// Menu
char *menubarstr[] = {"File", "Object", "Game", "View", "Window", "Help"};
MenuEntry menucmds[] = {
{"Save as...", CMD_SAVE},
{"Change WK version", CMD_CHANGE_SG_WKVER},
{"Quit", CMD_QUIT},
{0,0},
{"Create object...", CMD_CREATEOBJ},
{"Duplicate selected objects", CMD_DUPLICATESELOBJECT},
{"Convert type...", CMD_CONVERTOBJTYPE},
{"Give selected objects to...", CMD_GIVESELOBJECT},
{"Give type...", CMD_GIVEOBJTYPE},
{"Delete selected objects", CMD_DELETESELOBJECT},
{"Delete last created object", CMD_DELETELASTCREATEDOBJ},
{"Delete type...", CMD_DELETEOBJTYPE},
{"Delete class...", CMD_DELETEOBJCLASS},
{"Scale selected objects by 1.5", CMD_SELOBJSCALEBIGGER},
{"Scale selected objects by 1/1.5", CMD_SELOBJSCALESMALLER},
{"Rotate selected objects by 90 deg", CMD_ROTATEOBJQP},
{"Randomize subtypes", CMD_RANDOMSUBTYPE},
{"Reset objects' heights", CMD_RESETOBJPOS},
{"Rename player object...", CMD_CHANGE_PLAYER_NAME},
{"Change player color...", CMD_CHANGE_PLAYER_COLOR},
{"Select object by ID...", CMD_SELECT_OBJECT_ID},
{"Enable/disable aligned movement", CMD_CHANGE_OBJMOVALIGN},
{0,0},
{"Pause/Resume", CMD_PAUSE},
{"Increase game speed", CMD_GAME_SPEED_FASTER},
{"Decrease game speed", CMD_GAME_SPEED_SLOWER},
{"Start level", CMD_START_LEVEL},
{"Control client...", CMD_CONTROL_CLIENT},
{"Execute command...", CMD_EXECUTE_COMMAND},
{"Execute command with target...", CMD_EXECUTE_COMMAND_WITH_TARGET},
{"Execute action sequence...", CMD_RUNACTSEQ},
{"Send event...", CMD_SEND_EVENT},
{"Cancel all objects' orders", CMD_CANCEL_ALL_OBJS_ORDERS},
{"Remove battles delayed sequences", CMD_REMOVE_BATTLES_DELAYED_SEQS},
{"Quick stampdown...", CMD_STAMPDOWN_OBJECT},
{"Open game text window...", CMD_ENABLE_GTW},
{"Enable/disable gameplay shortcuts", CMD_TOGGLEEXPERIMENTALKEYS},
{0,0},
{"Move to...", CMD_CAMPOS},
{"Move to down-left corner", CMD_CAMDOWNLEFT},
{"Move to down-right corner", CMD_CAMDOWNRIGHT},
{"Move to up-left corner", CMD_CAMUPLEFT},
{"Move to up-right corner", CMD_CAMUPRIGHT},
{"Move to player's manor...", CMD_CAMMANOR},
{"Move to client's position...", CMD_CAMCLISTATE},
{"Reset orientation", CMD_CAMRESETORI},
{"Show/hide terrain", CMD_SHOWHIDELANDSCAPE},
{"Show/hide representations", CMD_TOGGLEREPRENSATIONS},
{"Show/hide object tooltips", CMD_TOGGLEOBJTOOLTIPS},
{"Show/hide time & object information", CMD_TOGGLE_TIMEOBJINFO},
{"Show/hide grid", CMD_TOGGLEGRID},
//{"BCM himap bit left", CMD_BCMHIMAPLEFT},
//{"BCM himap bit right", CMD_BCMHIMAPRIGHT},
{0,0},
{"Open all", CMD_SWOPENALL},
{"Close all", CMD_SWCLOSEALL},
{"Selected object information", CMD_SWSELOBJ},
{"Level information", CMD_SWLEVINFO},
{"Level tree", CMD_SWLEVTREE},
{"Object creation", CMD_SWOBJCREA},
{"Terrain editor", CMD_SWMAPEDITOR},
{"City creator", CMD_SWCITYCREATOR},
{"Minimap", CMD_SWMINIMAP},
{0,0},
{"About...", CMD_ABOUT},
{0,0},
};
int orderButtX[6] = { 6, 37, 69, 93, 100, 90 };
int orderButtY[6] = { 364, 354, 361, 384, 416, 448 };
CObjectDefinition *objtypeToStampdown = 0;
bool eventAfterStampdown = 0;
goref playerToGiveStampdownObj;
float stampdownRot = 0;
MapTextureGroup *curtexgrp = 0; MapTexture *curtex = 0;
int men_rot = 0; bool men_xflip = 0, men_zflip = 0;
bool mousetoolpress_l = 0, mousetoolpress_r = 0;
int brushsize = 1, brushshape = 0; bool randommaptex = 0, randommaptiletransform = 0;
bool himapautowater = 0;
goref newmanorplayer; int nmc_size = 3; int nmc_npeasants = 4; bool nmc_flags = 0;
// Minimap drawing...
Bitmap *doom_bmp; int doom_w, doom_h; bool doom_edge;
int doom_mmw, doom_mmh, doom_sx, doom_sy;
extern int colortable[8];
void DrawObjOnMinimapBmp(GameObject *o)
{
float fx = o->position.x / 5;
float fy = o->position.z / 5;
if(doom_edge) {fx += mapedge; fy += mapedge;}
int x = doom_sx + floor(fx * doom_mmw / doom_w);
int y = doom_bmp->h - 1 - doom_sy - floor(fy * doom_mmh / doom_h);
if(x >= 0 && x < doom_bmp->w && y >= 0 && y < doom_bmp->h)
{
int c = colortable[o->color];
//c = ((c&0xFF0000)>>16) | (c&0xFF00) | ((c&0xFF)<<16);
((uint*)doom_bmp->pix)[y*doom_bmp->w + x] = c | 0xFF000000;
}
for(DynListEntry<GameObject> *e = o->children.first; e; e = e->next)
DrawObjOnMinimapBmp(&e->value);
}
void DrawObjectsOnMinimapBmp(Bitmap *bmp, bool edge)
{
doom_bmp = bmp;
doom_edge = edge;
doom_w = edge ? mapwidth : (mapwidth - 2 * mapedge);
doom_h = edge ? mapheight : (mapheight - 2 * mapedge);
if(doom_w > doom_h) {doom_mmw = bmp->w; doom_mmh = doom_h * bmp->w / doom_w;}
else {doom_mmh = bmp->h; doom_mmw = doom_w * bmp->h / doom_h;}
doom_sx = bmp->w/2 - doom_mmw/2;
doom_sy = bmp->h/2 - doom_mmh/2;
DrawObjOnMinimapBmp(levelobj);
}
// ImGui dialog boxes replacing Win32-based ones.
bool IGGSLItemsGetter(void *data, int idx, const char **out);
int ndlgmode = 0; // 0=closed, 1=Listbox, 2=String
char *ndlgheader = 0;
GrowStringList *nlstdlggsl = 0; //int nlstdlgfirstsel = 0;
char *nstrdlgout = 0;
std::function<void()> dlgOkPress = []() {printf("OK pressed.\n");};
bool ndlgfirsttime = false;
int nlstdlgsel = 0;
void OpenListDlgBox(GrowStringList *gsl, char *hs, int fsel, std::function<void()> f)
{
ndlgheader = hs ? hs : "Select something from this list.";
nlstdlggsl = gsl;
nlstdlgsel = fsel;
ndlgmode = 1;
ndlgfirsttime = true;
dlgOkPress = f;
}
void OpenStrDlgBox(char *out, char *hs, std::function<void()> f)
{
ndlgheader = hs ? hs : "Type a string.";
nstrdlgout = out;
ndlgmode = 2;
ndlgfirsttime = true;
dlgOkPress = f;
}
void IGNDlgBox()
{
bool q = true, ok = false;
static ImGuiTextFilter filter;
if(!ndlgmode) return;
if(ndlgfirsttime)
{
ImGui::SetNextWindowSize(ImVec2(400,0/*(ndlgmode==2)?100:300*/), ImGuiSetCond_Always);
ImGui::SetNextWindowPosCenter(ImGuiSetCond_Always);
filter.Clear();
}
if(!ImGui::Begin("Prompt##NDlgBox", &q, ImGuiWindowFlags_NoCollapse)) {ImGui::End(); return;}
ImGui::PushItemWidth(-1);
if(!q) ndlgmode = 0;
ImGui::TextWrapped(ndlgheader);
switch(ndlgmode)
{
case 1:
if (ImGui::IsWindowAppearing()) ImGui::SetKeyboardFocusHere();
filter.Draw();
ImGui::ListBoxHeader("##ListBox", ImVec2(0,200));
for(int i = 0; i < nlstdlggsl->len; i++)
if(filter.PassFilter(nlstdlggsl->getdp(i)))
{
if(ImGui::Selectable(nlstdlggsl->getdp(i), nlstdlgsel == i))
nlstdlgsel = i;
if(ImGui::IsItemHovered())
if(ImGui::IsMouseDoubleClicked(0))
{nlstdlgsel = i;
ok = 1;}
}
ImGui::ListBoxFooter();
break;
case 2:
if (ImGui::IsWindowAppearing()) ImGui::SetKeyboardFocusHere();
if(ImGui::InputText("##InputText", nstrdlgout, 80, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll))
ok = 1;
break;
}
if(ImGui::Button("OK"))
ok = 1;
ImGui::SameLine();
if(ImGui::Button("Cancel") || ImGui::IsKeyDown(VK_ESCAPE))
ndlgmode = 0;
ImGui::PopItemWidth();
ImGui::End();
ndlgfirsttime = 0;
if(ok)
{ndlgmode = 0; dlgOkPress();}
}
bool askBeforeExit = 0;
void QuitApp()
{
if(askBeforeExit)
if(MessageBox(hWindow, "Do you really want to quit wkbre?\nUnsaved changes will be lost!", appName, 52) != IDYES)
return;
exit(0);
}
void DrawTooltip()
{
if(!tooltip_str) return;
int x = tooltip_x, y = tooltip_y, w, h;
if(currentCursor)
{x += currentCursor->w; y += currentCursor->h;}
GetTextSize(tooltip_str, &w, &h);
if((x + w) > scrw) x = scrw-w;
if((y + h) > scrh) y = scrh-h;
if(x < 0) x = 0;
if(y < 0) y = 0;
NoTexture(0);
DrawRect(x, y, w, h, 0xC0000080);
DrawFont(x, y, tooltip_str);
}
void DisplaceCurCamera(Vector3 r)
{
if(curclient)
curclient->camerapos += r;
else
camerapos += r;
}
void RotateCurCamera(float x, float y)
{
if(curclient)
curclient->cameraori += Vector3(x, y, 0);
else
{campitch += x; camyaw += y;}
}
void GetCurCameraRot(float *x, float *y)
{
if(curclient)
{*x = curclient->cameraori.x; *y = curclient->cameraori.y;}
else
{*x = campitch; *y = camyaw;}
}
void SetCurCameraRot(float x, float y)
{
if(curclient)
{curclient->cameraori.x = x; curclient->cameraori.y = y;}
else
{campitch = x; camyaw = y;}
}
void SetCurCameraPos(Vector3 v)
{
if(curclient)
curclient->camerapos = v;
else
camerapos = v;
}
void SetCurCameraPosXZ(float x, float z)
{
if(curclient)
{curclient->camerapos.x = x; curclient->camerapos.z = z;}
else
{camerapos.x = x; camerapos.z = z;}
}
void SetCurCameraPosXYZ(float x, float y, float z)
{
if(curclient)
curclient->camerapos = Vector3(x, y, z);
else
camerapos = Vector3(x, y, z);
}
void RemoveObjOfType(GameObject *o, CObjectDefinition *d)
{
DynListEntry<GameObject> *nx;
for(DynListEntry<GameObject> *e = o->children.first; e; e = nx)
{
nx = e->next;
RemoveObjOfType(&e->value, d);
}
if(o->objdef == d)
RemoveObject(o);
}
void ReplaceObjsType(GameObject *o, CObjectDefinition *a, CObjectDefinition *b)
{
for(DynListEntry<GameObject> *e = o->children.first; e; e = e->next)
ReplaceObjsType(&e->value, a, b);
if(o->objdef == a)
{
ConvertObject(o, b);
/*
o->objdef = b;
o->item.clear(); //memcpy(o->item, b->startItems, strItems.len * sizeof(valuetype));
o->appearance = 0;
o->subtype = (b->numsubtypes>1)?((rand()%(b->numsubtypes-1)) + 1):0;
o->renderable = b->renderable;
*/
}
}
void SetObjsCtrl(GameObject *o, CObjectDefinition *d, GameObject *p)
{
if(o == p) //levelobj->children.getEntry(1)->value
return;
DynListEntry<GameObject> *nx;
for(DynListEntry<GameObject> *e = o->children.first; e; e = nx)
{
nx = e->next;
SetObjsCtrl(&e->value, d, p);
}
if(o->objdef == d)
SetObjectParent(o, p);
}
void NAskObjDef(char *head, std::function<void(CObjectDefinition*)> f)
{
static GrowStringList l; char ts[256];
l.clear();
for(int i = 0; i < strObjDef.len; i++)
{
if((objdef[i].type == 0) || (objdef[i].name == 0))
{l.add("?"); continue;}
strcpy(ts, CLASS_str[objdef[i].type]);
strcat(ts, " ");
strcat(ts, objdef[i].name);
l.add(ts);
}
//static std::function<void(CObjectDefinition*)> f = g;
OpenListDlgBox(&l, head?head:"Select an object definition.", 0,
[f]() {
CObjectDefinition *cod;
if(nlstdlgsel == -1) cod = 0;
else cod = &objdef[nlstdlgsel];
f(cod);
}
);
}
void NAskPlayer(char *head, std::function<void(GameObject*)> f)
{
static GrowStringList l; char ts[512]; int x = 0;
l.clear();
for(DynListEntry<GameObject> *e = levelobj->children.first; e; e = e->next)
{
if(e->value.objdef->type != CLASS_PLAYER) break; // TODO: Something better.
sprintf(ts, "%u: %S (obj. id %u)", x++, e->value.name ? e->value.name : L"(null)", e->value.id);
l.add(ts);
}
OpenListDlgBox(&l, head?head:"Select a player.", (l.len >= 2) ? 1 : 0,
[f]() {
if(nlstdlgsel != -1)
f(&levelobj->children.getEntry(nlstdlgsel)->value);
});
}
void RandomizeObjAppear(GameObject *o)
{
for(DynListEntry<GameObject> *e = o->children.first; e; e = e->next)
RandomizeObjAppear(&e->value);
SetRandomSubtypeAndAppearance(o);
}
void ResetPosition(GameObject *o)
{
for(DynListEntry<GameObject> *e = o->children.first; e; e = e->next)
ResetPosition(&e->value);
if((o->objdef->type == CLASS_BUILDING) || (o->objdef->type == CLASS_CHARACTER) ||
(o->objdef->type == CLASS_CONTAINER) || (o->objdef->type == CLASS_PROP))
GOPosChanged(o, 0, 1);
//o->position.y = GetHeight(o->position.x, o->position.z);
}
void RemoveObjOfClass(GameObject *o, int c)
{
DynListEntry<GameObject> *nx;
for(DynListEntry<GameObject> *e = o->children.first; e; e = nx)
{
nx = e->next;
RemoveObjOfClass(&e->value, c);
}
if(o->objdef->type == c)
RemoveObject(o);
}
void SendEventToObjAndSubord(GameObject *o, int v)
{
SendGameEvent(0, o, v);
DynListEntry<GameObject> *n;
for(DynListEntry<GameObject> *e = o->children.first; e; e = n)
{
n = e->next;
SendEventToObjAndSubord(&e->value, v);
}
}
void NAskClass(char *head, std::function<void(int)> f)
{
static GrowStringList sl;
for (int i = 0; i < OBJTYPE_NUM; i++)
sl.add(OBJTYPE_str[i]);
OpenListDlgBox(&sl, head ? head : "Select an object class.", 0,
[f]() {
if (nlstdlgsel != -1)
f(stfind_cs(CLASS_str, CLASS_NUM, OBJTYPE_str[nlstdlgsel]));
}
);
}
void NAskCommand(char *head, DynList<goref> *objs, std::function<void(CCommand*)> func)
{
static GrowList<CCommand *> lc;
static GrowStringList ls;
lc.clear();
ls.clear();
for (DynListEntry<goref> *e = objs->first; e; e = e->next)
{
if (!e->value.valid()) continue;
for (int i = 0; i < e->value->objdef->offeredCmds.len; i++)
if (!lc.has(e->value->objdef->offeredCmds[i]))
lc.add(e->value->objdef->offeredCmds[i]);
}
for (int i = 0; i < lc.len; i++)
ls.add(lc[i]->name);
OpenListDlgBox(&ls, head ? head : "Select a command.", 0,
[func]() {
if (nlstdlgsel != -1)
func(lc[nlstdlgsel]);
}
);
}
DynList<goref> createdObjects;
DynList<goref> selobjects;
int menuVisible = 1;
char *statustext = 0; //"Status bar";
char statustextbuf[1024];
char *notificationtext = 0; uint notiftimeref, notifdelay;
void GiveNotification(char *str, int delay = 3000)
{
notificationtext = strdup(str);
notiftimeref = GetTickCount();
notifdelay = delay;
}
void GiveSpeedNotif()
{
char t[128];
sprintf_s(t, 127, "Game speed: %g", game_speed);
GiveNotification(t);
}
void UpdateSelectionInfo()
{
DynListEntry<goref> *n;
for(DynListEntry<goref> *e = selobjects.first; e; e = n)
{
n = e->next;
if(!e->value.valid())
selobjects.remove(e);
}
if(!selobjects.len)
{statustext = 0; return;}
if(selobjects.len == 1)
{
_snprintf(statustextbuf, 128,
"Object ID %i, %s \"%s\"", selobjects.first->value->id,
CLASS_str[selobjects.first->value->objdef->type],
selobjects.first->value->objdef->name);
statustext = statustextbuf;
}
else
{
_snprintf(statustextbuf, 128, "%u objects selected.", selobjects.len);
/*strcpy(statustextbuf, "Objs");
for(DynListEntry<goref> *e = selobjects.first; e; e = e->next)
{
char nms[64];
sprintf(nms, " %u", e->value.getID());
strcat_s(statustextbuf, 128, nms);
statustextbuf[128] = 0;
}*/
statustext = statustextbuf;
}
}
void SelectObject(GameObject *o)
{
if(!o) return;
if(o->flags & FGO_SELECTED) return;
o->flags |= FGO_SELECTED;
selobjects.add();
selobjects.last->value = o;
UpdateSelectionInfo();
}
void DeselectObject(GameObject *o)
{
if(!o) return;
if(!(o->flags & FGO_SELECTED)) return;
o->flags &= ~FGO_SELECTED;
DynListEntry<goref> *n;
for(DynListEntry<goref> *e = selobjects.first; e; e = n)
{
n = e->next;
if(e->value.get() == o)
selobjects.remove(e);
}
UpdateSelectionInfo();
}
void DeselectAll()
{
DynListEntry<goref> *n;
for(DynListEntry<goref> *e = selobjects.first; e; e = n)
{
n = e->next;
if(e->value.valid())
{
e->value->flags &= ~FGO_SELECTED;
selobjects.remove(e);
}
}
UpdateSelectionInfo();
}
void CancelAllObjsOrders(GameObject *o)
{
if(o->ordercfg.order.len)
//CancelAllOrders(o);
o->ordercfg.order.clear();
RemoveObjReference(o);
for(DynListEntry<GameObject> *e = o->children.first; e; e = e->next)
CancelAllObjsOrders(&e->value);
}
void AddClientsToGSL(GrowStringList *sl)
{
for(uint i = 0; i < clistates.len; i++)
{
ClientState *c = clistates.getpnt(i);
if(!c->obj.valid())
sl->add("<PLAYER object removed>");
else {
char nm[256]; char *so = nm;
wchar_t *si = c->obj->name;
while(*si) *(so++) = *(si++);
*so = 0;
sl->add(nm);
}
}
}
void CallCommand(int cmd)
{
switch(cmd)
{
case CMD_SAVE:
{
#ifndef WKBRE_RELEASE
if(keyheld[VK_SHIFT])
{
char t[1024], e[1024] = "\"\0";
strcpy(t, gamedir);
strcat(t, "\\saved\\Save_Games\\wkbre_quick_look.sav");
SaveSaveGame(t);
strcat(e, t);
strcat(e, "\"");
char *x = "C:\\Users\\Adrien\\Downloads\\SciTE\\SciTE\\SciTE.exe";
_spawnlp(_P_NOWAIT, x, x, e, NULL);
break;
}
#endif
if(!strlen(lastmap))
{MessageBox(hWindow, "The savegame is not linked to a terrain file.\nEither save the current terrain in \"Window > Terrain editor > Save SNR/BCM\",\nor set the path of the terrain file in \"Window > Level information > Properties > Map\", then try again.", appName, 48);
break;}
/*
char s[256];
if(StrDlgBox(s, "Type the name of the new save game. It will be placed in \"saved\\Save_Games\" in the game directory. The name must end with either \".sav\" or \".lvl\"."))
*/
static char s[400];
strcpy(s, lastsavegamename);
strcat(s, isLevelStarted ? ".sav" : ".lvl");
auto f = []()
{
char *p = strrchr(s, '.');
bool addext = false;
if (!p) addext = true;
else if (stricmp(p + 1, "sav") && stricmp(p + 1, "lvl")) addext = true;
std::string s2(s);
if (addext) s2 += isLevelStarted ? ".sav" : ".lvl";
char t[1024] = "Save_Games\\\0";
strcat(t, s2.c_str());
if(FileExists(t))
if(MessageBox(hWindow, "The file name already exists. Do you want to replace/overwrite this file?", appName, 48 | MB_YESNO) != IDYES)
return;
//strcpy(t, gamedir);
//strcat(t, "\\saved\\Save_Games\\");
//strcat(t, s);
if (SaveSaveGame((char*)(std::string(gamedir) + "\\saved\\" + t).c_str())) {
GiveNotification("Savegame saved!");
if (lastsavegamepath) free(lastsavegamepath);
lastsavegamepath = strdup(t);
}
else
MessageBox(hWindow, "wkbre was not able to create the file for your savegame.\n\nBe sure that the filename doesn't contain special characters and that the \"saved\\Save_Games\" folder exists and is not write-protected.", appName, 48);
};
//OpenStrDlgBox(s, "Save level (.lvl) or savegame (.sav) as:", f);
OpenStrDlgBox(s, isLevelStarted ? "Save savegame (.sav) as:" : "Save level (.lvl) as:", f);
} break;
case CMD_DELETEOBJTYPE:
{
NAskObjDef("Select the type of objects you want to delete.",
[](CObjectDefinition *d) {
RemoveObjOfType(levelobj, d);
});
} break;
case CMD_CONVERTOBJTYPE:
{
NAskObjDef("What type of object do you want to convert?",
[](CObjectDefinition *a) {
NAskObjDef("Which object type should they be converted to?",
[a](CObjectDefinition *b) {
ReplaceObjsType(levelobj, a, b);
});
});
} break;
case CMD_GIVEOBJTYPE:
{
NAskObjDef("What type of objects do you want to give?",
[](CObjectDefinition *d) {
NAskPlayer("Give the objects to:",
[d](GameObject *p) {
SetObjsCtrl(levelobj, d, p);
});
});
} break;
case CMD_RANDOMSUBTYPE:
RandomizeObjAppear(levelobj); break;
case CMD_ABOUT:
{
swAbout = !swAbout;
} break;
case CMD_RESETOBJPOS:
ResetPosition(levelobj); break;
case CMD_CAMDOWNLEFT:
SetCurCameraPosXYZ(0, 0, 0); break;
case CMD_CAMDOWNRIGHT:
SetCurCameraPosXYZ((mapwidth-mapedge*2)*5, 0, 0); break;
case CMD_CAMUPLEFT:
SetCurCameraPosXYZ(0, 0, (mapheight-mapedge*2)*5); break;
case CMD_CAMUPRIGHT:
SetCurCameraPosXYZ((mapwidth-mapedge*2)*5, 0, (mapheight-mapedge*2)*5); break;
case CMD_SHOWHIDELANDSCAPE:
enableMap = !enableMap; break;
case CMD_QUIT:
QuitApp(); break;
case CMD_DELETESELOBJECT:
for(DynListEntry<goref> *e = selobjects.first; e; e = e->next)
if(e->value.valid())
{
GameObject *o = e->value.get();
//DeselectObject(o);
RemoveObject(o);
}
break;
case CMD_DUPLICATESELOBJECT:
for(DynListEntry<goref> *e = selobjects.first; e; e = e->next)
if(e->value.valid())
DuplicateObject(e->value.get());
break;
case CMD_DELETEOBJCLASS:
{
NAskClass("Delete all objects of class:",
[](int cl) {RemoveObjOfClass(levelobj, cl); }
);
} break;
case CMD_CAMRESETORI:
SetCurCameraRot(0.0f, 0.0f); break;
case CMD_SELOBJSCALEBIGGER:
for(DynListEntry<goref> *e = selobjects.first; e; e = e->next)
if(e->value.valid())
e->value->scale *= 1.5;
break;
case CMD_SELOBJSCALESMALLER:
for(DynListEntry<goref> *e = selobjects.first; e; e = e->next)
if(e->value.valid())
e->value->scale /= 1.5;
break;
case CMD_GIVESELOBJECT:
{
NAskPlayer("Give selected object to:", [](GameObject *p) {
for (DynListEntry<goref> *e = selobjects.first; e; e = e->next)
if (e->value.valid())
SetObjectParent(e->value.get(), p);
});
} break;
case CMD_RUNACTSEQ:
{
OpenListDlgBox(&strActionSeq, "Which action sequence do you want to execute?", 0,
[]() {
if (nlstdlgsel != -1)
{
SequenceEnv s;
for (DynListEntry<goref> *e = selobjects.first; e; e = e->next)
if (e->value.valid())
{
s.self = e->value; break;
}
actionseq[nlstdlgsel]->run(&s);
}
}
);
} break;
case CMD_ROTATEOBJQP:
if( (objtypeToStampdown && playerToGiveStampdownObj.valid()) ||
(mousetool == 7 && newmanorplayer.valid()) )
{
stampdownRot += M_PI / 2;
if(stampdownRot >= 2*M_PI)
stampdownRot -= M_PI * 2;
break;
}
for(DynListEntry<goref> *e = selobjects.first; e; e = e->next)
if(e->value.valid())
{
e->value->orientation.y += M_PI / 2;
if(e->value->orientation.y >= 2*M_PI)
e->value->orientation.y -= M_PI * 2;
}
break;
case CMD_TOGGLEEXPERIMENTALKEYS:
experimentalKeys = !experimentalKeys; break;
case CMD_TOGGLEREPRENSATIONS:
showrepresentations = !showrepresentations; break;
case CMD_CAMCLISTATE:
{
static GrowStringList sl;
sl.clear();
AddClientsToGSL(&sl);
OpenListDlgBox(&sl, "Copy camera position and rotation from whose client?", 0,
[]() {
if (nlstdlgsel != -1) {
ClientState *c = clistates.getpnt(nlstdlgsel);
SetCurCameraPos(c->camerapos);
SetCurCameraRot(c->cameraori.x, c->cameraori.y);
}
}
);
} break;
case CMD_PAUSE:
playMode = !playMode;
if(playMode) GetElapsedTime();
break;
case CMD_TOGGLEOBJTOOLTIPS:
enableObjTooltips = !enableObjTooltips; break;
case CMD_GAME_SPEED_FASTER:
game_speed *= 2.0f; GiveSpeedNotif(); break;
case CMD_GAME_SPEED_SLOWER:
game_speed /= 2.0f; GiveSpeedNotif(); break;
case CMD_CANCEL_ALL_OBJS_ORDERS:
CancelAllObjsOrders(levelobj); break;
case CMD_SELECT_OBJECT_ID:
{
static char s[256];
auto f = []() {
GameObject *o = FindObjID(atoi(s));
if(!o) GiveNotification("Object with specified ID not found.");
else {DeselectAll(); SelectObject(o);}
};
OpenStrDlgBox(s, "Enter the ID of the object you'd like to select.", f);
} break;
case CMD_CHANGE_SG_WKVER:
{
static GrowStringList sl;
sl.clear();
sl.add("Warrior Kings"); sl.add("Warrior Kings - Battles");
OpenListDlgBox(&sl, "Make next saves compatible with:", (sg_ver==WKVER_BATTLES)?1:0,
[]() {
if (nlstdlgsel != -1)
sg_ver = nlstdlgsel ? WKVER_BATTLES : WKVER_ORIGINAL;
}
);
} break;
case CMD_CONTROL_CLIENT:
{
static GrowStringList sl;
sl.clear();
sl.add("<No client>");
AddClientsToGSL(&sl);
OpenListDlgBox(&sl, "Which client to you want to take control?", 1,
[]() {
if (!nlstdlgsel)
curclient = 0;
else if (nlstdlgsel != -1)
curclient = clistates.getpnt(nlstdlgsel - 1);
}
);
} break;
case CMD_CHANGE_OBJMOVALIGN:
objmovalign = !objmovalign;
GiveNotification(objmovalign ? "Aligned object movement ON." : "Aligned object movement OFF.");
break;
case CMD_EXECUTE_COMMAND:
{
NAskCommand("Which command do you want to execute on the selected objects (with no target)?", &selobjects,
[](CCommand *c) {
for (DynListEntry<goref> *e = selobjects.first; e; e = e->next)
if (e->value.valid())
ExecuteCommand(e->value.get(), c, 0, ORDERASSIGNMODE_FORGET_EVERYTHING_ELSE);
}
);
break;
}
case CMD_EXECUTE_COMMAND_WITH_TARGET:
if(selobjects.len >= 2)
if(selobjects.last->value.valid())
{
static DynList<goref> dl;
dl.clear();
dl.add(); dl.first->value = selobjects.first->value;
NAskCommand("Which command do you want to execute on the first selected objects with the last selected object as the target?", &dl,
[](CCommand *c) {
DynListEntry<goref> *e = selobjects.first;
for (int i = 0; i < selobjects.len - 1; i++)
{
if (e->value.valid())
ExecuteCommand(e->value.get(), c, selobjects.last->value.get(), ORDERASSIGNMODE_FORGET_EVERYTHING_ELSE);
e = e->next;
}
}
);
}
break;
case CMD_CREATE_MAPPED_TYPE_OBJECT:
{
OpenListDlgBox(&strTypeTag, "Select a type tag.", 0,
[]() {
if(nlstdlgsel != -1)
{
for(DynListEntry<goref> *e = selobjects.first; e; e = e->next)
if(e->value.valid())
if(e->value->objdef->mappedType[nlstdlgsel])
{
GameObject *o = CreateObject(e->value->objdef->mappedType[nlstdlgsel], e->value->parent);
o->position = e->value->position;
GOPosChanged(o);
}
}
}
);
break;
}
case CMD_START_LEVEL:
if (isLevelStarted)
if (MessageBox(hWindow, "The level has already been started! (It is a SAV file.)\nStarting the level again can cause weird behavior (especially an infinite loop)!\nDo you really want to start again?", appName, 48 | MB_YESNO) != IDYES)
break;
SendEventToObjAndSubord(levelobj, PDEVENT_ON_LEVEL_START);
isLevelStarted = 1;
GiveNotification("Level started.");
break;
case CMD_REMOVE_BATTLES_DELAYED_SEQS:
for(DynListEntry<DelayedSequenceEntry> *e = delayedSeq.first; e; e = e->next)
delete [] e->value.obj;
delayedSeq.clear();
for(DynListEntry<SequenceOverPeriodEntry> *e = exePeriodSeq.first; e; e = e->next)
delete [] e->value.ola;
exePeriodSeq.clear();
for(DynListEntry<SequenceOverPeriodEntry> *e = repPeriodSeq.first; e; e = e->next)
delete [] e->value.ola;
repPeriodSeq.clear();
break;
case CMD_SEND_EVENT:
{
OpenListDlgBox(&strGameEvent, "Which event do you want to send to the selected objects?", 0,
[]() {
if(nlstdlgsel != -1)
for(DynListEntry<goref> *e = selobjects.first; e; e = e->next)
if(e->value.valid())
SendGameEvent(0, e->value.get(), nlstdlgsel);
}
);
break;
}
case CMD_TOGGLE_TIMEOBJINFO:
showTimeObjInfo = !showTimeObjInfo; break;
case CMD_SWSELOBJ:
swSelObj = !swSelObj; break;
case CMD_SWLEVINFO:
swLevInfo = !swLevInfo; break;
case CMD_SWLEVTREE:
swLevTree = !swLevTree; break;
case CMD_SWOBJCREA:
swObjCrea = !swObjCrea; break;
case CMD_SWMAPEDITOR:
swMapEditor = !swMapEditor; break;
case CMD_SWCITYCREATOR:
swCityCreator = !swCityCreator; break;
case CMD_SWMINIMAP:
swMinimap = !swMinimap; break;
case CMD_SWOPENALL:
swSelObj = swLevInfo = swLevTree = swObjCrea = swMapEditor = swCityCreator = swMinimap = 1; break;
case CMD_SWCLOSEALL:
swSelObj = swLevInfo = swLevTree = swObjCrea = swMapEditor = swCityCreator = swMinimap = 0; break;
case CMD_TOGGLEGRID:
showMapGrid = !showMapGrid; break;
case CMD_HELP:
ShellExecute(hWindow, "open", "help.htm", NULL, NULL, SW_SHOWNORMAL);
break;
case CMD_EXPORT_BCP:
{
if (!strlen(lastmap))
{