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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*/
#include "hpl1/engine/game/ScriptFuncs.h"
#include "hpl1/engine/game/Game.h"
#include "hpl1/engine/graphics/Beam.h"
#include "hpl1/engine/graphics/BillBoard.h"
#include "hpl1/engine/graphics/Graphics.h"
#include "hpl1/engine/graphics/ParticleSystem3D.h"
#include "hpl1/engine/graphics/Renderer3D.h"
#include "hpl1/engine/input/Input.h"
#include "hpl1/engine/libraries/angelscript/angelscript.h"
#include "hpl1/engine/math/Math.h"
#include "hpl1/engine/physics/PhysicsBody.h"
#include "hpl1/engine/physics/PhysicsController.h"
#include "hpl1/engine/physics/PhysicsJoint.h"
#include "hpl1/engine/physics/PhysicsJointHinge.h"
#include "hpl1/engine/physics/PhysicsJointScrew.h"
#include "hpl1/engine/physics/PhysicsJointSlider.h"
#include "hpl1/engine/resources/Resources.h"
#include "hpl1/engine/resources/SoundEntityManager.h"
#include "hpl1/engine/resources/SoundManager.h"
#include "hpl1/engine/resources/TextureManager.h"
#include "hpl1/engine/scene/Light3D.h"
#include "hpl1/engine/scene/MeshEntity.h"
#include "hpl1/engine/scene/PortalContainer.h"
#include "hpl1/engine/scene/Scene.h"
#include "hpl1/engine/scene/SoundEntity.h"
#include "hpl1/engine/scene/World3D.h"
#include "hpl1/engine/sound/MusicHandler.h"
#include "hpl1/engine/sound/Sound.h"
#include "hpl1/engine/sound/SoundChannel.h"
#include "hpl1/engine/sound/SoundData.h"
#include "hpl1/engine/sound/SoundEntityData.h"
#include "hpl1/engine/sound/SoundHandler.h"
#include "hpl1/engine/system/Script.h"
#include "hpl1/engine/system/String.h"
#include "hpl1/engine/system/System.h"
#include "hpl1/engine/system/low_level_system.h"
namespace hpl {
//////////////////////////////////////////////////////////////////////////
// JOINT CALLBACK
//////////////////////////////////////////////////////////////////////////
cScriptJointCallback::cScriptJointCallback(cScene *apScene) {
mpScene = apScene;
msMaxFunc = "";
msMinFunc = "";
}
void cScriptJointCallback::OnMinLimit(iPhysicsJoint *apJoint) {
if (msMinFunc != "") {
iScript *pScript = mpScene->GetWorld3D()->GetScript();
tString sCommand = msMinFunc + "(\"" + apJoint->GetName() + "\")";
if (pScript->Run(sCommand) == false) {
Warning("Couldn't run script command '%s'\n", sCommand.c_str());
}
}
}
void cScriptJointCallback::OnMaxLimit(iPhysicsJoint *apJoint) {
if (msMaxFunc != "") {
iScript *pScript = mpScene->GetWorld3D()->GetScript();
tString sCommand = msMaxFunc + "(\"" + apJoint->GetName() + "\")";
if (pScript->Run(sCommand) == false) {
Warning("Couldn't run script command '%s'\n", sCommand.c_str());
}
}
}
//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////
static cResources *gpResources = NULL;
static cSystem *gpSystem = NULL;
static cInput *gpInput = NULL;
static cGraphics *gpGraphics = NULL;
static cScene *gpScene = NULL;
static cSound *gpSound = NULL;
static cGame *gpGame = NULL;
//-----------------------------------------------------------------------
static void Print(tString asText) {
Log(asText.c_str());
}
SCRIPT_DEFINE_FUNC_1(void, Print, string)
static tString FloatToString(float afX) {
char sTemp[30];
snprintf(sTemp, 30, "%f", afX);
return (tString)sTemp;
}
SCRIPT_DEFINE_FUNC_1(string, FloatToString, float)
static tString IntToString(int alX) {
char sTemp[30];
snprintf(sTemp, 30, "%d", alX);
return (tString)sTemp;
}
SCRIPT_DEFINE_FUNC_1(string, IntToString, int)
static float RandFloat(float afMin, float afMax) {
return cMath::RandRectf(afMin, afMax);
}
SCRIPT_DEFINE_FUNC_2(float, RandFloat, float, float)
static int RandInt(int alMin, int alMax) {
return cMath::RandRectl(alMin, alMax);
}
SCRIPT_DEFINE_FUNC_2(int, RandInt, int, int)
static bool StringContains(tString asString, tString asSubString) {
return cString::GetLastStringPos(asString, asSubString) >= 0;
}
SCRIPT_DEFINE_FUNC_2(bool, StringContains, string, string)
static void ResetLogicTimer() {
gpGame->ResetLogicTimer();
}
SCRIPT_DEFINE_FUNC(void, ResetLogicTimer)
/////////////////////////////////////////////////////////////////////////
/////// RENDERER //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
/**
* Sets ambient light color-
**/
static void SetAmbientColor(float afR, float afG, float afB) {
gpGraphics->GetRenderer3D()->SetAmbientColor(cColor(afR, afG, afB, 1.0f));
}
SCRIPT_DEFINE_FUNC_3(void, SetAmbientColor, float, float, float)
//-----------------------------------------------------------------------
/**
* Sets if the skybox should be active
**/
static void SetSkyboxActive(bool abX) {
gpGraphics->GetRenderer3D()->SetSkyBoxActive(abX);
}
SCRIPT_DEFINE_FUNC_1(void, SetSkyboxActive, bool)
//-----------------------------------------------------------------------
/**
* Sets the skybox color.
**/
static void SetSkyboxColor(float afR, float afG, float afB, float afA) {
gpGraphics->GetRenderer3D()->SetSkyBoxColor(cColor(afR, afG, afB, afA));
}
SCRIPT_DEFINE_FUNC_4(void, SetSkyboxColor, float, float, float, float)
//-----------------------------------------------------------------------
/**
* Sets the skybox
* \param asTexture Name of the cube map texture to use
**/
static void SetSkybox(tString asTexture) {
if (asTexture != "") {
iTexture *pTex = gpResources->GetTextureManager()->CreateCubeMap(asTexture, false);
gpGraphics->GetRenderer3D()->SetSkyBox(pTex, true);
} else {
gpGraphics->GetRenderer3D()->SetSkyBox(NULL, false);
}
}
SCRIPT_DEFINE_FUNC_1(void, SetSkybox, string)
//-----------------------------------------------------------------------
/**
* Creates a particle system and attaches it to the camera.
* \param asName Name of particle system
* \param asType The type of particle system (file)
**/
static void CreateParticleSystemOnCamera(tString asName, tString asType) {
cParticleSystem3D *pPS = gpScene->GetWorld3D()->CreateParticleSystem(asName, asType,
1, cMatrixf::Identity);
if (pPS) {
cCamera3D *pCam = static_cast<cCamera3D *>(gpScene->GetCamera());
pCam->AttachEntity(pPS);
}
}
SCRIPT_DEFINE_FUNC_2(void, CreateParticleSystemOnCamera, string, string)
//-----------------------------------------------------------------------
/**
* Sets if fog should be active
* \param abX If the fog is active or not.
**/
static void SetFogActive(bool abX) {
gpGraphics->GetRenderer3D()->SetFogActive(abX);
}
SCRIPT_DEFINE_FUNC_1(void, SetFogActive, bool)
/**
* Sets if the fog should be used to cull non-visible objects
* \param abX If the culling is active or not.
**/
static void SetFogCulling(bool abX) {
gpGraphics->GetRenderer3D()->SetFogCulling(abX);
}
SCRIPT_DEFINE_FUNC_1(void, SetFogCulling, bool)
/**
* Creates a particle system and attaches it to the camera.
* \param afStart Start of fog color
* \param afStart End of fog fade. After this limit all geometry is full fog color.
* \param afR, afG, afB Color of Fog.
**/
static void SetFogProperties(float afStart, float afEnd, float afR, float afG, float afB) {
gpGraphics->GetRenderer3D()->SetFogStart(afStart);
gpGraphics->GetRenderer3D()->SetFogEnd(afEnd);
gpGraphics->GetRenderer3D()->SetFogColor(cColor(afR, afG, afB, 1.0f));
}
SCRIPT_DEFINE_FUNC_5(void, SetFogProperties, float, float, float, float, float)
//-----------------------------------------------------------------------
static void SetSectorProperties(tString asSector, float afAmbR, float afAmbG, float afAmbB) {
cPortalContainer *pContainer = gpScene->GetWorld3D()->GetPortalContainer();
cSector *pSector = pContainer->GetSector(asSector);
if (pSector == NULL) {
Warning("Could not find sector '%s'\n", asSector.c_str());
return;
}
pSector->SetAmbientColor(cColor(afAmbR, afAmbG, afAmbB, 1));
}
SCRIPT_DEFINE_FUNC_4(void, SetSectorProperties, string, float, float, float)
//-----------------------------------------------------------------------
static void SetSectorPortalActive(tString asSector, int alPortal, bool abActive) {
cPortalContainer *pContainer = gpScene->GetWorld3D()->GetPortalContainer();
cSector *pSector = pContainer->GetSector(asSector);
if (pSector == NULL) {
Warning("Could not find sector '%s'\n", asSector.c_str());
return;
}
cPortal *pPortal = pSector->GetPortal(alPortal);
if (pPortal == NULL) {
Warning("Could not find portal %d in sector '%s'\n", alPortal, asSector.c_str());
return;
}
pPortal->SetActive(abActive);
}
SCRIPT_DEFINE_FUNC_3(void, SetSectorPortalActive, string, int, bool)
/////////////////////////////////////////////////////////////////////////
/////// RESOURCES //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
/**
* Gets a string in the current language.
* \param asCat The translation category
* \param asName The name of the category entry.
**/
static tString Translate(tString asCat, tString asName) {
tWString wsText = gpResources->Translate(asCat, asName);
return wsText;
}
SCRIPT_DEFINE_FUNC_2(string, Translate, string, string)
//-----------------------------------------------------------------------
/**
* Preloads the data for a sound.
* \param asFile This can be a wav, ogg, mp3 or snt file.
**/
static void PreloadSound(tString asFile) {
tString sExt = cString::ToLowerCase(cString::GetFileExt(asFile));
if (sExt == "snt") {
cSoundEntityData *pData = gpResources->GetSoundEntityManager()->CreateSoundEntity(asFile);
if (pData == NULL) {
Warning("Couldn't preload sound '%s'\n", asFile.c_str());
return;
}
if (pData->GetMainSoundName() != "") {
iSoundChannel *pChannel = gpSound->GetSoundHandler()->CreateChannel(pData->GetMainSoundName(), 0);
hplDelete(pChannel);
}
if (pData->GetStartSoundName() != "") {
iSoundChannel *pChannel = gpSound->GetSoundHandler()->CreateChannel(pData->GetStartSoundName(), 0);
hplDelete(pChannel);
}
if (pData->GetStopSoundName() != "") {
iSoundChannel *pChannel = gpSound->GetSoundHandler()->CreateChannel(pData->GetStopSoundName(), 0);
hplDelete(pChannel);
}
} else {
iSoundData *pSound = gpResources->GetSoundManager()->CreateSoundData(asFile, false);
if (pSound) {
Warning("Couldn't preload sound '%s'\n", asFile.c_str());
}
}
}
SCRIPT_DEFINE_FUNC_1(void, PreloadSound, string)
//-----------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////
/////// MESH ENTITY //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
static void SetMeshActive(tString asName, bool abActive) {
cMeshEntity *pEnt = gpScene->GetWorld3D()->GetMeshEntity(asName);
if (pEnt == NULL) {
Warning("Didn't find mesh entity '%s'\n", asName.c_str());
return;
}
pEnt->SetActive(abActive);
pEnt->SetVisible(abActive);
}
SCRIPT_DEFINE_FUNC_2(void, SetMeshActive, string, bool)
//-----------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////
/////// PARTICLE SYSTEM //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
/**
* Create a particle system at the position of an area
* \param asName The name of the particle system.
* \param abActive If it should be active or not.
**/
static void SetParticleSystemActive(tString asName, bool abActive) {
cParticleSystem3D *pPS = gpScene->GetWorld3D()->GetParticleSystem(asName);
if (pPS == NULL) {
Warning("Didn't find particle system '%s'\n", asName.c_str());
return;
}
pPS->SetActive(abActive);
pPS->SetVisible(abActive);
}
SCRIPT_DEFINE_FUNC_2(void, SetParticleSystemActive, string, bool)
//-----------------------------------------------------------------------
/**
* Create a particle system at the position of an area
* \param asName The name of the particle system.
* \param asType The type of aprticle system
* \param asArea The name of the area
* \param X Y and Z the variables of the particle system.
**/
static void CreateParticleSystem(tString asName, tString asType, tString asArea,
float afX, float afY, float afZ) {
cAreaEntity *pArea = gpScene->GetWorld3D()->GetAreaEntity(asArea);
if (pArea == NULL) {
Warning("Couldn't find area '%s'\n", asArea.c_str());
return;
}
cParticleSystem3D *pPS = gpScene->GetWorld3D()->CreateParticleSystem(asName, asType,
cVector3f(afX, afY, afZ), pArea->m_mtxTransform);
if (pPS == NULL) {
Warning("No particle system of type '%s'\n", asType.c_str());
return;
}
}
SCRIPT_DEFINE_FUNC_6(void, CreateParticleSystem, string, string, string, float, float, float)
//-----------------------------------------------------------------------
/**
* Kill a particle system
* \param asName The name of the particle system.
**/
static void KillParticleSystem(tString asName) {
/*cParticleSystem3D *pPS = gpScene->GetWorld3D()->GetParticleSystem(asName);
if(pPS==NULL){
Warning("Didn't find particle system '%s'\n",asName.c_str());
return;
}
pPS->Kill();*/
bool bFound = false;
cParticleSystem3DIterator it = gpScene->GetWorld3D()->GetParticleSystemIterator();
while (it.HasNext()) {
cParticleSystem3D *pPS = it.Next();
if (pPS->GetName() == asName) {
pPS->Kill();
bFound = true;
}
}
if (!bFound)
Warning("Didn't find particle system '%s'\n", asName.c_str());
}
SCRIPT_DEFINE_FUNC_1(void, KillParticleSystem, string)
//-----------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////
/////// BEAM //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
/**
* Creates an a beam between two areas
* \param asName
* \param asFile
* \param asStartArea
* \param asEndArea
*/
static void CreateBeam(tString asName, tString asFile,
tString asStartArea, tString asEndArea) {
cAreaEntity *pStartArea = gpScene->GetWorld3D()->GetAreaEntity(asStartArea);
if (pStartArea == NULL) {
Warning("Couldn't find area '%s'\n", asStartArea.c_str());
return;
}
cAreaEntity *pEndArea = gpScene->GetWorld3D()->GetAreaEntity(asEndArea);
if (pEndArea == NULL) {
Warning("Couldn't find area '%s'\n", asEndArea.c_str());
return;
}
cBeam *pBeam = gpScene->GetWorld3D()->CreateBeam(asName);
if (pBeam->LoadXMLProperties(asFile) == false) {
Error("Couldn't create beam from file '%s'\n", asFile.c_str());
gpScene->GetWorld3D()->DestroyBeam(pBeam);
return;
}
pBeam->SetPosition(pStartArea->m_mtxTransform.GetTranslation());
pBeam->GetEnd()->SetPosition(pEndArea->m_mtxTransform.GetTranslation());
}
SCRIPT_DEFINE_FUNC_4(void, CreateBeam, string, string, string, string)
//-----------------------------------------------------------------------
/**
* Destroys a beam
* \param asName
*/
static void DestroyBeam(tString asName) {
cBeam *pBeam = gpScene->GetWorld3D()->GetBeam(asName);
if (pBeam == NULL) {
Warning("Couldn't find beam '%s'\n", asName.c_str());
return;
}
gpScene->GetWorld3D()->DestroyBeam(pBeam);
}
SCRIPT_DEFINE_FUNC_1(void, DestroyBeam, string)
//-----------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////
/////// LIGHT //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
/**
* Fades a sound to a color and a radius
* \param asName The name of the light
* \param afR The red channel to fade to.
* \param afG The green channel to fade to.
* \param afB The blue channel to fade to.
* \param afA The alpha channel to fade to.
* \param afRadius The radius to fade to.
* \param afTime The amount of seconds the fade should last.
**/
static void FadeLight3D(tString asName, float afR, float afG, float afB, float afA,
float afRadius, float afTime) {
iLight3D *pLight = gpScene->GetWorld3D()->GetLight(asName);
if (pLight == NULL) {
Warning("Couldn't find light '%s'\n", asName.c_str());
return;
}
pLight->FadeTo(cColor(afR, afG, afB, afA), afRadius, afTime);
pLight->SetVisible(true);
pLight->UpdateLight(2.0f / 60.0f);
}
SCRIPT_DEFINE_FUNC_7(void, FadeLight3D, string, float, float, float, float, float, float)
//-----------------------------------------------------------------------
/**
* Attaches a billboard to a light
* \param asBillboardName The billbaord name
* \param asLightName The light name
* \param abX True if it should be attached, false if you want to remove.
**/
static void AttachBillboardToLight3D(tString asBillboardName, tString asLightName, bool abX) {
iLight3D *pLight = gpScene->GetWorld3D()->GetLight(asLightName);
if (pLight == NULL) {
Warning("Couldn't find light '%s'\n", asLightName.c_str());
return;
}
cBillboard *pBillboard = gpScene->GetWorld3D()->GetBillboard(asBillboardName);
if (pBillboard == NULL) {
Warning("Couldn't find billboard '%s'\n", asBillboardName.c_str());
return;
}
if (abX)
pLight->AttachBillboard(pBillboard);
else
pLight->RemoveBillboard(pBillboard);
}
SCRIPT_DEFINE_FUNC_3(void, AttachBillboardToLight3D, string, string, bool)
//-----------------------------------------------------------------------
/**
* Sets on/off a light
* \param asName The light name
* \param abX if the light should be on or off.
**/
static void SetLight3DVisible(tString asName, bool abX) {
iLight3D *pLight = gpScene->GetWorld3D()->GetLight(asName);
if (pLight == NULL) {
Warning("Couldn't find light '%s'\n", asName.c_str());
return;
}
pLight->SetVisible(abX);
}
SCRIPT_DEFINE_FUNC_2(void, SetLight3DVisible, string, bool)
//-----------------------------------------------------------------------
/**
* Sets on/off for affect only in sector where centre is.
* \param asName The light name
* \param abX if the light should only affects objects in same sector or not.
**/
static void SetLight3DOnlyAffectInSector(tString asName, bool abX) {
iLight3D *pLight = gpScene->GetWorld3D()->GetLight(asName);
if (pLight == NULL) {
Warning("Couldn't find light '%s'\n", asName.c_str());
return;
}
pLight->SetOnlyAffectInSector(abX);
}
SCRIPT_DEFINE_FUNC_2(void, SetLight3DOnlyAffectInSector, string, bool)
//-----------------------------------------------------------------------
/**
* Sets flickering on/off a light
* \param asName The light name
* \param abX if the light flicker should be on or off.
**/
static void SetLight3DFlickerActive(tString asName, bool abX) {
iLight3D *pLight = gpScene->GetWorld3D()->GetLight(asName);
if (pLight == NULL) {
Warning("Couldn't find light '%s'\n", asName.c_str());
return;
}
pLight->SetFlickerActive(abX);
}
SCRIPT_DEFINE_FUNC_2(void, SetLight3DFlickerActive, string, bool)
//-----------------------------------------------------------------------
/**
* Sets flickering parameters
* \param asName The light name
* \param abR, afG, afB, afA The color of the light when off
* \param afRadius The radius of the light when off.
* \param afOnMinLength Minimum time before going from off to on.
* \param afOnMaxLength Maximum time before going from off to on.
* \param asOnSound Name of the sound played when going from off to on. "" means no sound.
* \param asOnPS Name of the particle system played when going from off to on. "" means none.
* \param afOffMinLength Minimum time before going from on to off.
* \param afOffMaxLength Maximum time before going from on to off.
* \param asOffSound Name of the sound played when going from on to off. "" means no sound.
* \param asOffPS Name of the particle system played when going from on to off. "" means none.
* \param abFade If there should be a fade between off and on.
* \param afOnFadeLength Fade length from off to on.
* \param afOffFadeLength Fade length from on to off.
**/
static void SetLight3DFlicker(tString asName,
float afR, float afG, float afB, float afA,
float afRadius,
float afOnMinLength, float afOnMaxLength,
tString asOnSound, tString asOnPS,
float afOffMinLength, float afOffMaxLength,
tString asOffSound, tString asOffPS,
bool abFade,
float afOnFadeLength, float afOffFadeLength) {
iLight3D *pLight = gpScene->GetWorld3D()->GetLight(asName);
if (pLight == NULL) {
Warning("Couldn't find light '%s'\n", asName.c_str());
return;
}
pLight->SetFlicker(cColor(afR, afG, afB, afA), afRadius,
afOnMinLength, afOnMaxLength, asOnSound, asOnPS,
afOffMinLength, afOffMaxLength, asOffSound, asOffPS,
abFade, afOnFadeLength, afOffFadeLength);
}
SCRIPT_DEFINE_FUNC_17(void, SetLight3DFlicker, string,
float, float, float, float,
float, float, float, string, string, float, float, string, string, bool, float, float)
//-----------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////
/////// SOUND //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
/**
* Creates a sound entity at the position of an area.
* \param asName Name of the sound area
* \param asFile The snt file to load.
* \param asArea The area to create at.
*/
static void CreateSoundEntity(tString asName, tString asFile,
tString asArea) {
cAreaEntity *pArea = gpScene->GetWorld3D()->GetAreaEntity(asArea);
if (pArea == NULL) {
Warning("Couldn't find area '%s'\n", asArea.c_str());
return;
}
cSoundEntity *pSound = gpScene->GetWorld3D()->CreateSoundEntity(asName, asFile, true);
if (pSound == NULL) {
Warning("Couldn't create sound entity '%s'\n", asFile.c_str());
return;
}
pSound->SetPosition(pArea->m_mtxTransform.GetTranslation());
}
SCRIPT_DEFINE_FUNC_3(void, CreateSoundEntity, string, string, string)
//-----------------------------------------------------------------------
/**
* Play a sound entity
* \param asName The entity name
* \param abPlayStart If the start sound should be played.
**/
static void PlaySoundEntity(tString asName, bool abPlayStart) {
cSoundEntity *pSound = gpScene->GetWorld3D()->GetSoundEntity(asName);
if (pSound == NULL) {
Warning("Couldn't find sound entity '%s'\n", asName.c_str());
return;
}
pSound->Play(abPlayStart);
}
SCRIPT_DEFINE_FUNC_2(void, PlaySoundEntity, string, bool)
/**
* Stop a sound entity
* \param asName The entity name
* \param abPlayEnd If the end sound should be played.
**/
static void StopSoundEntity(tString asName, bool abPlayEnd) {
cSoundEntity *pSound = gpScene->GetWorld3D()->GetSoundEntity(asName);
if (pSound == NULL) {
Warning("Couldn't find sound entity '%s'\n", asName.c_str());
return;
}
pSound->Stop(abPlayEnd);
}
SCRIPT_DEFINE_FUNC_2(void, StopSoundEntity, string, bool)
//-----------------------------------------------------------------------
/**
* Play a sound entity fading it
* \param asName The entity name
* \param afSpeed Volume increase per second.
**/
static void FadeInSoundEntity(tString asName, float afSpeed) {
cSoundEntity *pSound = gpScene->GetWorld3D()->GetSoundEntity(asName);
if (pSound == NULL) {
Warning("Couldn't find sound entity '%s'\n", asName.c_str());
return;
}
pSound->FadeIn(afSpeed);
}
SCRIPT_DEFINE_FUNC_2(void, FadeInSoundEntity, string, float)
/**
* Stop a sound entity fading it
* \param asName The entity name
* \param afSpeed Volume decrease per second.
**/
static void FadeOutSoundEntity(tString asName, float afSpeed) {
cSoundEntity *pSound = gpScene->GetWorld3D()->GetSoundEntity(asName);
if (pSound == NULL) {
Warning("Couldn't find sound entity '%s'\n", asName.c_str());
return;
}
pSound->FadeOut(afSpeed);
}
SCRIPT_DEFINE_FUNC_2(void, FadeOutSoundEntity, string, float)
//-----------------------------------------------------------------------
static void PlayMusic(tString asName, float afVol, float afStepSize, bool abLoop) {
gpSound->GetMusicHandler()->Play(asName, afVol, afStepSize, abLoop);
}
SCRIPT_DEFINE_FUNC_4(void, PlayMusic, string, float, float, bool)
//-----------------------------------------------------------------------
static void StopMusic(float afStepSize) {
gpSound->GetMusicHandler()->Stop(afStepSize);
}
SCRIPT_DEFINE_FUNC_1(void, StopMusic, float)
//-----------------------------------------------------------------------
/**
* Play a sound gui sound, with out any position.
* \param asName The sound name
* \param afVol Volume of the sound
**/
static void PlayGuiSound(tString asName, float afVol) {
gpSound->GetSoundHandler()->PlayGui(asName, false, afVol);
}
SCRIPT_DEFINE_FUNC_2(void, PlayGuiSound, string, float)
/////////////////////////////////////////////////////////////////////////
/////// PHYSICS //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
/**
* Sets a callback for a joint.
* The syntax for the function is: void MyFunction(string asJointName)
* \param asJointName The joint name
* \param asType The type, can be: "OnMax" or "OnMin".
* \param asFunc The script function to be called. Must be in the current script file. "" = disabled.
**/
static void SetJointCallback(tString asJointName, tString asType,
tString asFunc) {
iPhysicsJoint *pJoint = gpScene->GetWorld3D()->GetPhysicsWorld()->GetJoint(asJointName);
if (pJoint == NULL) {
Warning("Couldn't find joint '%s'\n", asJointName.c_str());
return;
}
int lType = 0;
tString sLowName = cString::ToLowerCase(asType);
if (sLowName == "onmax")
lType = 1;
if (sLowName == "onmin")
lType = 2;
if (lType == 0) {
Warning("Joint callback type '%s' does not exist\n", asType.c_str());
return;
}
cScriptJointCallback *pCallback = static_cast<cScriptJointCallback *>(pJoint->GetCallback());
if (pCallback == NULL) {
pCallback = hplNew(cScriptJointCallback, (gpScene));
pJoint->SetCallback(pCallback, true);
}
if (lType == 1)
pCallback->msMaxFunc = asFunc;
if (lType == 2)
pCallback->msMinFunc = asFunc;
}
SCRIPT_DEFINE_FUNC_3(void, SetJointCallback, string, string, string)
//-----------------------------------------------------------------------
/**
* Breaks a joint.
* \param asJointName The joint name
**/
static void BreakJoint(tString asJointName) {
iPhysicsJoint *pJoint = gpScene->GetWorld3D()->GetPhysicsWorld()->GetJoint(asJointName);
if (pJoint == NULL) {
Warning("Couldn't find joint '%s'\n", asJointName.c_str());
return;
}
pJoint->Break();
}
SCRIPT_DEFINE_FUNC_1(void, BreakJoint, string)
//-----------------------------------------------------------------------
/**
* Sets if a joint controller is active or not.
* \param asJointName The joint name
* \param asCtrlName The controller name
* \param abActive If the controller is to be active or not.
**/
static void SetJointControllerActive(tString asJointName, tString asCtrlName, bool abActive) {
iPhysicsJoint *pJoint = gpScene->GetWorld3D()->GetPhysicsWorld()->GetJoint(asJointName);
if (pJoint == NULL) {
Warning("Couldn't find joint '%s'\n", asJointName.c_str());
return;
}
iPhysicsController *pCtrl = pJoint->GetController(asCtrlName);
if (pCtrl == NULL) {
Warning("Couldn't find controller %s in joint '%s'\n", asCtrlName.c_str(), asJointName.c_str());
return;
}
pCtrl->SetActive(abActive);
}
SCRIPT_DEFINE_FUNC_3(void, SetJointControllerActive, string, string, bool)
//-----------------------------------------------------------------------
/**
* Change the active controller. All other controllers are set to false.
* \param asJointName The joint name
* \param asCtrlName The controller name
**/
static void ChangeJointController(tString asJointName, tString asCtrlName) {
iPhysicsJoint *pJoint = gpScene->GetWorld3D()->GetPhysicsWorld()->GetJoint(asJointName);
if (pJoint == NULL) {
Warning("Couldn't find joint '%s'\n", asJointName.c_str());
return;
}
if (pJoint->ChangeController(asCtrlName) == false) {
Warning("Couldn't find controller %s in joint '%s'\n", asCtrlName.c_str(), asJointName.c_str());
return;
}
}
SCRIPT_DEFINE_FUNC_2(void, ChangeJointController, string, string)
//-----------------------------------------------------------------------
/**
* Sets if a joint controller is active or not.
* \param asJointName The joint name
* \param asCtrlName The controller name
* \param asProperty Property to change, can be "DestValue"
* \param afValue Value to set it to.
**/
static void SetJointControllerPropertyFloat(tString asJointName, tString asCtrlName,
tString asProperty, float afValue) {
iPhysicsJoint *pJoint = gpScene->GetWorld3D()->GetPhysicsWorld()->GetJoint(asJointName);
if (pJoint == NULL) {
Warning("Couldn't find joint '%s'\n", asJointName.c_str());
return;
}
iPhysicsController *pCtrl = pJoint->GetController(asCtrlName);
if (pCtrl == NULL) {
Warning("Couldn't find controller %s in joint '%s'\n", asCtrlName.c_str(), asJointName.c_str());
return;
}
if (asProperty == "DestValue") {
pCtrl->SetDestValue(afValue);
}
}
SCRIPT_DEFINE_FUNC_4(void, SetJointControllerPropertyFloat, string, string, string, float)
//-----------------------------------------------------------------------
/**
* Gets a property from the joint.
* Valid properties are:
* "Angle" The angle between the bodies (in degrees) (Not working for ball joint)
* "Distance" The distance between the bodies (in meter)
* "LinearSpeed" The relative linear speed between the bodies (in m/s)
* "AngularSpeed" The relative angular speed between the bodies (in m/s)
* "Force" The size of the force (in newton, kg*m/s^2).
* "MaxLimit" The max limit (meters or degrees)
* "MinLimit" The in limit (meters or degrees)
* \param asJointName The joint name
* \param asProp The property to get
**/
static float GetJointProperty(tString asJointName, tString asProp) {
iPhysicsJoint *pJoint = gpScene->GetWorld3D()->GetPhysicsWorld()->GetJoint(asJointName);
if (pJoint == NULL) {
Warning("Couldn't find joint '%s'\n", asJointName.c_str());
return 0;
}
tString sLowProp = cString::ToLowerCase(asProp);
if (sLowProp == "angle") {
return cMath::ToDeg(pJoint->GetAngle());
} else if (sLowProp == "distance") {
return pJoint->GetDistance();
} else if (sLowProp == "linearspeed") {
return pJoint->GetVelocity().Length();
} else if (sLowProp == "angularspeed") {
return pJoint->GetAngularVelocity().Length();
} else if (sLowProp == "force") {
return pJoint->GetForce().Length();
}
/////////////////////////////
// Min Limit
else if (sLowProp == "minlimit") {
switch (pJoint->GetType()) {
case ePhysicsJointType_Hinge: {
iPhysicsJointHinge *pHingeJoint = static_cast<iPhysicsJointHinge *>(pJoint);
return cMath::ToDeg(pHingeJoint->GetMinAngle());
}
case ePhysicsJointType_Screw: {
iPhysicsJointScrew *pScrewJoint = static_cast<iPhysicsJointScrew *>(pJoint);
return pScrewJoint->GetMinDistance();
}
case ePhysicsJointType_Slider: {
iPhysicsJointSlider *pSliderJoint = static_cast<iPhysicsJointSlider *>(pJoint);
return pSliderJoint->GetMinDistance();
}
case ePhysicsJointType_Ball:
break;
case ePhysicsJointType_LastEnum:
break;
}
}
/////////////////////////////
// Max Limit
else if (sLowProp == "maxlimit") {
switch (pJoint->GetType()) {
case ePhysicsJointType_Hinge: {
iPhysicsJointHinge *pHingeJoint = static_cast<iPhysicsJointHinge *>(pJoint);
return cMath::ToDeg(pHingeJoint->GetMaxAngle());
}
case ePhysicsJointType_Screw: {
iPhysicsJointScrew *pScrewJoint = static_cast<iPhysicsJointScrew *>(pJoint);
return pScrewJoint->GetMaxDistance();
}
case ePhysicsJointType_Slider: {
iPhysicsJointSlider *pSliderJoint = static_cast<iPhysicsJointSlider *>(pJoint);
return pSliderJoint->GetMaxDistance();
}
case ePhysicsJointType_Ball:
break;
case ePhysicsJointType_LastEnum:
break;
}
}
Warning("Joint property '%s' does not exist!\n", asProp.c_str());
return 0;
}
SCRIPT_DEFINE_FUNC_2(float, GetJointProperty, string, string)
//-----------------------------------------------------------------------
/**
* Gets a property from the body.
* Valid properties are:
* "Mass" The mass of the body (in kg)
* "LinearSpeed" The linear speed the body has (in m/s)
* "AngularSpeed" The angular speed the body has (in m/s)
* \param asBodyName The body name
* \param asProp The property to get
**/
static float GetBodyProperty(tString asBodyName, tString asProp) {
iPhysicsBody *pBody = gpScene->GetWorld3D()->GetPhysicsWorld()->GetBody(asBodyName);
if (pBody == NULL) {
Warning("Couldn't find Body '%s'\n", asBodyName.c_str());
return 0;
}
tString sLowProp = cString::ToLowerCase(asProp);
if (sLowProp == "mass") {
return pBody->GetMass();
} else if (sLowProp == "linearspeed") {
return pBody->GetLinearVelocity().Length();
} else if (sLowProp == "angularspeed") {
return pBody->GetAngularVelocity().Length();
}
Warning("Body property '%s' does not exist!\n", asProp.c_str());
return 0;
}
SCRIPT_DEFINE_FUNC_2(float, GetBodyProperty, string, string)
//-----------------------------------------------------------------------
/**
* Sets a property to the body.
* Valid properties are:
* "Mass" The mass of the body (in kg)
* "CollideCharacter" 0 = false 1=true
* \param asBodyName The body name
* \param asProp The property to get
* \param afVal The new value of the property
**/
static void SetBodyProperty(tString asBodyName, tString asProp, float afVal) {
iPhysicsBody *pBody = gpScene->GetWorld3D()->GetPhysicsWorld()->GetBody(asBodyName);
if (pBody == NULL) {
Warning("Couldn't find Body '%s'\n", asBodyName.c_str());
return;
}
tString sLowProp = cString::ToLowerCase(asProp);
if (sLowProp == "mass") {
pBody->SetMass(afVal);
pBody->SetEnabled(true);
if (afVal == 0) {
pBody->SetLinearVelocity(0);
pBody->SetAngularVelocity(0);
}
return;
} else if (sLowProp == "collidecharacter") {
pBody->SetCollideCharacter(afVal < 0.05 ? false : true);
return;
} else if (sLowProp == "hasgravity") {
pBody->SetCollideCharacter(afVal < 0.05 ? false : true);
return;
}
Warning("Body property '%s' does not exist!\n", asProp.c_str());
}
SCRIPT_DEFINE_FUNC_3(void, SetBodyProperty, string, string, float)
//-----------------------------------------------------------------------
static void AttachBodiesWithJoint(tString asParentName, tString asChildName, tString asJointName) {
iPhysicsBody *pParent = gpScene->GetWorld3D()->GetPhysicsWorld()->GetBody(asParentName);
if (pParent == NULL) {
Warning("Couldn't find Body '%s'\n", asParentName.c_str());
return;
}
iPhysicsBody *pChild = gpScene->GetWorld3D()->GetPhysicsWorld()->GetBody(asChildName);
if (pChild == NULL) {
Warning("Couldn't find Body '%s'\n", asChildName.c_str());
return;
}
iPhysicsWorld *pPhysicsWorld = gpScene->GetWorld3D()->GetPhysicsWorld();
cVector3f vPivot = (pParent->GetLocalPosition() + pChild->GetLocalPosition()) * 0.5f;
cVector3f vDir = cMath::Vector3Normalize(pChild->GetLocalPosition() - pParent->GetLocalPosition());
iPhysicsJointSlider *pJoint = pPhysicsWorld->CreateJointSlider(asJointName, vPivot, vDir, pParent, pChild);
pJoint->SetMinDistance(-0.01f);
pJoint->SetMaxDistance(0.01f);
}
SCRIPT_DEFINE_FUNC_3(void, AttachBodiesWithJoint, string, string, string)
//-----------------------------------------------------------------------
/**
* Sets a property to the joint.
* Valid properties are:
* "MinLimit" The min limit (depends on joint, does not work on ball)
* "MaxLimit" The max limit (depends on joint, does not work on ball)
* \param asJointName The body name
* \param asProp The property to get
* \param afVal The new value of the property
**/
static void SetJointProperty(tString asJointName, tString asProp, float afVal) {
iPhysicsJoint *pJoint = gpScene->GetWorld3D()->GetPhysicsWorld()->GetJoint(asJointName);
if (pJoint == NULL) {
Warning("Couldn't find joint '%s'\n", asJointName.c_str());
return;
}
tString sLowProp = cString::ToLowerCase(asProp);
if (pJoint->GetChildBody())
pJoint->GetChildBody()->SetEnabled(true);
if (pJoint->GetParentBody())
pJoint->GetParentBody()->SetEnabled(true);
/////////////////////////////
// Min Limit
if (sLowProp == "minlimit") {
switch (pJoint->GetType()) {
case ePhysicsJointType_Hinge: {
iPhysicsJointHinge *pHingeJoint = static_cast<iPhysicsJointHinge *>(pJoint);
pHingeJoint->SetMinAngle(cMath::ToRad(afVal));
break;
}
case ePhysicsJointType_Screw: {
iPhysicsJointScrew *pScrewJoint = static_cast<iPhysicsJointScrew *>(pJoint);
pScrewJoint->SetMinDistance(afVal);
break;
}
case ePhysicsJointType_Slider: {
iPhysicsJointSlider *pSliderJoint = static_cast<iPhysicsJointSlider *>(pJoint);
pSliderJoint->SetMinDistance(afVal);
break;
}
default:
break;
}
}
/////////////////////////////
// Max Limit
else if (sLowProp == "maxlimit") {
switch (pJoint->GetType()) {
case ePhysicsJointType_Hinge: {
iPhysicsJointHinge *pHingeJoint = static_cast<iPhysicsJointHinge *>(pJoint);
pHingeJoint->SetMaxAngle(cMath::ToRad(afVal));
break;
}
case ePhysicsJointType_Screw: {
iPhysicsJointScrew *pScrewJoint = static_cast<iPhysicsJointScrew *>(pJoint);
pScrewJoint->SetMaxDistance(afVal);
break;
}
case ePhysicsJointType_Slider: {
iPhysicsJointSlider *pSliderJoint = static_cast<iPhysicsJointSlider *>(pJoint);
pSliderJoint->SetMaxDistance(afVal);
break;
}
default:
break;
}
} else {
Warning("Joint property '%s' does not exist!\n", asProp.c_str());
}
}
SCRIPT_DEFINE_FUNC_3(void, SetJointProperty, string, string, float)
//-----------------------------------------------------------------------
/**
* Adds a force to the body. This can either be in the bodies local coord system or the world's.
* \param asBodyName The body name
* \param asCoordType The coordinate system type. "World" or "Local".
* \param afX force in the x direction. (in newton, kg*m/s^2)
* \param afY force in the y direction. (in newton, kg*m/s^2)
* \param afZ force in the z direction. (in newton, kg*m/s^2)
**/
static void AddBodyForce(tString asBodyName, tString asCoordType,
float afX, float afY, float afZ) {
iPhysicsBody *pBody = gpScene->GetWorld3D()->GetPhysicsWorld()->GetBody(asBodyName);
if (pBody == NULL) {
Warning("Couldn't find Body '%s'\n", asBodyName.c_str());
return;
}
int lType = 0;
tString sLowType = cString::ToLowerCase(asCoordType);
if (sLowType == "world")
lType = 1;
else if (sLowType == "local")
lType = 2;
if (lType == 0) {
Warning("Coord system type '%s' is not valid.\n", asCoordType.c_str());
return;
}
if (lType == 1) {
pBody->AddForce(cVector3f(afX, afY, afZ));
} else if (lType == 2) {
cVector3f vWorldForce = cMath::MatrixMul(pBody->GetLocalMatrix().GetRotation(),
cVector3f(afX, afY, afZ));
pBody->AddForce(vWorldForce);
}
}
SCRIPT_DEFINE_FUNC_5(void, AddBodyForce, string, string, float, float, float)
//-----------------------------------------------------------------------
/**
* Adds an impule (a change in velocity) to the body. This can either be in the bodies local coord system or the world's.
* \param asBodyName The body name
* \param asCoordType The coordinate system type. "World" or "Local".
* \param afX velocity in the x direction. (in m/s)
* \param afY velocity in the y direction. (in m/s)
* \param afZ velocity in the z direction. (in m/s)
**/
static void AddBodyImpulse(tString asBodyName, tString asCoordType,
float afX, float afY, float afZ) {
iPhysicsBody *pBody = gpScene->GetWorld3D()->GetPhysicsWorld()->GetBody(asBodyName);
if (pBody == NULL) {
Warning("Couldn't find Body '%s'\n", asBodyName.c_str());
return;
}
int lType = 0;
tString sLowType = cString::ToLowerCase(asCoordType);
if (sLowType == "world")
lType = 1;
else if (sLowType == "local")
lType = 2;
if (lType == 0) {
Warning("Coord system type '%s' is not valid.\n", asCoordType.c_str());
return;
}
if (lType == 1) {
pBody->AddImpulse(cVector3f(afX, afY, afZ));
} else if (lType == 2) {
cVector3f vWorldForce = cMath::MatrixMul(pBody->GetLocalMatrix().GetRotation(),
cVector3f(afX, afY, afZ));
pBody->AddImpulse(vWorldForce);
}
}
SCRIPT_DEFINE_FUNC_5(void, AddBodyImpulse, string, string, float, float, float)
//-----------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////
/////// LOCAL VARS //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
static void CreateLocalVar(tString asName, int alVal) {
if (gpScene->GetLocalVar(asName) == NULL) {
cScriptVar *pVar = gpScene->CreateLocalVar(asName);
pVar->mlVal = alVal;
}
}
SCRIPT_DEFINE_FUNC_2(void, CreateLocalVar, string, int)
static void SetLocalVar(tString asName, int alVal) {
cScriptVar *pVar = gpScene->CreateLocalVar(asName);
pVar->mlVal = alVal;
}
SCRIPT_DEFINE_FUNC_2(void, SetLocalVar, string, int)
static void AddLocalVar(tString asName, int alVal) {
cScriptVar *pVar = gpScene->CreateLocalVar(asName);
pVar->mlVal += alVal;
}
SCRIPT_DEFINE_FUNC_2(void, AddLocalVar, string, int)
static int GetLocalVar(tString asName) {
cScriptVar *pVar = gpScene->GetLocalVar(asName);
if (pVar == NULL) {
Error("Couldn't find local var '%s'\n", asName.c_str());
return 0;
}
return pVar->mlVal;
}
SCRIPT_DEFINE_FUNC_1(int, GetLocalVar, string)
//-----------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////
/////// GLOBAL VARS //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
static void CreateGlobalVar(tString asName, int alVal) {
if (gpScene->GetGlobalVar(asName) == NULL) {
cScriptVar *pVar = gpScene->CreateGlobalVar(asName);
pVar->mlVal = alVal;
}
}
SCRIPT_DEFINE_FUNC_2(void, CreateGlobalVar, string, int)
static void SetGlobalVar(tString asName, int alVal) {
cScriptVar *pVar = gpScene->CreateGlobalVar(asName);
pVar->mlVal = alVal;
}
SCRIPT_DEFINE_FUNC_2(void, SetGlobalVar, string, int)
static void AddGlobalVar(tString asName, int alVal) {
cScriptVar *pVar = gpScene->CreateGlobalVar(asName);
pVar->mlVal += alVal;
}
SCRIPT_DEFINE_FUNC_2(void, AddGlobalVar, string, int)
static int GetGlobalVar(tString asName) {
cScriptVar *pVar = gpScene->GetGlobalVar(asName);
if (pVar == NULL) {
Error("Couldn't find global var '%s'\n", asName.c_str());
return 0;
}
return pVar->mlVal;
}
SCRIPT_DEFINE_FUNC_1(int, GetGlobalVar, string)
//-----------------------------------------------------------------------
void cScriptFuncs::Init(cGraphics *apGraphics,
cResources *apResources,
cSystem *apSystem,
cInput *apInput,
cScene *apScene,
cSound *apSound,
cGame *apGame) {
gpGraphics = apGraphics;
gpResources = apResources;
gpSystem = apSystem;
gpInput = apInput;
gpScene = apScene;
gpSound = apSound;
gpGame = apGame;
// General
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(Print));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(FloatToString));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(IntToString));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(RandFloat));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(RandInt));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(StringContains));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(ResetLogicTimer));
// Renderer
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetAmbientColor));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetSkybox));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetSkyboxActive));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetSkyboxColor));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(CreateParticleSystemOnCamera));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetFogActive));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetFogCulling));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetFogProperties));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetSectorProperties));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetSectorPortalActive));
// Resources
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(PreloadSound));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(Translate));
// Mesh Entity
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetMeshActive));
// Beams
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(CreateBeam));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(DestroyBeam));
// Particle systems
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetParticleSystemActive));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(CreateParticleSystem));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(KillParticleSystem));
// Light
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(FadeLight3D));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(AttachBillboardToLight3D));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetLight3DVisible));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetLight3DFlickerActive));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetLight3DFlicker));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetLight3DOnlyAffectInSector));
// Sound
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(PlayMusic));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(StopMusic));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(PlaySoundEntity));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(StopSoundEntity));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(FadeInSoundEntity));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(FadeOutSoundEntity));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(PlayGuiSound));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(CreateSoundEntity));
// Physics
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetJointCallback));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(BreakJoint));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(GetJointProperty));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(GetBodyProperty));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetBodyProperty));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetJointProperty));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(AttachBodiesWithJoint));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetJointControllerActive));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(ChangeJointController));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetJointControllerPropertyFloat));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(AddBodyForce));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(AddBodyImpulse));
// Local vars
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(CreateLocalVar));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetLocalVar));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(AddLocalVar));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(GetLocalVar));
// Global vars
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(CreateGlobalVar));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(SetGlobalVar));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(AddGlobalVar));
gpSystem->GetLowLevel()->addScriptFunc(SCRIPT_REGISTER_FUNC(GetGlobalVar));
}
//-----------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
//////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
} // namespace hpl
|