This repository has been archived by the owner on Nov 11, 2022. It is now read-only.
/
luaP.cpp
2223 lines (1997 loc) · 71.9 KB
/
luaP.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
///
//@module LuaPlugin
//@author youneuoy
//@license GPL-3.0
#include "luaP.h"
#include "plugData.h"
std::vector<std::string> luaP::logS;
static int ourP(lua_State* L) {
int n = lua_gettop(L); /* number of arguments */
int i;
lua_getglobal(L, "tostring");
for (i = 1; i <= n; i++) {
std::string newS;
const char* s;
lua_pushvalue(L, -1); /* function to be called */
lua_pushvalue(L, i); /* value to print */
lua_call(L, 1, 1);
s = lua_tostring(L, -1); /* get result */
if (s == NULL)
return luaL_error(L, LUA_QL("tostring") " must return a string to "
LUA_QL("print"));
if (i > 1)
{
newS += '\t';
//fputs("\t", stdout);
}
newS += s;
luaP::logS.push_back(newS);
//fputs(s, stdout);
lua_pop(L, 1); /* pop result */
}
//luaP::logS += "\n";
//fputs("\n", stdout);
return 0;
}
void replaceAll2(std::string& s, const std::string& search, const std::string& replace) {
for (size_t pos = 0; ; pos += replace.length())
{
pos = s.find(search, pos);
if (pos == std::string::npos) break;
s.erase(pos, search.length());
s.insert(pos, replace);
}
}
void luaP::runScriptS(std::string* script)
{
const char* retS = nullptr;
auto funcResult = luaState.script(*script);
if (!funcResult.valid())
{
sol::error luaError = funcResult;
luaP::logS.push_back(luaError.what());
}
return;
}
bool luaP::checkVar(const char* gName, int variable)
{
sol::optional<int> scriptVar = luaState[gName];
if (scriptVar)
{
return scriptVar.value() == variable;
}
return false;
}
sol::state* luaP::init(std::string& luaFilePath, std::string& modPath)
{
struct
{
sol::table M2TWEOPTable;
sol::table stratmapTable;
//this inside stratmap table
sol::table objectsTable;
sol::table cameraTable;
sol::table gameTable;
sol::table gameUITable;
}tables;
struct
{
sol::usertype<uiElement>uiElement;
sol::usertype<unit>unit;
sol::usertype<general>character;
sol::usertype<generalCharacterictics>namedCharacter;
sol::usertype<anchillary>ancillary;
sol::usertype<traitContainer>traitContainerT;
sol::usertype<EduEntry>EduEntry;
sol::usertype<factionStruct>factionStruct;
sol::usertype<factionStratMapDescrS>factionStratMapStruct;
sol::usertype<watchTowerStruct>watchtowerStruct;
sol::usertype<fortStruct>fortStruct;
sol::usertype<portBuildingStruct>portStruct;
sol::usertype<portDockStrat>dockStruct;
sol::usertype<settlementStruct>settlementStruct;
sol::usertype<guild>guild;
sol::usertype<resStrat>tradeResource;
sol::usertype<stackStruct>stackStruct;
sol::usertype<building>building;
sol::usertype<buildingsQueue>buildingsQueue;
sol::usertype<buildingInQueue>buildingInQueue;
sol::usertype<siegeS>siege;
sol::usertype<building_data>building_data;
sol::usertype<buildingDrawInfo>buildingDrawInfo;
}types;
luaState = {};
luaPath = modPath + "\\youneuoy_Data\\plugins\\lua";
luaState.open_libraries(sol::lib::base, sol::lib::package, sol::lib::coroutine, sol::lib::string, sol::lib::os, sol::lib::math, sol::lib::table, sol::lib::bit32, sol::lib::io, sol::lib::ffi, sol::lib::jit, sol::lib::debug);
std::string packagePS = "package.path = '";
packagePS += modPath;
packagePS += "\\youneuoy_Data\\plugins\\lua\\?.lua;'";
packagePS += "..'";
packagePS += modPath;
packagePS += "\\youneuoy_Data\\plugins\\lua\\redist\\?.lua;'..package.path ;";
packagePS += "package.cpath = '";
packagePS += modPath;
packagePS += "\\youneuoy_Data\\plugins\\lua\\redist\\?.dll;'..package.cpath ;";
std::string f = "\\";
std::string r = "/";
replaceAll2(packagePS, f, r);
luaState["print"] = &ourP;
auto funcResult = luaState.script(packagePS.c_str());
if (!funcResult.valid())
{
sol::error luaError = funcResult;
MessageBoxA(NULL, luaError.what(), "Lua exception!", NULL);
return nullptr;
}
sol::load_result fileRes = luaState.load_file(luaFilePath);
if (!fileRes.valid()) { // This checks the syntax of your script, but does not execute it
sol::error luaError = fileRes;
MessageBoxA(NULL, luaError.what(), "Lua exception!", NULL);
return nullptr;
}
sol::protected_function_result result1 = fileRes(); // this causes the script to execute
if (!result1.valid()) {
sol::error luaError = result1;
MessageBoxA(NULL, luaError.what(), "Lua exception!", NULL);
return nullptr;
}
///M2TWEOP
//@section m2tweopTable
/***
Basic M2TWEOP table
@tfield getModPath getModPath
@tfield getPluginPath getPluginPath
@tfield loadTexture loadTexture
@tfield unloadTexture unloadTexture
@tfield setAncillariesLimit setAncillariesLimit
@tfield unlockGameConsoleCommands unlockGameConsoleCommands
@tfield setMaxBgSize setMaxBgSize
@tfield toggleUnitsBMapHighlight toggleUnitsBMapHighlight
@tfield setReligionsLimit setReligionsLimit
@tfield isTileFree isTileFree
@tfield getTileRegionID getTileRegionID
@tfield getRegionOwner getRegionOwner
@tfield setEDUUnitsSize setEDUUnitsSize
@table M2TWEOP
*/
tables.M2TWEOPTable = luaState.create_table("M2TWEOP");
/***
Function to return the path to the mod folder, starts from the drive not the game folder.
@function M2TWEOP.getModPath
@treturn string mod path
@usage
mPath=M2TWEOP.getModPath();
print(mPath);
*/
tables.M2TWEOPTable.set_function("getModPath", &m2tweopHelpers::getModPath);
/***
Function to return the path to the plugin (location of your LUA files).
@function M2TWEOP.getPluginPath
@treturn string plugin path
@usage
plPath=M2TWEOP.getPluginPath();
print(plPath);
*/
tables.M2TWEOPTable.set_function("getPluginPath", &m2tweopHelpers::getLuaPath);
/***
Load d3d texture
@function M2TWEOP.loadTexture
@tparam string path full path to texture
@treturn int x size of the image
@treturn int y size of the image
@treturn int id of the image
@usage
local testImage={x=0,y=0,img=nil};
testImage.x, testImage.y, testImage.img=M2TWEOP.loadTexture(M2TWEOP.getModPath().."/youneuoy_textures/test.dds");
*/
tables.M2TWEOPTable.set_function("loadTexture", &m2tweopHelpers::loadTextureToGame);
/***
Unload d3d texture
@function M2TWEOP.unloadTexture
@tparam int id of the image
@usage
local testImage={x=0,y=0,img=nil};
testImage.x, testImage.y, testImage.img=M2TWEOP.loadTexture(M2TWEOP.getModPath().."/youneuoy_textures/test.dds");
M2TWEOP.unloadTexture(testImage.img);
*/
tables.M2TWEOPTable.set_function("unloadTexture", &m2tweopHelpers::unloadTextureFromGame);
/***
Sets the limit of ancillaries per character on the stratmap.
@function M2TWEOP.setAncillariesLimit
@tparam int newLimit default: 8, maximum: 127
@usage
M2TWEOP.setAncillariesLimit(15);
*/
tables.M2TWEOPTable.set_function("setAncillariesLimit", &m2tweopHelpers::setAncLimit);
/***
Unlocks all console commands, also allows the use of the 'control' command to change factions in singleplayer campaigns.
@function M2TWEOP.unlockGameConsoleCommands
@usage
M2TWEOP.unlockGameConsoleCommands();
*/
tables.M2TWEOPTable.set_function("unlockGameConsoleCommands", &m2tweopHelpers::unlockGameConsoleCommands);
/***
Sets the maximum amount of soldiers a general's bodyguard unit can replenish to.
@function M2TWEOP.setMaxBgSize
@tparam int newSize default: 77, maximum: 255 (Huge unit size).
@usage
M2TWEOP.setMaxBgSize(222);
*/
tables.M2TWEOPTable.set_function("setMaxBgSize", &m2tweopHelpers::setMaxBgSize);
/***
Sets the new maximum soldier count.
@function M2TWEOP.setEDUUnitsSize
@tparam int minSize maximum: 300
@tparam int maxSize maximum: 300
@usage
M2TWEOP.setEDUUnitsSize(1,300);
*/
tables.M2TWEOPTable.set_function("setEDUUnitsSize", &m2tweopHelpers::setEDUUnitsSize);
/***
* Sets the new maximum amount of building levels within a chain.
* @function M2TWEOP.setBuildingChainLimit
* @tparam int limit default: 9
* @usage
* M2TWEOP.setBuildingChainLimit(12);
*/
tables.M2TWEOPTable.set_function("setBuildingChainLimit", &m2tweopHelpers::setBuildingChainLimit);
/***
* Sets which level of castle converts to which level of city.
* @function M2TWEOP.setConversionLvlFromCastle
* @tparam int castleLvl 0-5
* @tparam int convertToLvl 0-6, 6 means conversion from that level is disabled
* @usage
* M2TWEOP.setConversionLvlFromCastle(3,3)
*/
tables.M2TWEOPTable.set_function("setConversionLvlFromCastle", &m2tweopHelpers::setConversionLvlFromCastle);
/***
* Sets which level of city converts to which level of castle.
* @function M2TWEOP.setConversionLvlFromCity
* @tparam int cityLvl 0-5
* @tparam int convertToLvl 0-6, 6 means conversion from that level is disabled
* @usage
* M2TWEOP.setConversionLvlFromCity(3,3)
*/
tables.M2TWEOPTable.set_function("setConversionLvlFromCity", &m2tweopHelpers::setConversionLvlFromCity);
/***
* Sets the minimum number of turns until the next guild offer after a rejection by the player.
* @function M2TWEOP.setGuildCooldown
* @tparam int turns default: 10
* @usage
* M2TWEOP.setGuildCooldown(5)
*/
tables.M2TWEOPTable.set_function("setGuildCooldown", &m2tweopHelpers::setGuildCooldown);
/***
Toggle the highlighting of units on the tactical map (Currently broken!).
@function M2TWEOP.toggleUnitsBMapHighlight
@usage
M2TWEOP.toggleUnitsBMapHighlight();
*/
tables.M2TWEOPTable.set_function("toggleUnitsBMapHighlight", &m2tweopHelpers::toggleUnitsBMapHighlight);
/***
Set the maximum number of religions in the mod (per descr_religions.txt)
@function M2TWEOP.setReligionsLimit
@tparam int newLimit maximum: 127
@usage
M2TWEOP.setReligionsLimit(25);
*/
tables.M2TWEOPTable.set_function("setReligionsLimit", &m2tweopHelpers::seReligionsLimit);
/***
Checks if a tile is free.
@function M2TWEOP.isTileFree
@tparam int X coordinate of the tile.
@tparam int Y coordinate of the tile.
@return boolean isFree
@usage
M2TWEOP.isTileFree(55,25);
*/
tables.M2TWEOPTable.set_function("isTileFree", &m2tweopHelpers::isTileFree);
/***
Get the RegionID of a tile.
@function M2TWEOP.getTileRegionID
@tparam int x
@tparam int y
@treturn int regionID
@usage
local regionID=M2TWEOP.getTileRegionID(55,25);
*/
tables.M2TWEOPTable.set_function("getTileRegionID", &m2tweopHelpers::getTileRegionID);
/***
Get the owner of a region by RegionID.
@function M2TWEOP.getRegionOwner
@tparam int regionID
@treturn factionStruct owner
@usage
local regionID=M2TWEOP.getTileRegionID(55,25);
local ownerFac=M2TWEOP.getRegionOwner(regionID);
*/
tables.M2TWEOPTable.set_function("getRegionOwner", &m2tweopHelpers::getRegionOwner);
/// gameSTDUITable
//@section gameSTDUITable
/***
Basic gameSTDUI table
@tfield getUiElement getUiElement
@table gameSTDUI
*/
tables.gameUITable = luaState.create_table("gameSTDUI");
/***
Get a game UI element, element must be opened.
@function gameSTDUI.getUiElement
@tparam string elementName
@treturn uiElementStruct element
@usage
function analyzeScroll(scrollName)
local scroll, uiList = gameSTDUI.getUiElement(scrollName), "UI elements of scroll: "..scrollName
if scroll ~= nil then
for i = 0, scroll.subElementsNum - 1, 1 do
uiList = uiList.."\n\t"..i.." "..scroll:getSubElement(i).elementName
end
print(uiList)
end
end
*/
tables.gameUITable.set_function("getUiElement", &gameSTDUIHelpers::getUiElement);
///uiElementStruct
//@section uiElementStructTable
/***
Basic uiElementStruct table
@tfield string elementName
@tfield int xSize
@tfield int ySize
@tfield int xPos
@tfield int yPos
@tfield int subElementsNum
@tfield getSubElement getSubElement
@tfield execute execute
@table uiElementStruct
*/
types.uiElement = luaState.new_usertype<uiElement>("uiElementStruct");
types.uiElement.set("elementName", sol::property(
&gameSTDUIHelpers::getUIElementName));
types.uiElement.set("xSize", &uiElement::xSize);
types.uiElement.set("ySize", &uiElement::ySize);
types.uiElement.set("xPos", &uiElement::xPos);
types.uiElement.set("yPos", &uiElement::yPos);
types.uiElement.set("subElementsNum", &uiElement::subElementsNum);
/***
Get a subelement of an UI element using the index.
@function gameSTDUI.getSubElement
@tparam int index Starts from 0.
@treturn uiElementStruct subelement
@usage
local financeScroll = gameSTDUI.getUiElement("finance_scroll");
local subElement1 = financeScroll:getSubElement(5);
*/
types.uiElement.set("getSubElement", &gameSTDUIHelpers::getSubElement);
/***
execute standard game UI element, use only for buttons
@function uiElementStruct:execute
@usage
local financeScroll = gameSTDUI.getUiElement("finance_scroll");
--at index 5 we have faction_listviews_button
local subElement1 = financeScroll:getSubElement(5);
subElement1:execute();
*/
types.uiElement.set("execute", &gameSTDUIHelpers::useUiElement);
///Strat Map Objects
//@section objectsTable
/***
Basic stratmap.objects table
@tfield addModelToGame addModelToGame
@tfield setModel setModel
@tfield replaceTile replaceTile
@table stratmap.objects
tables.objectsTable = luaState.create_table();
*/
/***
Add new cas stratmodel to game
@function objects.addModelToGame
@tparam string modelPath relative(to modfolder) path
@tparam int modelId model id
@usage
stratmap.objects.addModelToGame("data/models_strat/residences/invisible.CAS",1);
*/
tables.objectsTable.set_function("addModelToGame", &objectsHelpers::addModelToGame);
/***
Set the strategy model for object at specified coordinates, works only for supported object types
@function objects.setModel
@tparam int xCoord
@tparam int yCoord
@tparam int modelId used for: watchtower, resource, settlement, fort, port
@tparam int modelId2 used for: fort wall (use fort coords), dock (use port coords)
@usage
stratmap.objects.addModelToGame("data/models_strat/residences/invisible.CAS",1);
stratmap.objects.setModel(288,257,1,1);
*/
tables.objectsTable.set_function("setModel", sol::overload(&objectsHelpers::setModel,
&objectsHelpers::setModelOneVar));
/***
Replace custom tile. Change custom battlefield for coordinates.
@function objects.replaceTile
@tparam string label
@tparam int xCoord
@tparam int yCoord
@tparam string filename
@tparam string weather
@tparam string dayTime
@usage
stratmap.objects.replaceTile("Helms-Deep_Province",167,158,"hornburg_amb.wfc","clear","midday");
*/
tables.objectsTable.set_function("replaceTile", &objectsHelpers::replaceTile);
///Camera
//@section cameraTable
/***
Basic stratmap.camera table
@tfield move move
@tfield jump jump
@tfield zoom zoom
@table stratmap.camera
*/
tables.cameraTable = luaState.create_table();
/***
Slow move camera to tile
@function camera.move
@tparam int xCoord
@tparam int yCoord
@usage
stratmap.camera.move(1,2);
*/
tables.cameraTable.set_function("move", &cameraHelpers::moveStratCamera);
/***
Fast move camera to tile
@function camera.jump
@tparam int xCoord
@tparam int yCoord
@usage
stratmap.camera.jump(1,2);
*/
tables.cameraTable.set_function("jump", &cameraHelpers::snapStratCamera);
/***
Set zoom of stratcamera
@function camera.zoom
@tparam float distance
@usage
stratmap.camera.zoom(0.12);
*/
tables.cameraTable.set_function("zoom", &cameraHelpers::zoomStratCamera);
///Game
//@section gameTable
/***
Basic stratmap.game table
@tfield getFactionsCount getFactionsCount
@tfield getFaction getFaction
@tfield createCharacterByString createCharacterByString
@tfield createArmy createArmy
@tfield createArmyInSettlement createArmyInSettlement
@tfield getScriptCounter getScriptCounter
@tfield setScriptCounter setScriptCounter
@tfield callConsole callConsole
@table stratmap.game
*/
tables.gameTable = luaState.create_table();
/***
Call m2tw console command
@function game.callConsole
@treturn string error note: string can be empty but not nil
@usage
function onCharacterSelected(selectedChar)
local err = stratmap.game.callConsole("add_money", "2321")
print(err)
end
*/
tables.gameTable.set_function("callConsole", &gameHelpers::callConsole);
/***
Get factions number
@function game.getFactionsCount
@treturn int facNumber number of factions
@usage
local facNum=stratmap.game.getFactionsCount();
*/
tables.gameTable.set_function("getFactionsCount", &gameHelpers::getFactionsCount);
/***
Get faction with index
@function game.getFaction
@tparam int index
@treturn factionStruct faction
@usage
faction=stratmap.game.getFaction(2);
*/
tables.gameTable.set_function("getFaction", &gameHelpers::getFaction);
/***
Get guild with index
@function game.getGuild
@tparam int index
@treturn guild guild
@usage
ourGuild=stratmap.game.getGuild(1);
*/
tables.gameTable.set_function("getGuild", &gameHelpers::getGuild);
/***
Create character at coords
@function game.createCharacterByString
@tparam string type
@tparam factionStruct faction
@tparam int age
@tparam string name
@tparam string name2
@tparam int subFaction
@tparam string portrait_custom cannot be nil
@tparam int xCoord
@tparam int yCoord
@treturn character newCharacter
@usage
newCharacter=stratmap.game.createCharacterByString("named character",stratmap.game.getFaction(0),18,"Name1","Name2",31,"custom_portrait_name",character.character.xCoord+5,character.character.yCoord);
*/
tables.gameTable.set_function("createCharacterByString", &gameHelpers::createCharacter);
/***
Create army for character
@function game.createArmy
@tparam character ourGeneral
@treturn stackStruct army
@usage
army=stratmap.game.createArmy(gen);
*/
tables.gameTable.set_function("createArmy", &gameHelpers::createArmy);
/***
Create army in settlement (don't need character)
@function game.createArmyInSettlement
@tparam settlementStruct settlement
@treturn stackStruct army
@usage
army=stratmap.game.createArmyInSettlement(sett);
*/
tables.gameTable.set_function("createArmyInSettlement", &gameHelpers::createArmyInSettlement);
/***
Get script counter value, works for counter and event\_counter
@function game.getScriptCounter
@tparam string counterName
@treturn bool isExist
@treturn int counterValue
@usage
isExist, counterValue = stratmap.game.getScriptCounter("SomeCounter")
*/
tables.gameTable.set_function("getScriptCounter", &gameHelpers::getScriptCounter);
/***
Set event\_counter value, does not work for counter, only event\_counter
@function game.setScriptCounter
@tparam string counterName
@tparam int value
@usage
stratmap.game.setScriptCounter("SomeCounter", 25)
*/
tables.gameTable.set_function("setScriptCounter", &gameHelpers::setScriptCounter);
///Stratmap
//@section stratmapTable
/***
Basic stratmap table
@tfield objects objects
@tfield camera camera
@tfield game game
@table stratmap
*/
tables.stratmapTable = luaState.create_table("stratmap");
tables.stratmapTable.set("objects", tables.objectsTable);
tables.stratmapTable.set("camera", tables.cameraTable);
tables.stratmapTable.set("game", tables.gameTable);
///Unit
//@section unitTable
/***
Unit table
@tfield eduEntry eduEntry
@tfield float movePoints
@tfield int soldierCountStratMap soldiers count. You can change it on stratmap and soldiers updated. Use @{setParams} if you need change several parameters at once.
@tfield int exp soldiers expierence. You can change it on stratmap and soldiers updated. Use @{setParams} if you need change several parameters at once.
@tfield int armourLVL soldiers armour. You can change it on stratmap and soldiers updated. Use @{setParams} if you need change several parameters at once.
@tfield int weaponLVL soldiers weapon. You can change it on stratmap and soldiers updated. Use @{setParams} if you need change several parameters at once.
@tfield int soldierCountStratMapMax better read only
@tfield int soldierCountBattleMap better read only
@tfield character character
@tfield stackStruct army
@tfield kill kill
@tfield setParams setParams change soldierCountStratMap, exp, armourLVL, weaponLVL at one time.
@tfield string alias
@table unit
*/
types.unit = luaState.new_usertype<unit>("unit");
types.unit.set("eduEntry", &unit::eduEntry);
types.unit.set("movePoints", sol::property(&unitHelpers::getMovepoints, &unitHelpers::setMovepoints));
types.unit.set("soldierCountStratMap", sol::property(&unitHelpers::getsoldierCountStratMap, &unitHelpers::setSoldiersCount));
types.unit.set("exp", sol::property(&unitHelpers::getExp, &unitHelpers::setExp));
types.unit.set("armourLVL", sol::property(&unitHelpers::getarmourLVL, &unitHelpers::setarmourLVL));
types.unit.set("weaponLVL", sol::property(&unitHelpers::getweaponLVL, &unitHelpers::setweaponLVL));
types.unit.set("soldierCountStratMapMax", &unit::numberMax);
types.unit.set("soldierCountBattleMap", &unit::numberTact);
types.unit.set("character", &unit::general);
types.unit.set("army", &unit::army);
/***
Kill this unit
@function unit:kill
@usage
unit:kill();
*/
types.unit.set_function("kill", &unitHelpers::killUnit);
/***
Set unit basic parameters
@function unit:setParams
@tparam int exp
@tparam int armor
@tparam int weapon
@usage
unit:setParams(0,0,0);
*/
types.unit.set_function("setParams", &unitHelpers::setUnitParams);
types.unit.set("alias", sol::property(&technicalHelpers::unitUniStringToStr, &technicalHelpers::setUnitUniStr));
///EduEntry
//@section eduEntryTable
/***
Basic eduEntry table
@tfield string Type do not set!
@tfield string Soldier no not set!
@tfield int Index do not set!
@tfield int UnitCreatedCounter do not set!
@tfield int SoldierCount
@tfield float Mass
@tfield float Width
@tfield float Height
@tfield bool haveAttributeLegio
@tfield float MoveSpeedMod
@tfield float UnitSpacingFrontToBackClose
@tfield float UnitSpacingSideToSideClose
@tfield float UnitSpacingFrontToBackLoose
@tfield float UnitSpacingSideToSideLoose
@tfield int StatHealth
@tfield int StatHealthAnimal
@tfield int StatHeat
@tfield int StatGround1
@tfield int StatGround2
@tfield int StatGround3
@tfield int StatGround4
@tfield int StatCost1
@tfield int StatCost2
@tfield int StatCost3
@tfield int StatCost4
@tfield int StatCost5
@tfield int StatCost6
@tfield int StatCost7
@tfield int StatCost8
@table eduEntry
*/
types.EduEntry = luaState.new_usertype<EduEntry>("eduEntry");
types.EduEntry.set("Type", sol::property(
&luaGetSetFuncs::getStringPropertyEDU<EduEntryStruct_Type>, &luaGetSetFuncs::setStringPropertyEDU<EduEntryStruct_Type>
));
types.EduEntry.set("Soldier", sol::property(
&luaGetSetFuncs::getStringPropertyEDU<EduEntryStruct_Soldier>, &luaGetSetFuncs::setStringPropertyEDU<EduEntryStruct_Soldier>
));
types.EduEntry.set("Index", &EduEntry::Index);
types.EduEntry.set("UnitCreatedCounter", &EduEntry::UnitCreatedCounter);
types.EduEntry.set("SoldierCount", &EduEntry::SoldierCount);
types.EduEntry.set("Mass", &EduEntry::Mass);
types.EduEntry.set("Width", &EduEntry::Width);
types.EduEntry.set("Height", &EduEntry::Height);
types.EduEntry.set("haveAttributeLegio", sol::property(&eopEduHelpers::haveAttributeLegioGet, &eopEduHelpers::haveAttributeLegioSet));
types.EduEntry.set("MoveSpeedMod", &EduEntry::MoveSpeedMod);
types.EduEntry.set("UnitSpacingFrontToBackClose", &EduEntry::UnitSpacingFrontToBackClose);
types.EduEntry.set("UnitSpacingSideToSideClose", &EduEntry::UnitSpacingSideToSideClose);
types.EduEntry.set("UnitSpacingFrontToBackLoose", &EduEntry::UnitSpacingFrontToBackLoose);
types.EduEntry.set("UnitSpacingSideToSideLoose", &EduEntry::UnitSpacingSideToSideLoose);
types.EduEntry.set("StatHealth", &EduEntry::StatHealth);
types.EduEntry.set("StatHealthAnimal", &EduEntry::StatHealthAnimal);
types.EduEntry.set("StatHeat", &EduEntry::StatHeat);
types.EduEntry.set("StatGround1", &EduEntry::StatGround1);
types.EduEntry.set("StatGround2", &EduEntry::StatGround2);
types.EduEntry.set("StatGround3", &EduEntry::StatGround3);
types.EduEntry.set("StatGround4", &EduEntry::StatGround4);
types.EduEntry.set("StatCost1", &EduEntry::StatCost1);
types.EduEntry.set("StatCost2", &EduEntry::StatCost2);
types.EduEntry.set("StatCost3", &EduEntry::StatCost3);
types.EduEntry.set("StatCost4", &EduEntry::StatCost4);
types.EduEntry.set("StatCost5", &EduEntry::StatCost5);
types.EduEntry.set("StatCost6", &EduEntry::StatCost6);
types.EduEntry.set("StatCost7", &EduEntry::StatCost7);
types.EduEntry.set("StatCost8", &EduEntry::StatCost8);
///Character
//@section characterTable
/***
characters as they exist on the strategy map - dead characters, wives, children, and off-map characters do not have these fields.
@tfield int xCoord
@tfield int yCoord
@tfield namedCharacter namedCharacter
@tfield unit bodyguards
@tfield stackStruct armyLeaded
@tfield stackStruct armyNotLeaded in the stack but not leading it
@tfield float movePointsMax
@tfield float movePointsModifier
@tfield float movePoints
@tfield string ability see descr_hero_abilities.xml
@tfield getTypeID getTypeID
@tfield setTypeID setTypeID
@tfield moveToTile moveToTile
@tfield reposition reposition
@tfield kill kill
@tfield setBodyguardUnit setBodyguardUnit
@table character
*/
types.character = luaState.new_usertype<general>("character");
types.character.set("xCoord", &general::xCoord);
types.character.set("yCoord", &general::yCoord);
types.character.set("namedCharacter", &general::genChar);
types.character.set("bodyguards", &general::bodyguards);
types.character.set("armyLeaded", &general::armyLeaded);
types.character.set("armyNotLeaded", &general::armyNotLeaded);
types.character.set("movePointsMax", &general::movepointsMax);
types.character.set("movePointsModifier", &general::movepointsModifier);
types.character.set("movePoints", sol::property(&generalHelpers::getMovepoints, &generalHelpers::setMovepoints));
types.character.set("ability", sol::property(&luaGetSetFuncs::getStringPropertyGen<generalStruct_abilityID>, &luaGetSetFuncs::setStringPropertyGen<generalStruct_abilityID>));
/***
Get character type.
0-spy
1-assassin
2-diplomat
3-admiral
4-merchant
5-priest
6-general
7-named character
8-princess
9-heretic
10-witch
11-inquisitor
13-pope
@function character:getTypeID
@treturn int typeId
@usage
local ourType=ourCharacter:getTypeID();
*/
types.character.set_function("getTypeID", &generalHelpers::getTypeID);
/***
Set character type.
0-spy
1-assassin
2-diplomat
3-admiral
4-merchant
5-priest
6-general
7-named character
8-princess
9-heretic
10-witch
11-inquisitor
13-pope
@function character:setTypeID
@tparam int typeId
@usage
ourCharacter:setTypeID(2);
*/
types.character.set_function("setTypeID", &generalHelpers::setTypeID); /***
Issue regular move command, character must have movePoints
@function character:moveToTile
@tparam int xCoord
@tparam int yCoord
@usage
ourCharacter:moveToTile(11,25);
*/
types.character.set_function("moveToTile", &generalHelpers::moveToTile);
/***
Instantly teleport character to coordinates
@function character:reposition
@tparam int xCoord
@tparam int yCoord
@usage
ourCharacter:reposition(11,25);
*/
types.character.set_function("reposition", &generalHelpers::reposition);
/***
Delete this character
@function character:kill
@usage
ourCharacter:kill();
*/
types.character.set_function("kill", &generalHelpers::killGeneral);
/***
Set bodyguard. Do this only for characters without it (after creating,for example)
@function character:setBodyguardUnit
@tparam unit unit
@usage
ourCharacter:setBodyguardUnit(unit);
*/
types.character.set_function("setBodyguardUnit", &generalHelpers::setBodyguard);
///NamedCharacter
//@section namedCharacterTable
/***
all named characters have these fields including dead characters, wives, children, and off-map characters
@tfield int index
@tfield character character
@tfield string shortName internal name
@tfield string fullName internal name including surname
@tfield string localizedDisplayName display name, resets upon reload save
@tfield string label
@tfield string portrait note: wives (who were never princesses) and children do not have anything for this field
@tfield string portrait2 note: wives (who were never princesses) and children do not have anything for this field
@tfield string portrait_custom note: wives (who were never princesses) and children do not have anything for this field
@tfield string modelName battle model
@tfield int status 5-leader,2 - heir, 0 - ordinary character, read only, do not set value
@tfield setAsHeir setAsHeir
@tfield isAlive isAlive
@tfield bool isMale
@tfield int age
@tfield float yearOfBirth e.g. with 4 turns per year, the yearOfBirth could be 1840.25
@tfield factionStruct faction
@tfield int subFaction
@tfield namedCharacter parent
@tfield namedCharacter spouse
@tfield namedCharacter[4] childs example: ourChar.childs[2].fullName
@tfield getTraits getTraits
@tfield addTrait addTrait
@tfield removeTrait removeTrait
@tfield int ancNum
@tfield getAncillary getAncillary
@tfield addAncillary addAncillary
@tfield removeAncillary removeAncillary
@tfield int level
@tfield int authority
@tfield int command
@tfield int chivalryAndDread positive = Chivalry, negative = Dread
@tfield int loyalty
@tfield int piety
@tfield int ambush
@tfield int artilleryCommand
@tfield int assassination
@tfield int attack
@tfield int battleSurgery
@tfield int bodyguardSize
@tfield int bodyguardValour
@tfield int boldness
@tfield int bribeResistance
@tfield int bribery
@tfield int cavalryCommand
@tfield int charm
@tfield int construction
@tfield int defence
@tfield int disposition
@tfield int electability
@tfield int eligibility
@tfield int farming
@tfield int fertility
@tfield int finance
@tfield int footInTheDoor
@tfield int generosity
@tfield int gunpowerCommand
@tfield int health
@tfield int heresyImmunity
@tfield int hitpoints
@tfield int infantryCommand
@tfield int influence
@tfield int law
@tfield int lineOfSight
@tfield int localPopularity
@tfield int looting
@tfield int magic
@tfield int management
@tfield int mining
@tfield int movementPointsBonus
@tfield int navalCommand
@tfield int nightBattle
@tfield int personalSecurity
@tfield int publicSecurity
@tfield int purity
@tfield int sabotage
@tfield int siegeAttack
@tfield int siegeDefense
@tfield int siegeEngineering
@tfield int squalor
@tfield int subterfuge
@tfield int taxCollection
@tfield int trading
@tfield int trainingAgents
@tfield int trainingAnimalUnits
@tfield int trainingUnits
@tfield int troopMorale
@tfield int unorthodoxy
@tfield int unrest
@tfield int violence