-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevelManager.cpp
More file actions
1289 lines (1111 loc) · 35.8 KB
/
Copy pathLevelManager.cpp
File metadata and controls
1289 lines (1111 loc) · 35.8 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
#include "settings.h"
#include "commons.h"
#include "LevelManager.h"
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <time.h>
#include "Trap.h"
#include "HeroGate.h"
#include "LightingObject.h"
#include "BasicLight.h"
using namespace std;
using namespace game_utils;
using namespace game_objects;
using namespace game_objects::block_objects;
using namespace cml;
using namespace utils;
using namespace control;
#define LDLVL "LDLVL"
#define TDEF "TDEF"
#define PLOG "PLOG"
#define SAVE "SAVE"
// things
#define HERO_GATE 52
#define LEVEL_TEXTURE 4
#define TEXTURE_ATLAS 0
#define TNG_ITEM_DECORATION 1
#define TNG_BONUS_RESSURECT_CREATURE 87
#define TNG_BONUS_INCREASE_LEVEL 91
#define TNG_BONUS_REVEAL_MAP 86
#define TNG_BONUS_TRANSFER_CREATURE 88
#define TNG_BONUS_STEAL_HERO 89
#define TNG_BONUS_MULTIPLY_CREATURES 90
#define TNG_BONUS_MAKE_SAFE 99
#define TNG_SPELL_HAND_OF_EVIL 11
#define TNG_SPELL_CREATE_IMP 12
#define TNG_SPELL_SIGHT_OF_EVIL 15
#define TNG_SPELL_CAVE_IN 17
#define TNG_SPELL_HEAL_CREATURE 18
#define TNG_SPELL_HOLD_AUDIENCE 19
#define TNG_SPELL_LIGHTNING 20
#define TNG_SPELL_SPEED_CREATURE 21
#define TNG_SPELL_PROTECT_CREATURE 22
#define TNG_SPELL_CONCEAL_CREATURE 23
#define TNG_SPELL_DISEASE 45
#define TNG_SPELL_DESTROY_WALLS 47
#define TNG_SPELL_ARMAGEDDON 134
#define TNG_BOX_BOULDER 94
#define TNG_BOX_ALARM 95
#define TNG_BOX_POISON 96
#define TNG_BOX_LIGHTNING 97
#define TNG_BOX_WORD_OF_POWER 98
#define TNG_BOX_LAVA 99
#define TNG_STATUE1 8
#define TNG_STATUE2 30
#define TNG_STATUE_UNLIT 129
#define TNG_KEY 44
#define TNG_GOLD_250 6
#define TNG_GOLD_500 3
#define TNG_HERO_GATE 49
#define TNG_BARREL 1
#define TNG_CANDLE_ON_STICK 28
#define TNG_PINK_VASE 34
#define TNG_BLUE_VASE 35
#define TNG_GREEN_VASE 36
#define TNG_LIT_TORCH 2
#define TNG_UNLIT_TORCH 7
// traps
#define TNG_TRAP 8
#define TNG_TRAP_BOULDER 1
#define TNG_TRAP_ALARM 2
#define TNG_TRAP_POISON 3
#define TNG_TRAP_LIGHTNING 4
#define TNG_TRAP_WORD_OF_POWER 5
#define TNG_TRAP_LAVA 6
// creatures
#define TNG_CREATURE 5
#define TNG_CREATURE_BARBARIAN 2
#define TNG_CREATURE_KNIGHT 6
#define TNG_CREATURE_HORNED_REAPER 14
#define TNG_CREATURE_DRAGON 17
#define TNG_CREATURE_DEMON_SPAWN 18
#define TNG_CREATURE_FLY 19
#define TNG_CREATURE_BILE_DEMON 22
#define TNG_CREATURE_IMP 23
#define TNG_CREATURE_BEETLE 24
#define TNG_CREATURE_VAMPIRE 25
#define TNG_CREATURE_SPIDER 26
#define TNG_CREATURE_HELL_HOUND 27
// room effects
#define TNG_ROOM_EFFECT 7
#define TNG_ROOM_EFFECT_WATER 2
#define TNG_ROOM_EFFECT_DRY_ICE 4
namespace game_utils
{
namespace managers
{
CLevelManager::CLevelManager(): CManager(), CConsoleListener()
{
currentLevel=0;
}
CLevelManager::~CLevelManager()
{
}
bool CLevelManager::levelExists(string levelFileName)
{
FILE *levelFile;
bool status = true;
status&=(levelFile=fopen((levelFileName+".own").c_str(),"rb"))!=NULL;
status&=(levelFile=fopen((levelFileName+".slb").c_str(),"rb"))!=NULL;
status&=(levelFile=fopen((levelFileName+".tng").c_str(),"rb"))!=NULL;
return status;
}
bool CLevelManager::init()
{
CLogger::setEntryStart();
// Initialization: create the array of blocks.
for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
{
for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
{
levelMap[y][x] = new CBlock();
levelMap[y][x]->setLogicalPosition(vector2i(x,y));
}
}
CLogger::setEntryEnd("\tCreating a map ob blocks 85x85 new blocks.");
string fileName = "";
// Load level list from file.
if (levelFileName=="")
{
levelFileNames.clear();
ifstream iFile;
iFile.open((CV_RESOURCES_DIRECTORY+CV_CONFIG_LEVELS).c_str());
if (!iFile)
{
CLogger::addEntry("[ERROR|LevelManager]: Failed to load %s\n",(CV_RESOURCES_DIRECTORY+CV_CONFIG_LEVELS).c_str());
return false;
}
string line="";
while (!iFile.eof())
{
getline (iFile,line);
if (line.length()!=0 && line.at(0)!='#')
{
levelFileNames.push_back(CV_RESOURCES_DIRECTORY+line);
}
}
iFile.close();
// Load level from files.
fileName = levelFileNames[currentLevel];
}
else
{
fileName = levelFileName;
}
bool result = true;
result&=loadSLB(fileName+".SLB");
if (!result)
{
CLogger::addEntry("[ERROR|LevelManager]: Failed to load %s\n",(fileName+".slb").c_str());
return false;
}
result&=loadOWN(fileName+".OWN");
if (!result)
{
CLogger::addEntry("[ERROR|LevelManager]: Failed to load %s\n",(fileName+".own").c_str());
return false;
}
result&=loadTNG(fileName+".TNG");
if (!result)
{
CLogger::addEntry("[ERROR|LevelManager]: Failed to load %s\n",(fileName+".tng").c_str());
return false;
}
CLogger::setEntryStart();
// After everything has been properly loaded call INIT on all blocks.
for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
{
for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
{
levelMap[y][x]->init();
}
}
CLogger::setEntryEnd("\tInitializing 85x85 blocks.");
CLogger::setEntryStart();
// MUST: calculate height of the ceiling for every block
for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
{
for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
{
if (levelMap[y][x]->isLow())
{
calculateBlockCeilingHeight(levelMap[y][x]);
}
}
}
CLogger::setEntryEnd("\tCalculating ceiling 85x85 blocks.");
CLogger::setEntryStart();
// And only now can we call finalize.
CLightingManager *liManager = CV_GAME_MANAGER->getLightingManager();
for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
{
for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
{
levelMap[y][x]->finalize();
// setup light info
if (levelMap[y][x]->hasTorch())
{
liManager->addLightSource(levelMap[y][x]->getLogicalPosition(), CV_LIGHT_TYPE_TORCH);
}
for (std::vector<CBlockObject*>::iterator rmIter = levelMap[y][x]->getBlockObjects()->begin(); rmIter != levelMap[y][x]->getBlockObjects()->end(); rmIter++)
{
CBlockObject *bObject = *rmIter;
if (bObject->getEffectName() == "EFFECTS_CANDLE")
{
liManager->addLightSource(levelMap[y][x]->getLogicalPosition(), CV_LIGHT_TYPE_CANDLE);
break;
}
}
if (levelMap[y][x]->getType()==CV_BLOCK_TYPE_LAVA_ID && rand()%3==0)
{
liManager->addLightSource(levelMap[y][x]->getLogicalPosition(), CV_LIGHT_TYPE_LAVA);
}
else if (levelMap[y][x]->getType()==CV_BLOCK_TYPE_WATER_ID && rand()%3==0)
{
liManager->addLightSource(levelMap[y][x]->getLogicalPosition(), CV_LIGHT_TYPE_WATER);
}
}
}
//liManager->addLightSource(levelMap[3][3]->getLogicalPosition(), LIGHT_TYPE_TORCH);
CLogger::setEntryEnd("\tFinalizing 85x85 blocks.");
CV_GAME_MANAGER->getConsole()->registerClass(this,"LEVEL MANAGER");
CV_GAME_MANAGER->getConsole()->addParam(LDLVL,"(xxxx) Loads specified level. Level must exist in data/resources/levels.");
CV_GAME_MANAGER->getConsole()->addParam(TDEF,"() Toggles the terrain deformations."); // TODO
CV_GAME_MANAGER->getConsole()->addParam(PLOG,"() Prints the contents of the log file.");
CV_GAME_MANAGER->getConsole()->addParam(SAVE,"(xxxx) Saves the game. Level will be saved in data/resources/saves.");
return result;
}
bool CLevelManager::update()
{
return true;
}
bool CLevelManager::shutdown()
{
for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
{
for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
{
delete levelMap[y][x];
}
}
return true;
}
bool CLevelManager::loadSLB(string fileName)
{
struct sSLB
{
GLbyte typeID; // ID of the block
GLbyte empty; // empty not used reserved value
};
// open file and read data
FILE *inSLB;
if (!(inSLB=fopen(fileName.c_str(),"rb")))
{
return false;
}
sSLB slb[CV_LEVEL_MAP_SIZE][CV_LEVEL_MAP_SIZE];
for (GLuint i=0; i<CV_LEVEL_MAP_SIZE; i++)
{
if (fread(slb[i],CV_LEVEL_MAP_SIZE,sizeof(sSLB),inSLB)==0)
{
fclose(inSLB);
return FALSE;
}
}
fclose(inSLB);
unclaimedBlocksList.clear();
unfortifiedBlocksList.clear();
// process the data
for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
{
for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
{
levelMap[y][x]->setType(slb[y][x].typeID);
if(slb[y][x].typeID == CV_BLOCK_TYPE_UNCLAIMED_LAND_ID)
unclaimedBlocksList[getBlock(x,y)] = getBlock(x,y);
}
}
std::vector<CBlock*> Blocks;
for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
{
for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
{ // If earth block is next to a peice of claimed land, add it to the unfortified list (todo: check land is yours)
if((slb[y][x].typeID == CV_BLOCK_TYPE_EARTH_ID || slb[y][x].typeID == CV_BLOCK_TYPE_EARTH_WITH_TORCH_PLATE_ID) && (slb[y+1][x].typeID == CV_BLOCK_TYPE_CLAIMED_LAND_ID || slb[y-1][x].typeID == CV_BLOCK_TYPE_CLAIMED_LAND_ID || slb[y][x+1].typeID == CV_BLOCK_TYPE_CLAIMED_LAND_ID || slb[y][x-1].typeID == CV_BLOCK_TYPE_CLAIMED_LAND_ID))
unfortifiedBlocksList[getBlock(x,y)] = getBlock(x,y);
}
}
return true;
}
bool CLevelManager::saveSLB(string fileName)
{
struct sSLB
{
GLbyte typeID; // ID of the block
GLbyte empty; // empty not used reserved value
};
// open file and read data
FILE *inSLB;
if (!(inSLB=fopen(fileName.c_str(),"wb")))
{
return false;
}
sSLB slb[CV_LEVEL_MAP_SIZE][CV_LEVEL_MAP_SIZE];
// process the data
for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
{
for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
{
slb[y][x].typeID = levelMap[y][x]->getType();
}
}
for (GLuint i=0; i<CV_LEVEL_MAP_SIZE; i++)
{
if (fwrite(slb[i],CV_LEVEL_MAP_SIZE,sizeof(sSLB),inSLB)==0)
{
fclose(inSLB);
return FALSE;
}
}
fclose(inSLB);
return true;
}
bool CLevelManager::loadOWN(string fileName)
{
FILE *inOWN = NULL;
if (!(inOWN=fopen(fileName.c_str(),"rb")))
{
return false;
}
GLubyte line[256][256];
for (GLint i=0; i<256; i++)
{
fread(line[i],1,256,inOWN);
}
fclose(inOWN);
for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
{
for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
{
levelMap[y][x]->setOwner(line[y*3][x*3]);
}
}
return true;
}
bool CLevelManager::saveOWN(string fileName)
{
FILE *inOWN = NULL;
if (!(inOWN=fopen(fileName.c_str(),"wb")))
{
return false;
}
GLubyte line[256][256];
for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++)
{
for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++)
{
line[y*3][x*3]=levelMap[y][x]->getOwner();
}
}
for (int i=0; i<256; i++)
{
fwrite(line[i],1,256,inOWN);
}
fclose(inOWN);
return true;
}
bool CLevelManager::loadTNG(string fileName)
{
FILE *f_tng = NULL;
if (!(f_tng=fopen(fileName.c_str(),"rb")))
{
return false;
}
GLshort things_count=0;
GLubyte thing_data[21];
GLubyte thing_type;
GLubyte thing_subtype;
GLubyte owner;
GLubyte subtile_x,subtile_y;
GLint map_x,map_y;
GLfloat thing_x,thing_y;
srand((unsigned int)time(NULL));
// read the number of thing in the dk_map
fread(&things_count,1,2,f_tng);
for (GLshort i=0; i<things_count; i++)
{
fread(thing_data,1,21,f_tng);
thing_type=thing_data[6];
thing_subtype=thing_data[7];
owner=thing_data[8];
subtile_x=thing_data[1];
subtile_y=thing_data[3];
map_x=(GLint)subtile_x/3;
map_y=(GLint)subtile_y/3;
thing_x=(GLfloat)map_x*CV_BLOCK_WIDTH+(GLfloat)(subtile_x%3)*(CV_BLOCK_WIDTH/3.0f)+(CV_BLOCK_WIDTH/6.0f);
thing_y=(GLfloat)map_y*CV_BLOCK_DEPTH+(GLfloat)(subtile_y%3)*(CV_BLOCK_DEPTH/3.0f)+(CV_BLOCK_DEPTH/6.0f);
CBlock *block = getBlock(map_x,map_y);
GLfloat y = (block->isWater() || block->isLava())?0.0f:CV_BLOCK_HEIGHT/4.0f;
switch (thing_type)
{
case TNG_ITEM_DECORATION:
{
if (thing_subtype==TNG_BONUS_RESSURECT_CREATURE)
{
block->addModel("MODEL_BONUS",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BONUS_INCREASE_LEVEL)
{
block->addModel("MODEL_BONUS",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BONUS_REVEAL_MAP)
{
block->addModel("MODEL_BONUS",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BONUS_TRANSFER_CREATURE)
{
block->addModel("MODEL_BONUS",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BONUS_STEAL_HERO)
{
block->addModel("MODEL_BONUS",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BONUS_MULTIPLY_CREATURES)
{
block->addModel("MODEL_BONUS",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BONUS_MAKE_SAFE)
{
block->addModel("MODEL_BONUS",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_HAND_OF_EVIL)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_CREATE_IMP)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_SIGHT_OF_EVIL)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_CAVE_IN)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_HEAL_CREATURE)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_HOLD_AUDIENCE)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_LIGHTNING)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_SPEED_CREATURE)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_PROTECT_CREATURE)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_CONCEAL_CREATURE)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_DISEASE)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_DESTROY_WALLS)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_SPELL_ARMAGEDDON)
{
block->addModel("MODEL_BOOK",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BOX_BOULDER)
{
block->addModel("MODEL_BOX",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BOX_ALARM)
{
block->addModel("MODEL_BOX",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BOX_POISON)
{
block->addModel("MODEL_BOX",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BOX_LIGHTNING)
{
block->addModel("MODEL_BOX",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BOX_WORD_OF_POWER)
{
block->addModel("MODEL_BOX",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_BOX_LAVA)
{
block->addModel("MODEL_BOX",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_STATUE1)
{
block->addModel("MODEL_STATUE0",vector3f(thing_x,y,thing_y),true);
}
else if (thing_subtype==TNG_STATUE2)
{
block->addModel("MODEL_STATUE1",vector3f(thing_x,y,thing_y),true);
}
else if (thing_subtype==TNG_STATUE_UNLIT)
{
block->addModel("MODEL_STATUE2",vector3f(thing_x,y,thing_y),true);
}
else if (thing_subtype==TNG_KEY)
{
block->addModel("MODEL_KEY",vector3f(thing_x,(GLfloat)thing_data[5]*(CV_BLOCK_HEIGHT/4.2f),thing_y));
}
else if (thing_subtype==TNG_GOLD_250)
{
block->addModel("MODEL_GOLD250",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_GOLD_500)
{
block->addModel("MODEL_GOLD500",vector3f(thing_x,y,thing_y));
}
else if (thing_subtype==TNG_HERO_GATE)
{
block->addModel(new CHeroGate("MODEL_HGATE",vector3f(thing_x,y,thing_y)));
//CV_GAME_MANAGER->getConsole()->writeLine("HERO GATE: "+CConversions::intToStr(map_x)+","+CConversions::intToStr(map_y));
}
else if (thing_subtype==TNG_BARREL)
{
block->addModel("MODEL_BARREL",vector3f(thing_x,y,thing_y),true);
}
else if (thing_subtype==TNG_CANDLE_ON_STICK)
{
//block->addModel("MODEL_CANDLE",vector3f(thing_x,y,thing_y));
block->addModel(new CLightingObject("MODEL_CANDLE",vector3f(thing_x,y,thing_y),CLightingObject::LOT_CANDLE));
}
else if (thing_subtype==TNG_PINK_VASE)
{
block->addModel("MODEL_VASE0",vector3f(thing_x,y,thing_y),true);
}
else if (thing_subtype==TNG_BLUE_VASE)
{
block->addModel("MODEL_VASE1",vector3f(thing_x,y,thing_y),true);
}
else if (thing_subtype==TNG_GREEN_VASE)
{
block->addModel("MODEL_VASE2",vector3f(thing_x,y,thing_y),true);
}
else if (thing_subtype==TNG_LIT_TORCH || thing_subtype==TNG_UNLIT_TORCH)
{
if (!getBlock(map_x,map_y)->isRoom())
{
block->addModel(new CLightingObject("MODEL_TORCH",vector3f(thing_x,CV_BLOCK_HEIGHT-CV_BLOCK_HEIGHT/7.0f,thing_y),TNG_LIT_TORCH?CLightingObject::LOT_TORCH_LIT:CLightingObject::LOT_TORCH_UNLIT));
}
}
break;
}
// creature
case TNG_CREATURE:
{
if (thing_subtype==TNG_CREATURE_BARBARIAN)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED BARBARIAN");
CV_GAME_MANAGER->getCreatureManager()->addCreature("BARBARIAN",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_KNIGHT)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED KNIGHT");
CV_GAME_MANAGER->getCreatureManager()->addCreature("KNIGHT",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_HORNED_REAPER)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED HORNED REAPER");
CV_GAME_MANAGER->getCreatureManager()->addCreature("HORNED_REAPER",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_DRAGON)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED DRAGON");
CV_GAME_MANAGER->getCreatureManager()->addCreature("DRAGON",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_DEMON_SPAWN)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED DEMON SPAWN");
CV_GAME_MANAGER->getCreatureManager()->addCreature("DEMON_SPAWN",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_FLY)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED FLY");
CV_GAME_MANAGER->getCreatureManager()->addCreature("FLY",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_BILE_DEMON)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED BILE DEMON");
CV_GAME_MANAGER->getCreatureManager()->addCreature("BILE_DEMON",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_IMP)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED IMP");
CV_GAME_MANAGER->getCreatureManager()->addCreature("IMP",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_BEETLE)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED BEETLE");
CV_GAME_MANAGER->getCreatureManager()->addCreature("BEETLE",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_VAMPIRE)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED VAMPIRE");
CV_GAME_MANAGER->getCreatureManager()->addCreature("VAMPIRE",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_SPIDER)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED SPIDER");
CV_GAME_MANAGER->getCreatureManager()->addCreature("SPIDER",vector3f(thing_x,y,thing_y),owner);
}
else if (thing_subtype==TNG_CREATURE_HELL_HOUND)
{
CV_GAME_MANAGER->getConsole()->writeLine("CREATED HELL HOUND");
CV_GAME_MANAGER->getCreatureManager()->addCreature("HELL_HOUND",vector3f(thing_x,y,thing_y),owner);
}
break;
}
// room effect
case 7:
{
break;
}
// trap
case TNG_TRAP:
{
thing_x=(GLfloat)map_x*CV_BLOCK_WIDTH+CV_BLOCK_WIDTH/2.0f;
thing_y=(GLfloat)map_y*CV_BLOCK_DEPTH+CV_BLOCK_DEPTH/2.0f;
if (thing_subtype==TNG_TRAP_ALARM)
{
//trap_class_name=CLASS_NAME_TRAP_ALARM;
block->addModel(new CTrap("MODEL_TRAP",vector3f(thing_x,y,thing_y),CTrap::TT_ALARM));
}
else if (thing_subtype==TNG_TRAP_POISON)
{
block->addModel(new CTrap("MODEL_TRAP",vector3f(thing_x,y,thing_y),CTrap::TT_POISON));
}
else if (thing_subtype==TNG_TRAP_BOULDER)
{
block->addModel(new CTrap("MODEL_BOULDER",vector3f(thing_x,y,thing_y),CTrap::TT_BOULDER));
}
else if (thing_subtype==TNG_TRAP_LIGHTNING)
{
block->addModel(new CTrap("MODEL_TRAP",vector3f(thing_x,y,thing_y),CTrap::TT_LIGHTNING));
}
else if (thing_subtype==TNG_TRAP_WORD_OF_POWER)
{
block->addModel(new CTrap("MODEL_TRAP",vector3f(thing_x,y,thing_y),CTrap::TT_WORD_OF_POWER));
}
else if (thing_subtype==TNG_TRAP_LAVA)
{
block->addModel(new CTrap("MODEL_TRAP",vector3f(thing_x,y,thing_y),CTrap::TT_LAVA));
}
break;
}
// door
case 9:
{
break;
}
}
}
fclose(f_tng);
return true;
}
bool CLevelManager::saveTNG(string fileName)
{
// TODO this
return true;
}
CBlock *CLevelManager::getBlock(GLuint x, GLuint y)
{
return (x>=0&&y>=0&&x<CV_LEVEL_MAP_SIZE&&y<CV_LEVEL_MAP_SIZE?levelMap[y][x]:NULL);
}
CBlock *CLevelManager::getBlockOld(GLuint x, GLuint y)
{
return getBlock(y,x);
}
GLint CLevelManager::getBlockType(GLuint x, GLuint y)
{
return (x>=0&&y>=0&&x<CV_LEVEL_MAP_SIZE&&y<CV_LEVEL_MAP_SIZE?levelMap[y][x]->getType():-1);
}
GLint CLevelManager::getBlockTypeOld(GLuint x, GLuint y)
{
return getBlockType(y,x);
}
bool CLevelManager::isFullBlock(CBlock *block)
{
return !block->isLow();
}
CBlock *CLevelManager::getBlock(vector2i pos)
{
return getBlock(pos[0],pos[1]);
}
bool CLevelManager::isBlockTypeNear(GLint blockType, GLint x, GLint y, bool diagonal, GLubyte owner, std::vector<CBlock*> *blocks)
{
if (!(getBlock(x-1,y-1) && getBlock(x+1,y+1)))
return false;
for(GLint x1 = -1; x1<=1; x1++)
for(GLint y1 = -1; y1<=1; y1++)
if ((diagonal || x1==0 || y1==0) && !(x1==0 && y1==0) &&
(getBlock(x+x1,y+y1)->getType()==blockType) && (owner==getBlock(x+x1,y+y1)->getOwner()))
{
if(blocks) blocks->push_back(getBlock(x+x1,y+y1));
else return true;
}
/*CBlock block;
block.setOwner(owner);
block.setType(blockType);
if(owner <= 8)
{
if(isSameTypeAndOwner(x-1,y,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x-1,y));}
if(isSameTypeAndOwner(x+1,y,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x+1,y));}
if(isSameTypeAndOwner(x,y-1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x,y-1));}
if(isSameTypeAndOwner(x,y+1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x,y+1));}
if(diagonal)
{
if(isSameTypeAndOwner(x-1,y-1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x-1,y-1));}
if(isSameTypeAndOwner(x-1,y+1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x-1,y+1));}
if(isSameTypeAndOwner(x+1,y-1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x+1,y-1));}
if(isSameTypeAndOwner(x+1,y-1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x+1,y+1));}
}
} else {
if(isSameType(x-1,y,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x-1,y));}
if(isSameType(x+1,y,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x+1,y));}
if(isSameType(x,y-1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x,y-1));}
if(isSameType(x,y+1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x,y+1));}
if(diagonal)
{
if(isSameType(x-1,y-1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x-1,y-1));}
if(isSameType(x-1,y+1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x-1,y+1));}
if(isSameType(x+1,y-1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x+1,y-1));}
if(isSameType(x+1,y-1,&block)){ if(!blocks) return true; else blocks->push_back(getBlock(x+1,y+1));}
}
}*/
return (blocks?blocks->size()>0:false);
}
bool CLevelManager::isBlockClaimable(GLint x, GLint y, GLubyte owner, std::vector<CBlock*> *blocks)
{
if (!(getBlock(x-1,y-1) && getBlock(x+1,y+1)))
return false;
for(GLint x1 = -1; x1<=1; x1++)
for(GLint y1 = -1; y1<=1; y1++)
if ((x1==0 || y1==0) && !(x1==0 && y1==0) &&
((getBlock(x+x1,y+y1)->isRoom()) || (getBlock(x+x1,y+y1)->getType()==CV_BLOCK_TYPE_CLAIMED_LAND_ID)) && (owner==getBlock(x+x1,y+y1)->getOwner()))
{
if(blocks) blocks->push_back(getBlock(x+x1,y+y1));
else return true;
}
return (blocks?blocks->size()>0:false);
}
bool CLevelManager::isBlockTypeNear(GLint blockType, cml::vector2i logicalPos, bool diagonal, GLubyte owner, std::vector<CBlock*> *blocks)
{
return isBlockTypeNear(blockType,logicalPos[0], logicalPos[1], diagonal,owner,blocks);
}
bool CLevelManager::isBlockClaimable(cml::vector2i logicalPos, GLubyte owner, std::vector<CBlock*> *blocks)
{
return isBlockClaimable(logicalPos[0], logicalPos[1], owner, blocks);
}
std::map<CBlock*,CBlock*> *CLevelManager::getUnclaimedBlocksList()
{
return &unclaimedBlocksList;
}
GLvoid CLevelManager::removeMarkedBlock(CBlock *block)
{
markedBlocksList.erase(block);
}
GLvoid CLevelManager::removeUnclaimedBlock(CBlock *block)
{
unclaimedBlocksList.erase(block);
}
GLvoid CLevelManager::removeUnfortifiedBlock(CBlock *block)
{
unfortifiedBlocksList.erase(block);
}
GLvoid CLevelManager::addMarkedBlock(CBlock *block)
{
markedBlocksList[block] = block;
}
GLvoid CLevelManager::addUnclaimedBlock(CBlock *block)
{
unclaimedBlocksList[block] = block;
}
GLvoid CLevelManager::addUnfortifiedBlock(CBlock *block)
{
unfortifiedBlocksList[block] = block;
}
CBlock *CLevelManager::getMarkedBlock(GLubyte owner, cml::vector2i position)
{
CBlock *tempblock = NULL;
std::vector<cml::vector2i> path;
std::vector<cml::vector2i> currpath;
currpath.clear();
for (map<CBlock*,CBlock*>::iterator iter=markedBlocksList.begin(); iter!=markedBlocksList.end(); iter++)
{
path.clear();
if(CV_GAME_MANAGER->getPathManager()->findPath(position,((CBlock*)iter->second)->getLogicalPosition(),&path))
{
if((path.size() < currpath.size()) || (currpath.size() == 0))
{
tempblock = (CBlock*)iter->second;
currpath = path;
}
}
}
if(tempblock)
return tempblock;
return NULL;
}
CBlock *CLevelManager::getUnclaimedBlock(GLubyte owner, cml::vector2i position)
{
CBlock *tempblock = NULL;
std::vector<cml::vector2i> path;
std::vector<cml::vector2i> currpath;
currpath.clear();
for (map<CBlock*,CBlock*>::iterator iter=unclaimedBlocksList.begin(); iter!=unclaimedBlocksList.end(); iter++)
{
path.clear();
if(!((CBlock*)iter->second)->isTaken())
{
if(isBlockClaimable(((CBlock*)iter->second)->getLogicalPosition(),owner))
{
if(CV_GAME_MANAGER->getPathManager()->findPath(position,((CBlock*)iter->second)->getLogicalPosition(),&path))
{
if((path.size() < currpath.size()) || (currpath.size() == 0))
{
tempblock = (CBlock*)iter->second;
currpath = path;
}
}
}
}
}
if(tempblock)
{
tempblock->setTaken(true);
return tempblock;
}
return NULL;
}
CBlock *CLevelManager::getUnfortifiedBlock(GLubyte owner, cml::vector2i position)
{
CBlock *tempblock = NULL;
std::vector<cml::vector2i> path;
std::vector<cml::vector2i> currpath;
currpath.clear();
for (map<CBlock*,CBlock*>::iterator iter=unfortifiedBlocksList.begin(); iter!=unfortifiedBlocksList.end(); iter++)
{
path.clear();
if(!((CBlock*)iter->second)->isTaken())
{
if(isBlockClaimable(((CBlock*)iter->second)->getLogicalPosition(),owner))
{
if(CV_GAME_MANAGER->getPathManager()->findPath(position,((CBlock*)iter->second)->getLogicalPosition(),&path))