-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
ini.cpp
2241 lines (1770 loc) · 72.5 KB
/
ini.cpp
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
/*
Dune II - The Maker
Author : Stefan Hendriks
Contact: [email protected]
Website: http://dune2themaker.fundynamic.com
2001 - 2022 (c) code by Stefan Hendriks
*/
#include "ini.h"
#include "d2tmc.h"
#include "data/gfxdata.h"
#include "definitions.h"
#include "gamestates/cSelectYourNextConquestState.h"
#include "managers/cDrawManager.h" // TODO: an ini file reader should not depend on drawing code
#include "map/cMapCamera.h"
#include "map/cMapEditor.h"
#include "mentat/cAbstractMentat.h"
#include "player/cPlayer.h"
#include "utils/cLog.h"
#include "utils/common.h"
#include "utils/cSeedMapGenerator.h"
#include "gameobjects/units/cReinforcements.h"
#include <allegro.h>
#include <fmt/core.h>
#include <filesystem>
namespace fs=std::filesystem;
int INI_SectionType(char section[30], int last);
void INI_WordValueSENTENCE(char result[MAX_LINE_LENGTH], char value[256]);
int getHouseFromChar(char chunk[25]);
int getUnitTypeFromChar(char chunk[25]);
int INI_GetPositionOfCharacter(char result[MAX_LINE_LENGTH], char c);
class cReinforcements;
bool INI_Scenario_Section_Units(int iHumanID, bool bSetUpPlayers, const int *iPl_credits, const int *iPl_house,
const int *iPl_quota, const char *linefeed);
bool INI_Scenario_Section_Structures(int iHumanID, bool bSetUpPlayers, const int *iPl_credits, const int *iPl_house,
const int *iPl_quota, char *linefeed);
void INI_Scenario_Section_Reinforcements(int iHouse, const char *linefeed, cReinforcements* reinforcements);
void INI_Scenario_Section_MAP(int *blooms, int *fields, int wordtype, char *linefeed);
int INI_Scenario_Section_House(int wordtype, int iPlayerID, int *iPl_credits, int *iPl_quota, char *linefeed);
void INI_Scenario_Section_Basic(cAbstractMentat *pMentat, int wordtype, char *linefeed);
void INI_Scenario_SetupPlayers(int iHumanID, const int *iPl_credits, const int *iPl_house, const int *iPl_quota);
/*
Read a line in the INI file and put it into currentLine
*/
inline bool caseInsCharCompareN(char a, char b) {
return (toupper(a) == toupper(b));
}
bool caseInsCompare(const std::string &s1, const std::string &s2) {
return ((s1.size() == s2.size()) &&
equal(s1.begin(), s1.end(), s2.begin(), caseInsCharCompareN));
}
// Reads out an entire sentence and returns it
void INI_Sentence(FILE *f, char result[MAX_LINE_LENGTH]) {
char ch;
int pos = 0;
// clear out entire string
for (int i = 0; i < MAX_LINE_LENGTH; i++)
result[i] = '\0';
while ((feof(f) == 0) && ((ch = fgetc(f)) != '\n')) {
result[pos] = ch;
pos++;
// do not allow strings greater then 80 characters. This check prevents a crash for
// users who do exceed the limit.
if (pos > (MAX_LINE_LENGTH - 1))
break;
}
}
/*********************************************************************************/
// Reads out INPUT , will check for a [ at [0] and then checks till ], it will fill section[]
// with the chars in between. So : [MAP] -> section = 'MAP'. Use function INI_SectionType(..)
// to get the correct ID for that.
void INI_Section(char input[MAX_LINE_LENGTH], char section[30]) {
int pos = 0;
int end_pos = -1;
memset(section, '\0', strlen(section));
// check if the first character is a '['
if (input[0] == '[') {
pos = 1; // Begin at character 1
// find the ending ]
while (pos < (MAX_LINE_LENGTH - 1)) {
if (input[pos] == ']') {
end_pos = pos - 1;
break;
}
pos++;
}
if (end_pos > 1 && end_pos < 29) {
for (int wc = 0; wc < end_pos; wc++) {
section[wc] = input[wc + 1];
}
section[end_pos] = '\0'; // terminate string
}
}
}
// Reads out INPUT and will check for an '=' Everything at the left of the
// '=' IS a word and will be put in 'word[]'. Use function INI_WordType(char word[25]) to get
// the correct ID tag.
void INI_Word(char input[MAX_LINE_LENGTH], char word[30]) {
int word_pos = INI_GetPositionOfCharacter(input, '=');
memset(word, '\0', strlen(word));
if (word_pos > -1 && word_pos < 28) {
for (int wc = 0; wc < word_pos; wc++) {
word[wc] = input[wc];
}
word[word_pos] = '\0'; // terminate string
}
}
/**
* Return true when string "toFind" is in source string. Else return false.
*
* @param source
* @param toFind
* @return
*/
bool isInString(std::string source, std::string toFind) {
std::string::size_type loc = source.find(toFind, 0);
if (loc == 0) {
return true;
}
return false; // not found in string
}
std::string INI_SceneFileToScene(std::string scenefile) {
// wsa / data
if (isInString(scenefile, "HARVEST.WSA")) return "harvest";
if (isInString(scenefile, "IX.WSA")) return "ix";
if (isInString(scenefile, "SARDUKAR.WSA")) return "sardukar";
if (isInString(scenefile, "PALACE.WSA")) return "palace";
if (isInString(scenefile, "REPAIR.WSA")) return "repair";
if (isInString(scenefile, "HVYFTRY.WSA")) return "hvyftry";
if (isInString(scenefile, "HEADQRTS.WSA")) return "headqrts";
if (isInString(scenefile, "QUAD.WSA")) return "quad";
if (isInString(scenefile, "LTANK.WSA")) return "ltank";
logbook(fmt::format("Failed to map dune 2 scenefile [{}] to a d2tm scene file.", scenefile));
return "unknown";
}
int INI_StructureType(std::string structureName) {
if (isInString(structureName, "WINDTRAP")) return WINDTRAP;
if (isInString(structureName, "PALACE")) return PALACE;
if (isInString(structureName, "HEAVYFACTORY")) return HEAVYFACTORY;
if (isInString(structureName, "LIGHTFACTORY")) return LIGHTFACTORY;
if (isInString(structureName, "CONSTYARD")) return CONSTYARD;
if (isInString(structureName, "SILO")) return SILO;
if (isInString(structureName, "HIGHTECH")) return HIGHTECH;
if (isInString(structureName, "IX")) return IX;
if (isInString(structureName, "REPAIR")) return REPAIR;
if (isInString(structureName, "RADAR")) return RADAR;
if (isInString(structureName, "REFINERY")) return REFINERY;
if (isInString(structureName, "WOR")) return WOR;
if (isInString(structureName, "BARRACKS")) return BARRACKS;
if (isInString(structureName, "STARPORT")) return STARPORT;
if (isInString(structureName, "TURRET")) return TURRET;
if (isInString(structureName, "ROCKETTURRET")) return RTURRET;
if (isInString(structureName, "STARPORT")) return STARPORT;
if (isInString(structureName, "SLAB")) return SLAB1;
if (isInString(structureName, "4SLAB")) return SLAB4;
if (isInString(structureName, "WALL")) return WALL;
assert(false); // no recognition is fail.
return 0; // just in case some miracle happened, we need to go on and not crash everything.
}
// Reads out word[], checks structure type, and returns actual source-id
int INI_StructureType(char word[256]) {
std::string wordAsString(word);
return INI_StructureType(wordAsString);
}
// Reads out word[], does a string compare and returns type id
int INI_WordType(char word[25], int section) {
// char msg[255];
// memset(msg, 0, sizeof(msg));
// sprintf(msg, "Going to find word-type for [%s]", word);
// logbook(msg);
if (section == SEC_REGION) {
if (strcmp(word, "Region") == 0)
return WORD_REGION;
if (strcmp(word, "RegionConquer") == 0)
return WORD_REGIONCONQUER;
if (strcmp(word, "House") == 0)
return WORD_REGIONHOUSE;
if (strcmp(word, "Text") == 0)
return WORD_REGIONTEXT;
if (strcmp(word, "Select") == 0)
return WORD_REGIONSELECT;
return WORD_NONE;
}
if (section == INI_SCEN ||
section == INI_DESCRIPTION ||
section == INI_BRIEFING ||
section == INI_ADVICE ||
section == INI_LOSE ||
section == INI_WIN) {
if (strcmp(word, "Number") == 0)
return WORD_NUMBER;
if (strcmp(word, "Text") == 0)
return WORD_REGIONTEXT;
return WORD_NONE;
}
if (section == INI_SKIRMISH) {
if (strcmp(word, "Title") == 0)
return WORD_MAPNAME;
if (strcmp(word, "StartCell") == 0)
return WORD_STARTCELL;
}
if (section == INI_GAME) {
if (strcmp(word, "ModId") == 0)
return WORD_MODID;
} else if (section == INI_BASIC) {
if (strcmp(word, "CursorPos") == 0)
return WORD_FOCUS;
if (strcmp(word, "BriefPicture") == 0)
return WORD_BRIEFPICTURE;
if (strcmp(word, "WinFlags") == 0)
return WORD_WINFLAGS;
if (strcmp(word, "LoseFlags") == 0)
return WORD_LOSEFLAGS;
} else if (section >= INI_HOUSEATREIDES && section <= INI_HOUSEMERCENARY) {
if (strcmp(word, "Team") == 0)
return WORD_TEAM;
if (strcmp(word, "Credits") == 0)
return WORD_CREDITS;
if (strcmp(word, "Quota") == 0)
return WORD_QUOTA;
if (strcmp(word, "Brain") == 0)
return WORD_BRAIN;
//if (strcmp(word, "Skill") == 0)
//return WORD_SKILL;
if (strcmp(word, "House") == 0)
return WORD_HOUSE;
if (strcmp(word, "Focus") == 0)
return WORD_FOCUS;
}
/*
else if (section == INI_MENU)
{
if (strcmp(word, "TitleBitmap") == 0)
return WORD_TITLEBITMAP;
if (strcmp(word, "ClickSound") == 0)
return WORD_MENUCLICKSOUND;
}
else if (section == INI_MOD)
{
// Title of mod
if (strcmp(word, "Title") == 0)
return WORD_TITLE;
// Version of mod
if (strcmp(word, "Version") == 0)
return WORD_VERSION;
// Dir of mod
if (strcmp(word, "Dir") == 0)
return WORD_DIR;
}
else if (section == INI_SIDEBAR)
{
if (strcmp(word, "ColorRed") == 0)
return WORD_RED;
if (strcmp(word, "ColorBlue") == 0)
return WORD_BLUE;
if (strcmp(word, "ColorGreen") == 0)
return WORD_GREEN;
}
else if (section == INI_MOUSE)
{
// normal mouse
if (strcmp(word, "Normal") == 0)
return WORD_MOUSENORMAL;
// cannot move
if (strcmp(word, "CannotMove") == 0)
return WORD_MOUSENOMOVE;
// Move
if (strcmp(word, "Move") == 0)
return WORD_MOUSEMOVE;
// Attack
if (strcmp(word, "Attack") == 0)
return WORD_MOUSEATTACK;
// Deploy
if (strcmp(word, "Deploy") == 0)
return WORD_MOUSEDEPLOY;
}*/
else if (section == INI_MAP) {
// When reading [MAP], interpet the 'width' and 'height' for default width and height
// for the Map Editor
// Map width
if (strcmp(word, "Width") == 0)
return WORD_MAPWIDTH;
// Map heigth
if (strcmp(word, "Height") == 0)
return WORD_MAPHEIGHT;
// Dune II scens have a seed
if (strcmp(word, "Seed") == 0)
return WORD_MAPSEED;
// Dune II scens have spice blooms
if (strcmp(word, "Bloom") == 0)
return WORD_MAPBLOOM;
// Dune II scens have spice blooms
if (strcmp(word, "Field") == 0)
return WORD_MAPFIELD;
} else if (section == INI_BULLETS) {
// Bitmap
if (strcmp(word, "Bitmap") == 0)
return WORD_BITMAP;
// Dead Animation Bitmap
if (strcmp(word, "BitmapExplosion") == 0)
return WORD_BITMAP_DEAD;
// Bitmap width
if (strcmp(word, "BitmapWidth") == 0)
return WORD_BITMAP_WIDTH;
// Frames
if (strcmp(word, "BitmapFrames") == 0)
return WORD_BITMAP_FRAMES;
// Dead frames
if (strcmp(word, "BitmapExplFrames") == 0)
return WORD_BITMAP_DEADFRAMES;
// Damage
if (strcmp(word, "Damage") == 0)
return WORD_DAMAGE;
// Definition
if (strcmp(word, "Definition") == 0)
return WORD_DEFINITION;
if (strcmp(word, "Sound") == 0)
return WORD_SOUND;
} else if (section == INI_STRUCTURES) {
// HitPoints
if (strcmp(word, "HitPoints") == 0)
return WORD_HITPOINTS;
// 'getting fixed 'HitPoints
if (strcmp(word, "FixPoints") == 0)
return WORD_FIXHP;
// Power drain
if (strcmp(word, "PowerDrain") == 0)
return WORD_POWERDRAIN;
// Power give
if (strcmp(word, "PowerGive") == 0)
return WORD_POWERGIVE;
// Cost
if (strcmp(word, "Cost") == 0)
return WORD_COST;
// Build time
if (strcmp(word, "BuildTime") == 0)
return WORD_BUILDTIME;
} else if (section == INI_UNITS) {
// Bitmap
if (strcmp(word, "Bitmap") == 0)
return WORD_BITMAP;
// TOP Bitmap
if (strcmp(word, "BitmapTop") == 0)
return WORD_BITMAP_TOP;
// ICON Bitmap
if (strcmp(word, "Icon") == 0)
return WORD_ICON;
// WIDTH and HEIGHT of a bitmap
if (strcmp(word, "BitmapWidth") == 0)
return WORD_BITMAP_WIDTH;
// Bitmap Height
if (strcmp(word, "BitmapHeight") == 0)
return WORD_BITMAP_HEIGHT;
// HitPoints
if (strcmp(word, "HitPoints") == 0)
return WORD_HITPOINTS;
// Appetite
if (strcmp(word, "Appetite") == 0)
return WORD_APPETITE;
// Cost
if (strcmp(word, "Cost") == 0)
return WORD_COST;
// Bullet Type
if (strcmp(word, "BulletType") == 0)
return WORD_BULLETTYPE;
// Move speed
if (strcmp(word, "MoveSpeed") == 0)
return WORD_MOVESPEED;
// Turn speed
if (strcmp(word, "TurnSpeed") == 0)
return WORD_TURNSPEED;
// Attack frequency (todo: wording, it should be more like "delay" or "fireRate")
if (strcmp(word, "AttackFrequency") == 0)
return WORD_ATTACKFREQ;
// Next Attack frequency (if applicable) (todo: wording, it should be more like "delay" or "fireRate")
if (strcmp(word, "NextAttackFrequency") == 0)
return WORD_NEXTATTACKFREQ;
// Sight
if (strcmp(word, "Sight") == 0)
return WORD_SIGHT;
// Range
if (strcmp(word, "Range") == 0)
return WORD_RANGE;
// Build time
if (strcmp(word, "BuildTime") == 0)
return WORD_BUILDTIME;
// Description
if (strcmp(word, "Description") == 0)
return WORD_DESCRIPTION;
// BOOLEANS
if (strcmp(word, "IsHarvester") == 0)
return WORD_ISHARVESTER;
if (strcmp(word, "FireTwice") == 0)
return WORD_FIRETWICE;
if (strcmp(word, "IsInfantry") == 0)
return WORD_ISINFANTRY;
if (strcmp(word, "Squishable") == 0)
return WORD_ISSQUISHABLE;
if (strcmp(word, "CanSquish") == 0)
return WORD_CANSQUISH;
if (strcmp(word, "IsAirborn") == 0)
return WORD_ISAIRBORN;
if (strcmp(word, "AbleToCarry") == 0)
return WORD_ABLETOCARRY;
if (strcmp(word, "FreeRoam") == 0)
return WORD_FREEROAM;
// what structure type produces this kind of unit?
if (strcmp(word, "Producer") == 0) return WORD_PRODUCER;
// HARVESTER
if (strcmp(word, "MaxCredits") == 0) return WORD_HARVESTLIMIT;
if (strcmp(word, "HarvestSpeed") == 0) return WORD_HARVESTSPEED;
if (strcmp(word, "HarvestAmount") == 0) return WORD_HARVESTAMOUNT;
}
else if (section == INI_STRUCTURES) {
if (strlen(word) > 1) {
// Structure properties
if (strcmp(word, "PreBuild") == 0)
return WORD_PREBUILD;
if (strcmp(word, "Description") == 0)
return WORD_DESCRIPTION;
if (strcmp(word, "Power") == 0)
return WORD_POWER; // What power it takes
} else
return WORD_NONE;
} else if (section == INI_HOUSES) {
// each house has properties..
if (strcmp(word, "ColorR") == 0)
return WORD_RED;
if (strcmp(word, "ColorG") == 0)
return WORD_GREEN;
if (strcmp(word, "ColorB") == 0)
return WORD_BLUE;
// and specific stuff:
if (strcmp(word, "FirePower") == 0)
return WORD_FIREPOWER;
if (strcmp(word, "FireRate") == 0)
return WORD_FIRERATE;
if (strcmp(word, "StructPrice") == 0)
return WORD_STRUCTPRICE;
if (strcmp(word, "UnitPrice") == 0)
return WORD_UNITPRICE;
if (strcmp(word, "Speed") == 0)
return WORD_SPEED;
if (strcmp(word, "BuildSpeed") == 0)
return WORD_BUILDSPEED;
if (strcmp(word, "HarvestSpeed") == 0)
return WORD_HARVESTSPEED;
if (strcmp(word, "DumpSpeed") == 0)
return WORD_DUMPSPEED;
}
// char msg[255];
// memset(msg, 0, sizeof(msg));
// sprintf(msg, "Could not find word-type for [%s]", word);
// logbook(msg);
return WORD_NONE;
}
// Scenario section types
int SCEN_INI_SectionType(char section[30]) {
if (strcmp(section, "UNITS") == 0)
return INI_UNITS;
if (strcmp(section, "SKIRMISH") == 0)
return INI_SKIRMISH;
if (strcmp(section, "STRUCTURES") == 0)
return INI_STRUCTURES;
if (strcmp(section, "REINFORCEMENTS") == 0)
return INI_REINFORCEMENTS;
if (strcmp(section, "MAP") == 0)
return INI_MAP;
if (strcmp(section, "BASIC") == 0)
return INI_BASIC;
if (strcmp(section, "Atreides") == 0)
return INI_HOUSEATREIDES;
if (strcmp(section, "Ordos") == 0)
return INI_HOUSEORDOS;
if (strcmp(section, "Harkonnen") == 0)
return INI_HOUSEHARKONNEN;
if (strcmp(section, "Sardaukar") == 0)
return INI_HOUSESARDAUKAR;
if (strcmp(section, "Fremen") == 0)
return INI_HOUSEFREMEN;
if (strcmp(section, "Mercenary") == 0)
return INI_HOUSEMERCENARY;
return -1;
}
// GAME Section Types
int GAME_INI_SectionType(char section[30], int last) {
// if (strcmp(section, "BULLETS") == 0)
// return INI_BULLETS;
if (strcmp(section, "UNITS") == 0)
return INI_UNITS;
if (strcmp(section, "STRUCTURES") == 0)
return INI_STRUCTURES;
// When nothing found; we assume its just a new ID tag for some unit or structure
// Therefor we return the last known SECTION ID so we can assign the proper WORD ID's
return last;
}
// Reads out section[], does a string compare and returns type id
int INI_SectionType(char section[30], int last) {
if (strcmp(section, "MAP") == 0)
return INI_MAP;
if (strcmp(section, "SKIRMISH") == 0)
return INI_SKIRMISH;
if (strcmp(section, "DESCRIPTION") == 0)
return INI_DESCRIPTION;
if (strcmp(section, "SCEN") == 0)
return INI_SCEN;
if (strcmp(section, "BRIEFING") == 0)
return INI_BRIEFING;
if (strcmp(section, "WIN") == 0)
return INI_WIN;
if (strcmp(section, "LOSE") == 0)
return INI_LOSE;
if (strcmp(section, "ADVICE") == 0)
return INI_ADVICE;
if (strcmp(section, "HOUSES") == 0)
return INI_HOUSES;
if (strcmp(section, "UNITS") == 0)
return INI_UNITS;
if (strcmp(section, "STRUCTURES") == 0) {
alert("Structure Section found", section, "", "OK", nullptr, 13, 0);
return INI_STRUCTURES;
}
alert("No SECTION id found, assuming its an ID nested in section", section, "", "OK", nullptr, 13, 0);
// When nothing found; we assume its just a new ID tag for some unit or structure
// Therefor we return the last known SECTION ID so we can assign the proper WORD ID's
return last;
}
// Reads out 'result' and will return the value after the '='. Returns float.
// UGLY COPY/PASTE OF INI_WORDVALUEINT function, because we will completely
// rewrite this ini parsing abomination somewhere in the future.
float INI_WordValueFloat(char result[MAX_LINE_LENGTH], float defaultValue) {
int pos = 0;
int is_pos = -1;
while (pos < (MAX_LINE_LENGTH - 1)) {
if (result[pos] == '=') {
is_pos = pos;
break;
}
pos++;
}
if (is_pos > -1) {
// Whenever the IS (=) position is known, we make a number out of 'IS_POS' till the next empty
// space.
int end_pos = -1;
while (pos < (MAX_LINE_LENGTH - 1)) {
if (result[pos] == '\0') {
end_pos = pos;
break;
}
pos++;
}
// End position found!
if (end_pos > -1) {
// We know the END position. We will use that piece of string to read out a number.
char number[10];
// clear out entire string
for (int i = 0; i < 10; i++)
number[i] = '\0';
// Copy the part to 'number', Make sure we won't get outside the array of the character.
int cp = is_pos + 1;
int c = 0;
while (cp < end_pos) {
number[c] = result[cp];
c++;
cp++;
if (c > 9)
break;
}
return atof(number);
}
// nothing here, so we return nullptr at the end
}
return defaultValue; // no value found, return this
}
// Reads out 'result' and will return the value after the '='. Returns integer.
// For CHAR returns see "INI_WordValueCHAR(char result[80]);
int INI_WordValueINT(char result[MAX_LINE_LENGTH]) {
int pos = 0;
int is_pos = -1;
while (pos < (MAX_LINE_LENGTH - 1)) {
if (result[pos] == '=') {
is_pos = pos;
break;
}
pos++;
}
if (is_pos > -1) {
// Whenever the IS (=) position is known, we make a number out of 'IS_POS' till the next empty
// space.
int end_pos = -1;
while (pos < (MAX_LINE_LENGTH - 1)) {
if (result[pos] == '\0') {
end_pos = pos;
break;
}
pos++;
}
// End position found!
if (end_pos > -1) {
// We know the END position. We will use that piece of string to read out a number.
char number[10];
// clear out entire string
for (int i = 0; i < 10; i++)
number[i] = '\0';
// Copy the part to 'number', Make sure we won't get outside the array of the character.
int cp = is_pos + 1;
int c = 0;
while (cp < end_pos) {
number[c] = result[cp];
c++;
cp++;
if (c > 9)
break;
}
return atoi(number);
}
// nothing here, so we return nullptr at the end
}
return 0; // No value, return 0
}
void INI_WordValueSENTENCE(char result[MAX_LINE_LENGTH], char value[256]) {
int pos = 0;
int is_pos = -1;
// clear out entire string
memset(value, 0, strlen(value));
for (int i = 0; i < MAX_LINE_LENGTH; i++)
value[i] = '\0';
while (pos < (MAX_LINE_LENGTH - 1)) {
if (result[pos] == '"') {
is_pos = pos;
break;
}
pos++;
}
if (is_pos > -1) {
// Whenever the IS (=) position is known, we make a number out of 'IS_POS' till the next empty
// space.
int end_pos = -1;
pos++;
while (pos < (MAX_LINE_LENGTH - 1)) {
if (result[pos] == '"') {
end_pos = pos;
break;
}
pos++;
}
// End position found!
if (end_pos > -1) {
// We know the END position. We will use that piece of string to read out a number.
// Copy the part to 'value', Make sure we won't get outside the array of the character.
int cp = is_pos + 1;
int c = 0;
while (cp < end_pos) {
value[c] = result[cp];
c++;
cp++;
if (c > 254)
break;
}
}
}
}
int INI_GetPositionOfCharacter(char result[MAX_LINE_LENGTH], char c) {
std::string resultString(result);
return resultString.find_first_of(c, 0);
}
/**
* Return the part after the = sign as string.
*
* @param result
* @return
*/
std::string INI_WordValueString(char result[MAX_LINE_LENGTH]) {
std::string resultAsString(result);
int isPos = INI_GetPositionOfCharacter(result, '=');
return resultAsString.substr(isPos + 1);
}
// Reads out 'result' and will return the value after the '='. Returns nothing but will put
// the result in 'value[25]'. Max argument may be 256 characters!
void INI_WordValueCHAR(char result[MAX_LINE_LENGTH], char value[256]) {
int pos = 0;
int is_pos = -1;
// clear out entire string
memset(value, 0, strlen(value));
for (int i = 0; i < 256; i++) {
value[i] = '\0';
}
while (pos < (MAX_LINE_LENGTH - 1)) {
if (result[pos] == '=') {
is_pos = pos;
break;
}
pos++;
}
if (is_pos > -1) {
// Whenever the IS (=) position is known, we make a number out of 'IS_POS' till the next empty
// space.
int end_pos = -1;
while (pos < (MAX_LINE_LENGTH - 1)) {
if (result[pos] == '\0' || result[pos] == '\n') {
end_pos = (pos - 1);
break;
}
pos++;
}
// End position found!
if (end_pos > -1) {
// We know the END position. We will use that piece of string to read out a number.
// Copy the part to 'value', Make sure we won't get outside the array of the character.
int cp = is_pos + 1;
int c = 0;
while (cp <= end_pos) {
value[c] = result[cp];
c++;
cp++;
if (c > 80) {
break;
}
}
}
}
}
// Reads out 'result' and will return TRUE when its 'TRUE' or FALSE when its 'FALSE' , else
// returns nullptr
bool INI_WordValueBOOL(char result[MAX_LINE_LENGTH]) {
// use INI_WordValueCHAR to know if its 'true'
char val[256];
INI_WordValueCHAR(result, val);
// When its TRUE , return true
return caseInsCompare(val, "true");
}
// return ID of structure
int getStructureTypeFromChar(char *structure) {
if (strcmp(structure, "Const Yard") == 0)
return CONSTYARD;
if (strcmp(structure, "Palace") == 0)
return PALACE;
if (strcmp(structure, "Heavy Fctry") == 0)
return HEAVYFACTORY;
if (strcmp(structure, "Light Fctry") == 0)
return LIGHTFACTORY;
if (strcmp(structure, "Windtrap") == 0)
return WINDTRAP;
if (strcmp(structure, "Spice Silo") == 0)
return SILO;
if (strcmp(structure, "Hi-Tech") == 0)
return HIGHTECH;
if (strcmp(structure, "IX") == 0)
return IX;
if (strcmp(structure, "Repair") == 0)
return REPAIR;
if (strcmp(structure, "Outpost") == 0)
return RADAR;
if (strcmp(structure, "Refinery") == 0)
return REFINERY;
if (strcmp(structure, "WOR") == 0)
return WOR;
if (strcmp(structure, "Barracks") == 0)
return BARRACKS;
if (strcmp(structure, "Starport") == 0)
return STARPORT;
if (strcmp(structure, "Turret") == 0)
return TURRET;
if (strcmp(structure, "R-Turret") == 0)
return RTURRET;
logbook("Could not find structure:");
logbook(structure);
return CONSTYARD;
}
/**