-
Notifications
You must be signed in to change notification settings - Fork 105
/
GameScripts.cpp
1903 lines (1496 loc) · 61.5 KB
/
GameScripts.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
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of Penumbra Overture.
*
* Penumbra Overture is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Penumbra Overture is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Penumbra Overture. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StdAfx.h"
#include "GameScripts.h"
#include "Init.h"
#include "MapHandler.h"
#include "Player.h"
#include "PlayerHelper.h"
#include "GameEntity.h"
#include "GameSwingDoor.h"
#include "GameItem.h"
#include "GameObject.h"
#include "GameArea.h"
#include "GameStickArea.h"
#include "GameEnemy.h"
#include "GameLink.h"
#include "GameLamp.h"
#include "GameLadder.h"
#include "GameDamageArea.h"
#include "GameForceArea.h"
#include "GameLiquidArea.h"
#include "GameSaveArea.h"
#include "GameMessageHandler.h"
#include "RadioHandler.h"
#include "Inventory.h"
#include "Notebook.h"
#include "NumericalPanel.h"
#include "FadeHandler.h"
#include "EffectHandler.h"
#include "AttackHandler.h"
#include "SaveHandler.h"
#include "GraphicsHelper.h"
#include "MainMenu.h"
#include "GameMusicHandler.h"
#include "Credits.h"
#include "DemoEndText.h"
#include "GlobalInit.h"
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// SCRIPT FUNCTIONS
//////////////////////////////////////////////////////////////////////////
///////// HELPERS ////////////////////////////////////
//-----------------------------------------------------------------------
#define GAME_ENTITY_BEGIN(asName) iGameEntity *pEntity = gpInit->mpMapHandler->GetGameEntity(asName); \
if(pEntity==NULL){ \
Warning("Couldn't find game entity '%s'\n",asName.c_str()); \
return; } \
//-----------------------------------------------------------------------
tWString gsTempString = _W("");
//-----------------------------------------------------------------------
static void __stdcall AddToTempString(std::string asString)
{
gsTempString += cString::To16Char(asString);
}
SCRIPT_DEFINE_FUNC_1(void, AddToTempString, string)
static void __stdcall AddToTempStringTrans(std::string asCat,std::string asEntry)
{
cInit *mpInit = gpInit;
gsTempString += kTranslate(asCat,asEntry);
}
SCRIPT_DEFINE_FUNC_2(void, AddToTempStringTrans, string,string)
static void __stdcall AddToTempStringAction(std::string asAction)
{
cInit *mpInit = gpInit;
iAction *pAction = gpInit->mpGame->GetInput()->GetAction(asAction);
if(pAction)
{
tWString sString = kTranslate("ButtonNames",pAction->GetInputName());
if(sString != _W(""))
gsTempString += sString;
else
gsTempString += cString::To16Char(pAction->GetInputName());
}
else
{
gsTempString += kTranslate("ButtonNames", "None");
}
}
SCRIPT_DEFINE_FUNC_1(void, AddToTempStringAction,string)
//-----------------------------------------------------------------------
///////// GENERAL GAME ////////////////////////////////////
static void __stdcall ResetGame()
{
gpInit->mpGame->ResetLogicTimer();
gpInit->mpMapHandler->SetCurrentMapName("");
gpInit->mpMainMenu->SetActive(true);
}
SCRIPT_DEFINE_FUNC(void, ResetGame)
//-----------------------------------------------------------------------
static void __stdcall StartCredits()
{
gpInit->mpCredits->SetActive(true);
}
SCRIPT_DEFINE_FUNC(void, StartCredits)
static void __stdcall StartDemoEndText()
{
gpInit->mpDemoEndText->SetActive(true);
}
SCRIPT_DEFINE_FUNC(void, StartDemoEndText)
//-----------------------------------------------------------------------
static void __stdcall ClearSavedMaps()
{
gpInit->mpSaveHandler->ClearSavedMaps();
}
SCRIPT_DEFINE_FUNC(void, ClearSavedMaps)
//-----------------------------------------------------------------------
static std::string __stdcall GetActionKeyString(std::string asAction)
{
iAction *pAction = gpInit->mpGame->GetInput()->GetAction(asAction);
if(pAction)
{
return pAction->GetInputName();
}
return "ActionNotFound";
}
SCRIPT_DEFINE_FUNC_1(string, GetActionKeyString, string)
//-----------------------------------------------------------------------
static void __stdcall AddMessageTrans(std::string asTransCat,
std::string asTransName)
{
cInit *mpInit = gpInit;
gpInit->mpGameMessageHandler->Add(kTranslate(asTransCat,asTransName));
}
SCRIPT_DEFINE_FUNC_2(void, AddMessageTrans, string, string)
//-----------------------------------------------------------------------
static void __stdcall AddMessage(std::string asMessage)
{
gpInit->mpGameMessageHandler->Add(cString::To16Char(asMessage));
}
SCRIPT_DEFINE_FUNC_1(void, AddMessage, string)
//-----------------------------------------------------------------------
static void __stdcall AddMessageTempString()
{
gpInit->mpGameMessageHandler->Add(gsTempString);
gsTempString = _W("");
}
SCRIPT_DEFINE_FUNC(void, AddMessageTempString)
//-----------------------------------------------------------------------
static void __stdcall AddSubTitleTrans(std::string asTransCat,
std::string asTransName, float afTime)
{
cInit *mpInit = gpInit;
gpInit->mpEffectHandler->GetSubTitle()->Add(kTranslate(asTransCat,asTransName),afTime,false);
}
SCRIPT_DEFINE_FUNC_3(void, AddSubTitleTrans, string, string, float)
//-----------------------------------------------------------------------
static void __stdcall AddSubTitle(std::string asMessage, float afTime)
{
gpInit->mpEffectHandler->GetSubTitle()->Add(cString::To16Char(asMessage),afTime,false);
}
SCRIPT_DEFINE_FUNC_2(void, AddSubTitle, string, float)
//-----------------------------------------------------------------------
static void __stdcall AddSubTitleTempString(float afTime)
{
gpInit->mpEffectHandler->GetSubTitle()->Add(gsTempString,afTime,false);
gsTempString = _W("");
}
SCRIPT_DEFINE_FUNC_1(void, AddSubTitleTempString, float)
//-----------------------------------------------------------------------
static void __stdcall AddRadioMessage( std::string asTransCat,std::string asTransName,
std::string asSound)
{
cInit *mpInit = gpInit;
gpInit->mpRadioHandler->Add(kTranslate(asTransCat,asTransName),asSound);
}
SCRIPT_DEFINE_FUNC_3(void, AddRadioMessage, string, string, string)
//-----------------------------------------------------------------------
static void __stdcall SetRadioOnEndCallback(std::string asFunc)
{
gpInit->mpRadioHandler->SetOnEndCallback(asFunc);
}
SCRIPT_DEFINE_FUNC_1(void, SetRadioOnEndCallback, string)
//-----------------------------------------------------------------------
static void __stdcall SetInventoryMessage(std::string asMessage)
{
gpInit->mpInventory->SetMessage(cString::To16Char(asMessage));
}
SCRIPT_DEFINE_FUNC_1(void, SetInventoryMessage, string)
static void __stdcall SetInventoryMessageTrans(std::string asTransCat,
std::string asTransName)
{
cInit *mpInit = gpInit;
gpInit->mpInventory->SetMessage(kTranslate(asTransCat,asTransName));
}
SCRIPT_DEFINE_FUNC_2(void, SetInventoryMessageTrans, string, string)
//-----------------------------------------------------------------------
static void __stdcall SetMessagesOverCallback(std::string asFunction)
{
gpInit->mpGameMessageHandler->SetOnMessagesOverCallback(asFunction);
}
SCRIPT_DEFINE_FUNC_1(void, SetMessagesOverCallback, string)
//-----------------------------------------------------------------------
static void __stdcall ChangeMap(std::string asMapFile, std::string asMapPos,
std::string asStartSound, std::string asStopSound,
float afFadeOutTime, float afFadeInTime,
std::string asLoadTextCat, std::string asLoadTextEntry)
{
//if(gpInit->mpRadioHandler->IsActive()) return;
gpInit->mpMapHandler->ChangeMap(asMapFile,asMapPos, asStartSound,asStopSound,
afFadeOutTime,afFadeInTime,
asLoadTextCat,asLoadTextEntry);
}
SCRIPT_DEFINE_FUNC_8(void, ChangeMap, string, string, string, string, float, float, string, string)
//-----------------------------------------------------------------------
static void __stdcall SetMapGameName(std::string asName)
{
gpInit->mpMapHandler->SetMapGameName(cString::To16Char(asName));
}
SCRIPT_DEFINE_FUNC_1(void, SetMapGameName, string)
static void __stdcall SetMapGameNameTrans(std::string asTransCat,std::string asTransEntry)
{
cInit *mpInit = gpInit;
gpInit->mpMapHandler->SetMapGameName(kTranslate(asTransCat,asTransEntry));
}
SCRIPT_DEFINE_FUNC_2(void, SetMapGameNameTrans, string, string)
//-----------------------------------------------------------------------
static void __stdcall AddNotebookTaskText(std::string asName,std::string asText)
{
gpInit->mpNotebook->AddTask(asName, cString::To16Char(asText));
}
SCRIPT_DEFINE_FUNC_2(void, AddNotebookTaskText, string, string)
//-----------------------------------------------------------------------
static void __stdcall AddNotebookTask(std::string asName, std::string asTransCat,
std::string asTransEntry)
{
cInit *mpInit = gpInit;
gpInit->mpNotebook->AddTask(asName, kTranslate(asTransCat,asTransEntry));
}
SCRIPT_DEFINE_FUNC_3(void, AddNotebookTask, string, string, string)
//-----------------------------------------------------------------------
static void __stdcall RemoveNotebookTask(std::string asName)
{
gpInit->mpNotebook->RemoveTask(asName);
}
SCRIPT_DEFINE_FUNC_1(void, RemoveNotebookTask, string)
//-----------------------------------------------------------------------
static void __stdcall AddNotebookNote(std::string asNameCat, std::string asNameEntry,
std::string asTextCat, std::string asTextEntry)
{
cInit *mpInit = gpInit;
gpInit->mpNotebook->AddNote(kTranslate(asNameCat,asNameEntry),asTextCat,asTextEntry);
}
SCRIPT_DEFINE_FUNC_4(void, AddNotebookNote, string, string, string, string)
//-----------------------------------------------------------------------
static void __stdcall StartNumericalPanel(std::string asName,int alCode1,int alCode2,int alCode3,int alCode4,
float afDifficulty, std::string asCallback)
{
gpInit->mpNumericalPanel->SetActive(true);
tIntVec vCode; vCode.resize(4);
vCode[0] = alCode1; vCode[1] = alCode2; vCode[2] = alCode3; vCode[3] = alCode4;
gpInit->mpNumericalPanel->SetUp(asName,asCallback);
gpInit->mpNumericalPanel->SetCode(vCode);
}
SCRIPT_DEFINE_FUNC_7(void, StartNumericalPanel, string, int, int, int, int, float, string)
//-----------------------------------------------------------------------
static void __stdcall SetInventoryActive(bool abX)
{
gpInit->mpInventory->SetActive(abX);
}
SCRIPT_DEFINE_FUNC_1(void,SetInventoryActive,bool)
//-----------------------------------------------------------------------
static void __stdcall FadeIn(float afTime)
{
gpInit->mpFadeHandler->FadeIn(afTime);
}
SCRIPT_DEFINE_FUNC_1(void,FadeIn,float)
static void __stdcall FadeOut(float afTime)
{
gpInit->mpFadeHandler->FadeOut(afTime);
}
SCRIPT_DEFINE_FUNC_1(void,FadeOut,float)
static bool __stdcall IsFading()
{
return gpInit->mpFadeHandler->IsActive();
}
SCRIPT_DEFINE_FUNC(bool,IsFading)
//-----------------------------------------------------------------------
static void __stdcall SetWideScreenActive(bool abActive)
{
gpInit->mpFadeHandler->SetWideScreenActive(abActive);
}
SCRIPT_DEFINE_FUNC_1(void,SetWideScreenActive,bool)
//-----------------------------------------------------------------------
static void __stdcall AutoSave()
{
if(gpInit->mpPlayer->GetHealth()<=0) return;
//TODO: Some other effect here.
//gpInit->mpGraphicsHelper->DrawLoadingScreen("other_saving.jpg");
//gpInit->mpSaveHandler->SaveGameToFile("save/auto.sav");
//gpInit->mpSaveHandler->AutoSave("Auto",5);
gpInit->mpEffectHandler->GetSaveEffect()->AutoSave();
}
SCRIPT_DEFINE_FUNC(void,AutoSave)
//-----------------------------------------------------------------------
static void __stdcall StartFlash(float afFadeIn, float afWhite, float afFadeOut)
{
gpInit->mpEffectHandler->GetFlash()->Start(afFadeIn,afWhite,afFadeOut);
}
SCRIPT_DEFINE_FUNC_3(void,StartFlash,float,float,float)
//-----------------------------------------------------------------------
static void __stdcall SetWaveGravityActive(bool abX)
{
gpInit->mpEffectHandler->GetWaveGravity()->SetActive(abX);
}
SCRIPT_DEFINE_FUNC_1(void,SetWaveGravityActive,bool)
static void __stdcall SetupWaveGravity(float afMaxAngle, float afSwingLength,
float afGravitySize, std::string asAxis)
{
int lDir = cString::ToLowerCase(asAxis) == "x" ? 0 : 1;
gpInit->mpEffectHandler->GetWaveGravity()->Setup(cMath::ToRad(afMaxAngle),afSwingLength,afGravitySize,lDir);
}
SCRIPT_DEFINE_FUNC_4(void, SetupWaveGravity, float, float, float, string)
//-----------------------------------------------------------------------
static void __stdcall SetDepthOfFieldActive(bool abX, float afFadeTime)
{
gpInit->mpEffectHandler->GetDepthOfField()->SetActive(abX,afFadeTime);
}
SCRIPT_DEFINE_FUNC_2(void,SetDepthOfFieldActive,bool,float)
//-----------------------------------------------------------------------
static void __stdcall SetupDepthOfField(float afNearPlane, float afFocalPlane, float afFarPlane)
{
gpInit->mpEffectHandler->GetDepthOfField()->SetUp(afNearPlane,afFocalPlane,afFarPlane);
gpInit->mpEffectHandler->GetDepthOfField()->SetFocusBody(NULL);
}
SCRIPT_DEFINE_FUNC_3(void,SetupDepthOfField,float,float,float)
//-----------------------------------------------------------------------
static void __stdcall FocusOnEntity(std::string asEntity)
{
GAME_ENTITY_BEGIN(asEntity);
if(pEntity->GetBodyNum()==0) {
Error("Entity %s had no bodies and can not be focus on.\n",pEntity->GetName().c_str());
return;
}
gpInit->mpEffectHandler->GetDepthOfField()->FocusOnBody(pEntity->GetBody(0));
gpInit->mpEffectHandler->GetDepthOfField()->SetFocusBody(NULL);
}
SCRIPT_DEFINE_FUNC_1(void,FocusOnEntity,string)
//-----------------------------------------------------------------------
static void __stdcall SetConstantFocusOnEntity(std::string asEntity)
{
if(asEntity=="")
{
gpInit->mpEffectHandler->GetDepthOfField()->SetFocusBody(NULL);
return;
}
GAME_ENTITY_BEGIN(asEntity);
if(pEntity->GetBodyNum()==0) {
Error("Entity %s had no bodies and can not be focus on.\n",pEntity->GetName().c_str());
return;
}
gpInit->mpEffectHandler->GetDepthOfField()->SetFocusBody(pEntity->GetBody(0));
}
SCRIPT_DEFINE_FUNC_1(void,SetConstantFocusOnEntity,string)
//-----------------------------------------------------------------------
static void __stdcall PlayGameMusic( std::string asFile, float afVolume,float afFadeStep,
bool abLoop, int alPrio)
{
gpInit->mpMusicHandler->Play(asFile,abLoop,afVolume,afFadeStep,alPrio);
}
SCRIPT_DEFINE_FUNC_5(void, PlayGameMusic, string, float, float, bool, int)
//-----------------------------------------------------------------------
static void __stdcall StopGameMusic(float afFadeStep, int alPrio)
{
gpInit->mpMusicHandler->Stop(afFadeStep,alPrio);
}
SCRIPT_DEFINE_FUNC_2(void,StopGameMusic,float,int)
//-----------------------------------------------------------------------
static void __stdcall StartScreenShake(float afAmount, float afTime,float afFadeInTime,float afFadeOutTime)
{
gpInit->mpEffectHandler->GetShakeScreen()->Start(afAmount,afTime,afFadeInTime,afFadeOutTime);
}
SCRIPT_DEFINE_FUNC_4(void,StartScreenShake,float,float,float,float)
//-----------------------------------------------------------------------
static void __stdcall CreateLightFlashAtArea(std::string asArea, float afRadius,
float afR,float afG, float afB, float afA,
float afAddTime, float afNegTime)
{
cAreaEntity *pArea = gpInit->mpGame->GetScene()->GetWorld3D()->GetAreaEntity(asArea);
if(pArea==NULL)
{
Error("Could not find area '%s'\n",asArea.c_str());
return;
}
gpInit->mpMapHandler->AddLightFlash(pArea->m_mtxTransform.GetTranslation(),afRadius,
cColor(afR,afG,afB,afA),afAddTime,afNegTime);
}
SCRIPT_DEFINE_FUNC_8(void, CreateLightFlashAtArea, string, float, float, float, float, float, float, float)
//-----------------------------------------------------------------------
///////// ATTACK ////////////////////////////////////
//-----------------------------------------------------------------------
static void __stdcall CreateSplashDamage(std::string asAreaName, float afRadius,
float afMinDamage, float afMaxDamge,
float afMinForce, float afMaxForce,
float afMaxImpulse, int alStrength)
{
///////////////////
//Get area
iGameEntity *pEntity = gpInit->mpMapHandler->GetGameEntity(asAreaName);
if(pEntity==NULL || pEntity->GetType() != eGameEntityType_Area)
{
Warning("Couldn't find area entity '%s'\n",asAreaName.c_str());
return;
}
cGameArea *pArea = static_cast<cGameArea*>(pEntity);
gpInit->mpAttackHandler->CreateSplashDamage(pArea->GetBody(0)->GetWorldPosition(),
afRadius,afMinDamage,afMaxDamge,
afMinForce, afMaxForce, afMaxImpulse,
eAttackTargetFlag_Bodies |
eAttackTargetFlag_Player |
eAttackTargetFlag_Enemy,
1, alStrength);
}
SCRIPT_DEFINE_FUNC_8(void, CreateSplashDamage, string, float, float, float, float, float, float, int)
//-----------------------------------------------------------------------
///////// GAME TIMER ////////////////////////////////////
//-----------------------------------------------------------------------
static void __stdcall CreateTimer(std::string asName, float afTime, std::string asCallback, bool abGlobal)
{
gpInit->mpMapHandler->CreateTimer(asName,afTime,asCallback,abGlobal);
}
SCRIPT_DEFINE_FUNC_4(void,CreateTimer,string,float,string,bool)
static void __stdcall DestroyTimer(std::string asName)
{
cGameTimer *pTimer = gpInit->mpMapHandler->GetTimer(asName);
if(pTimer==NULL){
Warning("Couldn't find timer '%s'\n",asName.c_str());
return;
}
pTimer->mbDeleteMe = true;
}
SCRIPT_DEFINE_FUNC_1(void,DestroyTimer,string)
static void __stdcall SetTimerPaused(std::string asName, bool abPaused)
{
cGameTimer *pTimer = gpInit->mpMapHandler->GetTimer(asName);
if(pTimer==NULL){
Warning("Couldn't find timer '%s'\n",asName.c_str());
return;
}
pTimer->mbPaused = abPaused;
}
SCRIPT_DEFINE_FUNC_2(void,SetTimerPaused,string,bool)
static void __stdcall SetTimerTime(std::string asName, float afTime)
{
cGameTimer *pTimer = gpInit->mpMapHandler->GetTimer(asName);
if(pTimer==NULL){
Warning("Couldn't find timer '%s'\n",asName.c_str());
return;
}
pTimer->mfTime = afTime;
}
SCRIPT_DEFINE_FUNC_2(void,SetTimerTime,string,float)
static void __stdcall AddTimerTime(std::string asName, float afTime)
{
cGameTimer *pTimer = gpInit->mpMapHandler->GetTimer(asName);
if(pTimer==NULL){
Warning("Couldn't find timer '%s'\n",asName.c_str());
return;
}
pTimer->mfTime += afTime;
}
SCRIPT_DEFINE_FUNC_2(void,AddTimerTime,string,float)
static float __stdcall GetTimerTime(std::string asName)
{
cGameTimer *pTimer = gpInit->mpMapHandler->GetTimer(asName);
if(pTimer==NULL){
Warning("Couldn't find timer '%s'\n",asName.c_str());
return 0.0f;
}
return pTimer->mfTime;
}
SCRIPT_DEFINE_FUNC_1(float,GetTimerTime,string)
//-----------------------------------------------------------------------
///////// PLAYER ////////////////////////////////////
//-----------------------------------------------------------------------
static void __stdcall GivePlayerDamage(float afAmount, std::string asType)
{
ePlayerDamageType type = ePlayerDamageType_BloodSplash;
tString sLowType = cString::ToLowerCase(asType);
if(sLowType == "bloodsplash") type = ePlayerDamageType_BloodSplash;
else if(sLowType == "ice") type = ePlayerDamageType_Ice;
else
Warning("Damage type %s does not exist!\n",asType.c_str());
gpInit->mpPlayer->Damage(afAmount,type);
}
SCRIPT_DEFINE_FUNC_2(void,GivePlayerDamage,float,string)
//-----------------------------------------------------------------------
static void __stdcall SetPlayerHealth(float afHealth)
{
gpInit->mpPlayer->SetHealth(afHealth);
}
SCRIPT_DEFINE_FUNC_1(void,SetPlayerHealth,float)
static float __stdcall GetPlayerHealth()
{
return gpInit->mpPlayer->GetHealth();
}
SCRIPT_DEFINE_FUNC(float,GetPlayerHealth)
//-----------------------------------------------------------------------
static void __stdcall SetPlayerPose(std::string asPose,bool abChangeDirectly)
{
tString sPose = cString::ToLowerCase(asPose);
if(sPose == "stand")
{
gpInit->mpPlayer->ChangeMoveState(ePlayerMoveState_Walk,abChangeDirectly);
}
else if(sPose == "crouch")
{
gpInit->mpPlayer->ChangeMoveState(ePlayerMoveState_Crouch,abChangeDirectly);
}
else
{
Warning("Player pose mode '%s' does not exist\n",asPose.c_str());
}
}
SCRIPT_DEFINE_FUNC_2(void,SetPlayerPose,string,bool)
static void __stdcall SetPlayerActive(bool abActive)
{
gpInit->mpPlayer->SetActive(abActive);
}
SCRIPT_DEFINE_FUNC_1(void,SetPlayerActive,bool)
//-----------------------------------------------------------------------
static void __stdcall StartPlayerLookAt(std::string asEntityName, float afSpeedMul, float afMaxSpeed)
{
///////////////////
//Get entity
iGameEntity *pEntity = gpInit->mpMapHandler->GetGameEntity(asEntityName);
if(pEntity==NULL)
{
Warning("Couldn't find entity '%s'\n",asEntityName.c_str());
return;
}
if(pEntity->GetBody(0)==NULL)
{
Warning("Couldn't find a body in entity '%s'\n",asEntityName.c_str());
return;
}
gpInit->mpPlayer->GetLookAt()->SetTarget(pEntity->GetBody(0)->GetWorldPosition(),afSpeedMul,afMaxSpeed);
gpInit->mpPlayer->GetLookAt()->SetActive(true);
}
SCRIPT_DEFINE_FUNC_3(void,StartPlayerLookAt,string,float,float)
static void __stdcall StopPlayerLookAt()
{
gpInit->mpPlayer->GetLookAt()->SetActive(false);
}
SCRIPT_DEFINE_FUNC(void,StopPlayerLookAt)
//-----------------------------------------------------------------------
static void __stdcall StartPlayerFearFilter(float afStrength)
{
gpInit->mpPlayer->GetFearFilter()->SetActive(true);
}
SCRIPT_DEFINE_FUNC_1(void,StartPlayerFearFilter,float)
static void __stdcall StopPlayerFearFilter()
{
gpInit->mpPlayer->GetFearFilter()->SetActive(false);
}
SCRIPT_DEFINE_FUNC(void,StopPlayerFearFilter)
//-----------------------------------------------------------------------
static void __stdcall SetFlashlightDisabled(bool abDisabled)
{
gpInit->mpPlayer->GetFlashLight()->SetDisabled(abDisabled);
}
SCRIPT_DEFINE_FUNC_1(void,SetFlashlightDisabled,bool)
//-----------------------------------------------------------------------
///////// INVENTORY ////////////////////////////////////
//-----------------------------------------------------------------------
static void __stdcall AddPickupCallback(std::string asItem, std::string asFunction)
{
gpInit->mpInventory->AddPickupCallback(asItem,asFunction);
}
SCRIPT_DEFINE_FUNC_2(void,AddPickupCallback,string,string)
static void __stdcall AddUseCallback(std::string asItem, std::string asEntity, std::string asFunction)
{
gpInit->mpInventory->AddUseCallback(asItem,asEntity,asFunction);
}
SCRIPT_DEFINE_FUNC_3(void,AddUseCallback,string,string,string)
static void __stdcall AddCombineCallback(std::string asItem1,std::string asItem2, std::string asFunction)
{
gpInit->mpInventory->AddCombineCallback(asItem1,asItem2,asFunction);
}
SCRIPT_DEFINE_FUNC_3(void,AddCombineCallback,string,string,string)
//-----------------------------------------------------------------------
static void __stdcall RemovePickupCallback(std::string asFunction)
{
gpInit->mpInventory->RemovePickupCallback(asFunction);
}
SCRIPT_DEFINE_FUNC_1(void,RemovePickupCallback,string)
static void __stdcall RemoveUseCallback(std::string asFunction)
{
gpInit->mpInventory->RemoveUseCallback(asFunction);
}
SCRIPT_DEFINE_FUNC_1(void,RemoveUseCallback,string)
static void __stdcall RemoveCombineCallback(std::string asFunction)
{
gpInit->mpInventory->RemoveCombineCallback(asFunction);
}
SCRIPT_DEFINE_FUNC_1(void,RemoveCombineCallback,string)
//-----------------------------------------------------------------------
static bool __stdcall HasItem(std::string asName)
{
//if(cString::ToLowerCase(asName)=="notebook") return gpInit->mpInventory->GetNoteBookActive();
return gpInit->mpInventory->GetItem(asName) != NULL;
}
SCRIPT_DEFINE_FUNC_1(bool,HasItem,string)
static void __stdcall RemoveItem(std::string asName)
{
cInventoryItem *pItem = gpInit->mpInventory->GetItem(asName);
if(pItem)
{
gpInit->mpInventory->RemoveItem(pItem);
}
else
{
Warning("Cannot find item '%s' in inventory\n",asName.c_str());
}
}
SCRIPT_DEFINE_FUNC_1(void,RemoveItem,string)
static void __stdcall GiveItem(std::string asName,std::string asEntityFile,int alSlotIndex)
{
gpInit->mpInventory->AddItemFromFile(asName,asEntityFile, alSlotIndex);
}
SCRIPT_DEFINE_FUNC_3(void,GiveItem,string,string,int)
//-----------------------------------------------------------------------
///////// GAME ENTITY PROPERTIES //////////////////////////////////
//-----------------------------------------------------------------------
static void __stdcall ReplaceEntity(std::string asName, std::string asBodyName,
std::string asNewName, std::string asNewFile)
{
GAME_ENTITY_BEGIN(asName)
if(pEntity->GetBodyNum()==0){
Error("Entity '%s' contains no bodies!\n",pEntity->GetName().c_str());
return;
}
iPhysicsBody *pBody = NULL;
if(asBodyName != "" && pEntity->GetBodyNum()>1)
{
for(int i= 0; i < pEntity->GetBodyNum(); ++i)
{
tString sBodyName = cString::Sub(pEntity->GetBody(i)->GetName(), (int)asName.size() +1);
if(sBodyName == asBodyName){
pBody = pEntity->GetBody(i);
break;
}
}
if(pBody==NULL)
{
Error("Body '%s' could not be found in entity '%s'!\n",asBodyName.c_str(),asName.c_str());
return;
}
}
else
{
iPhysicsBody *pBody = pEntity->GetBody(0);
}
cMatrixf mtxTransform = pBody->GetWorldMatrix();
gpInit->mpMapHandler->RemoveGameEntity(pEntity);
cWorld3D *pWorld = gpInit->mpGame->GetScene()->GetWorld3D();
pWorld->CreateEntity(asNewName,mtxTransform,asNewFile, true);
}
SCRIPT_DEFINE_FUNC_4(void, ReplaceEntity, string, string, string, string)
//-----------------------------------------------------------------------
static void __stdcall SetGameEntityActive(std::string asName, bool abX)
{
GAME_ENTITY_BEGIN(asName)
pEntity->SetActive(abX);
}
SCRIPT_DEFINE_FUNC_2(void,SetGameEntityActive,string,bool)
static bool __stdcall GetGameEntityActive(std::string asName)
{
iGameEntity *pEntity = gpInit->mpMapHandler->GetGameEntity(asName);
if(pEntity==NULL){
Warning("Couldn't find game entity '%s'\n",asName.c_str());
return false;
}
return pEntity->IsActive();
}
SCRIPT_DEFINE_FUNC_1(bool,GetGameEntityActive,string)
//-----------------------------------------------------------------------
static void __stdcall CreateGameEntityVar(std::string asEntName, std::string asVarName, int alVal)
{
GAME_ENTITY_BEGIN(asEntName);
pEntity->CreateVar(asVarName,alVal);
}
SCRIPT_DEFINE_FUNC_3(void,CreateGameEntityVar,string,string,int)
static void __stdcall SetGameEntityVar(std::string asEntName, std::string asVarName, int alVal)
{
GAME_ENTITY_BEGIN(asEntName);
pEntity->SetVar(asVarName,alVal);
}
SCRIPT_DEFINE_FUNC_3(void,SetGameEntityVar,string,string,int)
static void __stdcall AddGameEntityVar(std::string asEntName, std::string asVarName, int alVal)
{
GAME_ENTITY_BEGIN(asEntName);
pEntity->AddVar(asVarName,alVal);
}
SCRIPT_DEFINE_FUNC_3(void,AddGameEntityVar,string,string,int)
static int __stdcall GetGameEntityVar(std::string asEntName, std::string asVarName)
{
iGameEntity *pEntity = gpInit->mpMapHandler->GetGameEntity(asEntName);
if(pEntity==NULL){
Warning("Couldn't find game entity '%s'\n",asEntName.c_str());
return 0;
}
return pEntity->GetVar(asVarName);
}
SCRIPT_DEFINE_FUNC_2(int,GetGameEntityVar,string,string)
//-----------------------------------------------------------------------
static void __stdcall SetGameEntityMaxExamineDist(std::string asName,float afDist)
{
GAME_ENTITY_BEGIN(asName)
pEntity->SetMaxExamineDist(afDist);
}
SCRIPT_DEFINE_FUNC_2(void,SetGameEntityMaxExamineDist,string,float)
static void __stdcall SetGameEntityMaxInteractDist(std::string asName,float afDist)
{
GAME_ENTITY_BEGIN(asName)
pEntity->SetMaxInteractDist(afDist);
}
SCRIPT_DEFINE_FUNC_2(void,SetGameEntityMaxInteractDist,string,float)
//-----------------------------------------------------------------------
static void __stdcall SetGameEntityDescriptionTrans(std::string asName,
std::string asTransCat,
std::string asTransName)
{
cInit *mpInit = gpInit;
GAME_ENTITY_BEGIN(asName)
pEntity->SetDescription(kTranslate(asTransCat,asTransName));
pEntity->SetShowDescritionOnce(false);
}
SCRIPT_DEFINE_FUNC_3(void, SetGameEntityDescriptionTrans, string, string, string)
//-----------------------------------------------------------------------
static void __stdcall SetGameEntityDescriptionOnceTrans(std::string asName,
std::string asTransCat,
std::string asTransName)
{
cInit *mpInit = gpInit;
GAME_ENTITY_BEGIN(asName)
pEntity->SetDescription(kTranslate(asTransCat,asTransName));
pEntity->SetShowDescritionOnce(true);
}
SCRIPT_DEFINE_FUNC_3(void, SetGameEntityDescriptionOnceTrans, string, string, string)
//-----------------------------------------------------------------------
static void __stdcall SetGameEntityDescription(std::string asName, std::string asMessage)
{
GAME_ENTITY_BEGIN(asName)
pEntity->SetDescription(cString::To16Char(asMessage));
pEntity->SetShowDescritionOnce(false);
}
SCRIPT_DEFINE_FUNC_2(void,SetGameEntityDescription,string,string)
static void __stdcall SetGameEntityGameNameTrans(std::string asName,
std::string asTransCat,
std::string asTransName)
{
cInit *mpInit = gpInit;
GAME_ENTITY_BEGIN(asName)
pEntity->SetGameName(kTranslate(asTransCat,asTransName));
}
SCRIPT_DEFINE_FUNC_3(void, SetGameEntityGameNameTrans, string, string, string)
//-----------------------------------------------------------------------
static void __stdcall ChangeEntityAnimation(std::string asName,
std::string asAnimation,
bool abLoop)
{
GAME_ENTITY_BEGIN(asName)
pEntity->GetMeshEntity()->PlayName(asAnimation,abLoop, true);
}
SCRIPT_DEFINE_FUNC_3(void, ChangeEntityAnimation, string, string, bool)
//-----------------------------------------------------------------------
static void __stdcall SetEntityHealth(std::string asName, float afHealth)
{
GAME_ENTITY_BEGIN(asName)
pEntity->SetHealth(afHealth);