/
Scripting.h
1222 lines (1125 loc) · 39.1 KB
/
Scripting.h
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
#ifndef SCRIPTING_H_
#define SCRIPTING_H_
#include <string>
#include <vector>
#include <lua.hpp>
#include <lauxlib.h>
#include <lualib.h>
#include "Graphics.h"
#include "Physics.h"
#include "GraphicsAndPhysics.h"
#include "Sound.h"
#include "EventReceiver.h"
#include "Players.h"
std::string dicerolltranslationfunction; // "callback" string for Lua scripted dice roll translation function
std::string startgamefunction;
std::string endofsimulaitonfunction;
std::string printfunction;
std::string buttonfunction;
std::string idlefunction;
int setsound(lua_State *L)
{//function for setting up sound
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setsound, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 3: if( !lua_isnumber(L,1) || !lua_isstring(L,2) || !lua_isboolean(L, 3)) // check the types of the arguments
{
std::cerr<<"Lua setsound"<<std::endl;
lua_error(L);
return 0;
}
//SoundManager::getinstance().initialize();
SoundManager::getinstance().setsound((unsigned int)lua_tonumber(L, 1), lua_tostring(L, 2), lua_toboolean(L, 3));
break;
default:
std::cerr<<"Lua setsound"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int playsound(lua_State *L)
{//function for playing sound
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"playsound, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isnumber(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua playsound"<<std::endl;
lua_error(L);
return 0;
}
//SoundManager::getinstance().initialize();
SoundManager::getinstance().playsound((unsigned int)lua_tonumber(L, 1));
break;
default:
std::cerr<<"Lua playsound"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
/*int setdiceresultfunction(lua_State *L)
{//function for setting function that will translate dice results
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setdiceresultfunction, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isstring(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua setdiceresultfunction"<<std::endl;
lua_error(L);
return 0;
}
dicerolltranslationfunction=lua_tostring(L, 1);
break;
default:
std::cerr<<"Lua setdiceresultfunction"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}*/
int addphysicalplane(lua_State *L)
{//function for adding physical planes
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"addphysicalplane, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 4: if( !lua_isnumber(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3) || !lua_isnumber(L,4) ) // check the types of the arguments
{
std::cerr<<"Lua addphysicalplane"<<std::endl;
lua_error(L);
return 0;
}
diceboxwalls.push_back(dCreatePlane( space,
(dReal)lua_tonumber(L,1),
(dReal)lua_tonumber(L,2),
(dReal)lua_tonumber(L,3),
(dReal)lua_tonumber(L,4)));
break;
default:
std::cerr<<"Lua addphysicalplane"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setwindowcaption(lua_State *L)
{//function for setting the name of the screen
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setwindowcaption, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isstring(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua setwindowcaption"<<std::endl;
lua_error(L);
return 0;
}
device->setWindowCaption(core::stringw(lua_tostring(L, 1)).c_str());
break;
default:
std::cerr<<"Lua setwindowcaption"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int createdice(lua_State *L)
{//function for creating a number of dice
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"createdice, numArgs "<<numArgs<<endl<<flush;
if( !lua_isstring(L,1) || !lua_isnumber(L,2) ) // check the types of the arguments
{
std::cerr<<"Lua createdice"<<std::endl;
lua_error(L);
return 0;
}
GameObjectManager& gom=GameObjectManager::getinstance();
unsigned int tmp=0;
for(int i=0;i<lua_tointeger(L,2);i++)
{
tmp=gom.createCube(irr::io::path(lua_tostring(L,1)), vector3df(0.0, 0.0, 0.0));
for(int j=3;j<=numArgs;j++)
{
gom(tmp)(j-3)=(bool)lua_toboolean(L,j);
}
}
return 0;
}
int createmodel(lua_State *L)
{//function for creating a game object that is not physical
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"createmodel, numArgs "<<numArgs<<endl<<flush;
if( !lua_isstring(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3) || !lua_isnumber(L,4) ) // check the types of the arguments
{
std::cerr<<"Lua createmodel"<<std::endl;
lua_error(L);
return 0;
}
GameObjectManager& gom=GameObjectManager::getinstance();
unsigned int tmp=0;
tmp=gom.createmodel(irr::io::path(lua_tostring(L,1)),
vector3df((irr::f32)lua_tonumber(L, 2), (irr::f32)lua_tonumber(L, 3), (irr::f32)lua_tonumber(L, 4)));
for(int i=5;i<=numArgs;i++)
{
gom(tmp)(i-5)=lua_toboolean(L,i);
}
return 0;
}
int createbutton(lua_State *L)
{//function for creating a button without graphics
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"createbutton, numArgs "<<numArgs<<endl<<flush;
if( numArgs<5 || !lua_isstring(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3) || !lua_isnumber(L,4) || !lua_isnumber(L,5) ) // check the types of the arguments
{
std::cerr<<"Lua createbutton"<<std::endl;
lua_error(L);
return 0;
}
GameButtonManager& gbm=GameButtonManager::getinstance();
gbm.addbutton(core::rect<s32>(
lua_tointeger(L,2),
lua_tointeger(L,3),
lua_tointeger(L,4),
lua_tointeger(L,5)),
lua_tostring(L,1));
for(int i=6;i<=numArgs;i++)
{
//cout<<"gbm(lua_tostring(L,1))(i-6)=lua_toboolean(L,i); "<<lua_toboolean(L,i)<<endl<<flush;
gbm(lua_tostring(L,1))(i-6)=(bool)lua_toboolean(L,i);
}
return 0;
}
int createbuttonwithgraphics(lua_State *L)
{//function for creating a button with graphics
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"createbuttonwithgraphics, numArgs "<<numArgs<<endl<<flush;
if( numArgs<6 || !lua_isstring(L,1) || !lua_isstring(L,2) || !lua_isnumber(L,3) || !lua_isnumber(L,4) || !lua_isnumber(L,5) || !lua_isnumber(L,6) ) // check the types of the arguments
{
std::cerr<<"Lua createbuttonwithgraphics"<<std::endl;
lua_error(L);
return 0;
}
GameButtonManager& gbm=GameButtonManager::getinstance();
gbm.addbutton(lua_tostring(L,1), core::rect<s32>(
lua_tointeger(L,3),
lua_tointeger(L,4),
lua_tointeger(L,5),
lua_tointeger(L,6)),
lua_tostring(L,2));
for(int i=7;i<=numArgs;i++)
{
//cout<<"gbm(lua_tostring(L,1))(i-6)=lua_toboolean(L,i); "<<lua_toboolean(L,i)<<endl<<flush;
gbm(lua_tostring(L,2))(i-7)=(bool)lua_toboolean(L,i);
}
return 0;}
int setlookatcamera(lua_State *L)
{//function for adding physical planes
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setlookatcamera, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 6: if( !lua_isnumber(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3) || !lua_isnumber(L,4) || !lua_isnumber(L,5) || !lua_isnumber(L,6) ) // check the types of the arguments
{
std::cerr<<"Lua setlookatcamera"<<std::endl;
lua_error(L);
return 0;
}
smgr->addCameraSceneNode(0,
vector3df((dReal)lua_tonumber(L,1), (dReal)lua_tonumber(L,2), (dReal)lua_tonumber(L,3)),
vector3df((dReal)lua_tonumber(L,4), (dReal)lua_tonumber(L,5), (dReal)lua_tonumber(L,6)));
break;
default:
std::cerr<<"Lua setlookatcamera"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int loadfont(lua_State *L)
{//function for playing sound
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"loadfont, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isstring(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua loadfont"<<std::endl;
lua_error(L);
return 0;
}
font=device->getGUIEnvironment()->getFont(lua_tostring(L, 1));
break;
default:
std::cerr<<"Lua loadfont"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setallphysicalobjectslock(lua_State *L)
{//function for setting bool values from physical objects
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setallphysicalobjectslock, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 2: if( !lua_isnumber(L,1) || !lua_isboolean(L,2) ) // check the types of the arguments
{
std::cerr<<"Lua setallphysicalobjectslock"<<std::endl;
lua_error(L);
return 0;
}
// GameObjectManager& gom=GameObjectManager::getinstance();
for(unsigned int i=0;i<GameObjectManager::getinstance().size();i++)
{
GameObjectManager::getinstance()(i)((unsigned int)lua_tonumber(L,1))=lua_toboolean(L,2);
}
break;
default:
std::cerr<<"Lua setallphysicalobjectslock"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setphysicalobjectslock(lua_State *L)
{//function for setting bool values from one physical object
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setphysicalobjectslock, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 3: if( !lua_isnumber(L,1) || !lua_isnumber(L,2) || !lua_isboolean(L,3) ) // check the types of the arguments
{
std::cerr<<"Lua setphysicalobjectslock"<<std::endl;
lua_error(L);
return 0;
}
//GameObjectManager& gom=GameObjectManager::getinstance();
GameObjectManager::getinstance()((unsigned int)lua_tonumber(L,1))((unsigned int)lua_tonumber(L,2))=lua_toboolean(L,3);
break;
default:
std::cerr<<"Lua setphysicalobjectslock"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int getrandom(lua_State *L)
{//function to generate random integer
lua_pushnumber(L, random::getinstance()->randomint());
return 1;
}
int getfloatbetween(lua_State *L)
{//function to generate random float
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"getfloatbetween, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 2: if( !lua_isnumber(L,1) || !lua_isnumber(L,2) ) // check the types of the arguments
{
std::cerr<<"Lua getfloatbetween"<<std::endl;
lua_error(L);
return 0;
}
lua_pushnumber(L, random::getinstance()->randomfloatbetween((float)lua_tonumber(L, 1), (float)lua_tonumber(L, 2)));
return 1;
break;
default:
std::cerr<<"Lua getfloatbetween"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setgameobject(lua_State *L)
{//function to set parameters of physical game objects
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setposition, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 10: if( !lua_isnumber(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3)
|| !lua_isnumber(L,4) || !lua_isnumber(L,5) || !lua_isnumber(L,6)
|| !lua_isnumber(L,7) || !lua_isnumber(L,8) || !lua_isnumber(L,9)
|| !lua_isnumber(L,10)) // check the types of the arguments
{
std::cerr<<"Lua setposition"<<std::endl;
lua_error(L);
return 0;
}
GameObjectManager::getinstance()((unsigned int)lua_tointeger(L, 1)).set
(irr::core::vector3df((irr::f32)lua_tonumber(L, 2), (irr::f32)lua_tonumber(L, 3), (irr::f32)lua_tonumber(L, 4)),
irr::core::vector3df((irr::f32)lua_tonumber(L, 5), (irr::f32)lua_tonumber(L, 6), (irr::f32)lua_tonumber(L, 7)),
irr::core::vector3df((irr::f32)lua_tonumber(L, 8), (irr::f32)lua_tonumber(L, 9), (irr::f32)lua_tonumber(L, 10)));
break;
default:
std::cerr<<"Lua setposition"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setstargamefunction(lua_State *L)
{//function for setting function that will translate dice results
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setstargamefunction, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isstring(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua setstargamefunction"<<std::endl;
lua_error(L);
return 0;
}
startgamefunction=lua_tostring(L, 1);
break;
default:
std::cerr<<"Lua setstargamefunction"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int getgomhandle(lua_State *L)
{//function to gethandle of game object
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"getgomhandle, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 2: if( !lua_isnumber(L,1) || !lua_isnumber(L,2) ) // check the types of the arguments
{
std::cerr<<"Lua getgomhandle"<<std::endl;
lua_error(L);
return 0;
}
lua_pushboolean(L, GameObjectManager::getinstance()((unsigned int)lua_tonumber(L,1))((unsigned int)lua_tonumber(L,2)));
return 1;
break;
default:
std::cerr<<"Lua getgomhandle"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int getgomsize(lua_State *L)
{//function for fetching the amount of Game Objects
lua_pushnumber(L, GameObjectManager::getinstance().size());
return 1;
}
int setendofsimulationfunction(lua_State *L)
{//function for setting function that will be run at the end of each ODE simulation
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setendofsimulationfunction, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isstring(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua setendofsimulationfunction"<<std::endl;
lua_error(L);
return 0;
}
endofsimulaitonfunction=lua_tostring(L, 1);
break;
default:
std::cerr<<"Lua setendofsimulationfunction"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int whatisrolled(lua_State *L)
{//function that checks what a given dice rolled
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"whatisrolled, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isnumber(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua whatisrolled"<<std::endl;
lua_error(L);
return 0;
}
lua_pushnumber(L, GameObjectManager::getinstance().whatisrolled((unsigned int)lua_tointeger(L, 1)));
return 1;
break;
default:
std::cerr<<"Lua whatisrolled"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int printtext(lua_State *L)
{//function to print text on the screen
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"printtext, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 9: if( !lua_isstring(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3)
|| !lua_isnumber(L,4) || !lua_isnumber(L,5) || !lua_isnumber(L,6)
|| !lua_isnumber(L,7) || !lua_isnumber(L,8) || !lua_isnumber(L,9) ) // check the types of the arguments
{
std::cerr<<"Lua printtext"<<std::endl;
lua_error(L);
return 0;
}
font->draw(lua_tostring(L, 1),
irr::core::rect<s32>((irr::s32)lua_tointeger(L, 2), (irr::s32)lua_tointeger(L, 3), (irr::s32)lua_tointeger(L, 4), (irr::s32)lua_tointeger(L, 5)),
irr::video::SColor((irr::u32)lua_tointeger(L, 6), (irr::u32)lua_tointeger(L, 7), (irr::u32)lua_tointeger(L, 8), (irr::u32)lua_tointeger(L, 9)));
break;
default:
std::cerr<<"Lua printtext"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setprintfunction(lua_State *L)//TODO: get rid of, replace with idle funciton
{//function for setting function that will print text
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setprintfunction, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isstring(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua setprintfunction"<<std::endl;
lua_error(L);
return 0;
}
printfunction=lua_tostring(L, 1);
break;
default:
std::cerr<<"Lua setprintfunction"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setbuttonfunction(lua_State *L)
{//function for setting function that will print text
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setbuttonfunction, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isstring(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua setbuttonfunction"<<std::endl;
lua_error(L);
return 0;
}
buttonfunction=lua_tostring(L, 1);
break;
default:
std::cerr<<"Lua setbuttonfunction"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int addplayer(lua_State *L)
{//function for adding players
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"addplayer, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 4: if( !lua_isnumber(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3) || !lua_isnumber(L,4) ) // check the types of the arguments
{
std::cerr<<"Lua addplayer"<<std::endl;
lua_error(L);
return 0;
}
PlayerManager::getinstance().addplayer(irr::core::rect<s32>((s32)lua_tointeger(L,1),
(s32)lua_tointeger(L,2),
(s32)lua_tointeger(L,3),
(s32)lua_tointeger(L,4)));
break;
default:
std::cerr<<"Lua addplayer"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int getcurrentplayernumber(lua_State *L)
{//function for fetching the amount of Game Objects
lua_pushnumber(L, PlayerManager::getinstance().playernumber);
return 1;
}
int getgbmhandle(lua_State *L)
{//function to get handle of game button
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"getgbmhandle, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 2: if( !lua_isstring(L,1) || !lua_isnumber(L,2) ) // check the types of the arguments
{
std::cerr<<"Lua getgbmhandle"<<std::endl;
lua_error(L);
return 0;
}
{
lua_pushboolean(L, GameButtonManager::getinstance()(lua_tostring(L,1))((unsigned int)lua_tonumber(L,2)));
return 1;
break;
}
default:
std::cerr<<"Lua getgbmhandle"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int getplayertiles(lua_State *L)
{//function to get all tiles owned by a player
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"getplayertiles, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isnumber(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua getplayertiles"<<std::endl;
lua_error(L);
return 0;
}
{
std::vector<std::string> tiles;
tiles=PlayerManager::getinstance()((unsigned int)lua_tonumber(L,1)).givetiles();
for(unsigned int i=0;i<tiles.size();i++)
{
lua_pushstring(L, tiles.at(i).c_str());
}
return tiles.size();
break;
}
default:
std::cerr<<"Lua getplayertiles"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int getplayertile(lua_State *L)
{//function to get last tile owned by the player
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"getplayertile, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isnumber(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua getplayertile"<<std::endl;
lua_error(L);
return 0;
}
lua_pushstring(L, PlayerManager::getinstance()((unsigned int)lua_tonumber(L,1)).backtile().c_str());
return 1;
break;
default:
std::cerr<<"Lua getplayertile"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int pmnextplayer(lua_State *L)
{//function to get the next player
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"pmnextplayer, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isboolean(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua pmnextplayer"<<std::endl;
lua_error(L);
return 0;
}
lua_pushinteger(L, PlayerManager::getinstance().nextplayer(lua_toboolean(L, 1)));
return 1;
break;
default:
std::cerr<<"Lua pmnextplayer"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setbuttoncolour(lua_State *L)
{//function to set the colour of a button
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setbuttoncolour, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 5: if( !lua_isstring(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3) || !lua_isnumber(L,4) || !lua_isnumber(L,5) ) // check the types of the arguments
{
std::cerr<<"Lua setbuttoncolour"<<std::endl;
lua_error(L);
return 0;
}
GameButtonManager::getinstance()(lua_tostring(L, 1)).setcolour(irr::video::SColor(
(irr::u32) lua_tointeger(L, 2),
(irr::u32) lua_tointeger(L, 3),
(irr::u32) lua_tointeger(L, 4),
(irr::u32) lua_tointeger(L, 5)));
break;
default:
std::cerr<<"Lua setbuttoncolour"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setgbmhandle(lua_State *L)
{//function to set a boolean handle on a button
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"getgbmhandle, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 3: if( !lua_isstring(L,1) || !lua_isnumber(L,2) || !lua_isboolean(L,3) ) // check the types of the arguments
{
std::cerr<<"Lua getgbmhandle"<<std::endl;
lua_error(L);
return 0;
}
{
GameButtonManager::getinstance()(lua_tostring(L, 1))((unsigned int)lua_tointeger(L, 2))=lua_toboolean(L, 3);
break;
}
default:
std::cerr<<"Lua getgbmhandle"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setgomhandle(lua_State *L)
{//function to set a boolean handle on game object
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setgomhandle, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 3: if( !lua_isnumber(L,1) || !lua_isnumber(L,2) || !lua_isboolean(L,3) ) // check the types of the arguments
{
std::cerr<<"Lua setgomhandle"<<std::endl;
lua_error(L);
return 0;
}
{
GameObjectManager::getinstance()((unsigned int)lua_tointeger(L, 1))((unsigned int)lua_tointeger(L, 2))=lua_toboolean(L, 3);
break;
}
default:
std::cerr<<"Lua setgomhandle"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setgameobjectposition(lua_State *L)
{//function to set position of physical game object
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setposition, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 4: if( !lua_isnumber(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3)
|| !lua_isnumber(L,4)) // check the types of the arguments
{
std::cerr<<"Lua setposition"<<std::endl;
lua_error(L);
return 0;
}
GameObjectManager::getinstance()((unsigned int)lua_tointeger(L, 1)).setposition
(irr::core::vector3df((irr::f32)lua_tonumber(L, 2), (irr::f32)lua_tonumber(L, 3), (irr::f32)lua_tonumber(L, 4)));
break;
default:
std::cerr<<"Lua setposition"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int resetbutton(lua_State *L)
{//function to reset position of a button
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"resetbutton, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isstring(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua resetbutton"<<std::endl;
lua_error(L);
return 0;
}
{
GameButtonManager::getinstance()(lua_tostring(L, 1)).reset();
break;
}
default:
std::cerr<<"Lua resetbutton"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int doesplayerhavetile(lua_State *L)
{//function to check if a player has a particular tile
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"doesplayerhavetile, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 2: if( !lua_isnumber(L,1) || !lua_isstring(L,2) ) // check the types of the arguments
{
std::cerr<<"Lua doesplayerhavetile"<<std::endl;
lua_error(L);
return 0;
}
{
lua_pushboolean(L, PlayerManager::getinstance()((unsigned int)lua_tointeger(L, 1)).doesplayerhavetile(lua_tostring(L, 2)));
return 1;
break;
}
default:
std::cerr<<"Lua doesplayerhavetile"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int pushplayertile(lua_State *L)
{//function to give player a tile
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"pushplayertile, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 2: if( !lua_isnumber(L,1) || !lua_isstring(L,2) ) // check the types of the arguments
{
std::cerr<<"Lua pushplayertile"<<std::endl;
lua_error(L);
return 0;
}
{
PlayerManager::getinstance()((unsigned int)lua_tointeger(L, 1)).pushtile(lua_tostring(L, 2));
break;
}
default:
std::cerr<<"Lua pushplayertile"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int popplayertile(lua_State *L)
{//function to take away a tile from a player
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"popplayertile, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 2: if( !lua_isnumber(L,1) || !lua_isstring(L,2) ) // check the types of the arguments
{
std::cerr<<"Lua popplayertile"<<std::endl;
lua_error(L);
return 0;
}
{
PlayerManager::getinstance()((unsigned int)lua_tointeger(L, 1)).poptile(lua_tostring(L, 2));
break;
}
default:
std::cerr<<"Lua popplayertile"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int getplayersarea(lua_State *L)
{//function to get the area of a player
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"getplayersarea, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isnumber(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua getplayersarea"<<std::endl;
lua_error(L);
return 0;
}
{
irr::core::rect<s32> area=PlayerManager::getinstance()((unsigned int)lua_tointeger(L, 1)).playersarea;
lua_pushinteger(L, area.UpperLeftCorner.X);
lua_pushinteger(L, area.UpperLeftCorner.Y);
lua_pushinteger(L, area.LowerRightCorner.X);
lua_pushinteger(L, area.LowerRightCorner.Y);
return 4;
break;
}
default:
std::cerr<<"Lua getplayersarea"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setbuttonarea(lua_State *L)
{//function to set the area of a game tile
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setbuttonarea, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 5: if( !lua_isstring(L,1) || !lua_isnumber(L,2) || !lua_isnumber(L,3) || !lua_isnumber(L,4) || !lua_isnumber(L,5) ) // check the types of the arguments
{
std::cerr<<"Lua setbuttonarea"<<std::endl;
lua_error(L);
return 0;
}
{
GameButtonManager::getinstance()(lua_tostring(L, 1)).setarea(irr::core::rect<s32>
((s32)lua_tointeger(L, 2),(s32)lua_tointeger(L, 3),(s32)lua_tointeger(L, 4),(s32)lua_tointeger(L, 5)));
break;
}
default:
std::cerr<<"Lua setbuttonarea"<<std::endl;
lua_error(L);
return 0;
}
return 0;
}
int setidlefunction(lua_State *L)
{//function for setting function that will be called each game loop
// find out how many arguements the function has been sent
int numArgs = lua_gettop(L);
//cout<<"setidlefunction, numArgs "<<numArgs<<endl<<flush;
switch(numArgs) // check the number of arguments
{
case 1: if( !lua_isstring(L,1) ) // check the types of the arguments
{
std::cerr<<"Lua setidlefunction"<<std::endl;
lua_error(L);
return 0;
}
idlefunction=lua_tostring(L, 1);
break;