00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "revolt.h"
00019 #include "main.h"
00020 #include "geom.h"
00021 #include "particle.h"
00022 #include "model.h"
00023 #include "aerial.h"
00024 #include "newcoll.h"
00025 #include "body.h"
00026 #include "car.h"
00027 #include "ctrlread.h"
00028 #include "object.h"
00029 #include "obj_init.h"
00030 #include "player.h"
00031 #include "ai.h"
00032 #include "ai_init.h"
00033 #include "editobj.h"
00034 #include "drawobj.h"
00035 #include "move.h"
00036 #include "timing.h"
00037 #include "visibox.h"
00038 #include "spark.h"
00039 #include "field.h"
00040 #include "weapon.h"
00041 #ifdef _PC
00042 #include "input.h"
00043 #endif
00044 #ifdef _N64
00045 #include "ffs_code.h"
00046 #include "ffs_list.h"
00047 #include "utils.h"
00048 #endif
00049
00050 #ifdef _PC
00051
00052
00053 static char *DragonMorphFrames[] = {
00054 "models\\dragon2.m",
00055 "models\\dragon3.m",
00056 };
00057
00058 static VEC DragonFireOffset = {-494.2f, 208.0f, 96.0f};
00059 static VEC DragonFireDir = {-0.45f, 2.0f, 6.0f};
00060 #endif
00061
00062 STROBE_TABLE StrobeTable[] = {
00063 5, 10, 1024, {192, 192, 0}, {0, 0, 0},
00064 5, 10, 1024, {0, 0, 128}, {0, 12, 0},
00065 };
00066
00068
00070
00071 static long InitBarrel(OBJECT *obj, long *flags);
00072 static long InitFootball(OBJECT *obj, long *flags);
00073 static long InitBeachball(OBJECT *obj, long *flags);
00074 static long InitPlanet(OBJECT *obj, long *flags);
00075 static long InitPlane(OBJECT *obj, long *flags);
00076 static long InitCopter(OBJECT *obj, long *flags);
00077 static long InitDragon(OBJECT *obj, long *flags);
00078 static long InitWater(OBJECT *obj, long *flags);
00079 static long InitTrolley(OBJECT *obj, long *flags);
00080 static void FreeTrolley(OBJECT *obj);
00081 static long InitBoat(OBJECT *obj, long *flags);
00082 static long InitSpeedup(OBJECT *obj, long *flags);
00083 static long InitRadar(OBJECT *obj, long *flags);
00084 static long InitBalloon(OBJECT *obj, long *flags);
00085 static long InitHorse(OBJECT *obj, long *flags);
00086 static long InitTrain(OBJECT *obj, long *flags);
00087 static long InitStrobe(OBJECT *obj, long *flags);
00088 static long InitSparkGen(OBJECT *obj, long *flags);
00089 static long InitSpaceman(OBJECT *obj, long *flags);
00090 static long InitPickup(OBJECT *obj, long *flags);
00091 static long InitDissolveModel(OBJECT *obj, long *flags);
00092 static long InitFlap(OBJECT *obj, long *flags);
00093 static long InitLaser(OBJECT *obj, long *flags);
00094 static long InitSplash(OBJECT *obj, long *flags);
00095
00096
00097 static OBJECT_INIT_DATA ObjInitData[] = {
00098 InitBarrel, sizeof(BARREL_OBJ),
00099 InitBeachball, 0,
00100 InitPlanet, 0,
00101 InitPlane, sizeof(PLANE_OBJ),
00102 InitCopter, sizeof(COPTER_OBJ),
00103 #ifdef _PC
00104 InitDragon, sizeof(DRAGON_OBJ),
00105 #else
00106 NULL, 0,
00107 #endif
00108 InitWater, 0,
00109 #ifdef _PC
00110 InitTrolley, sizeof(PLAYER),
00111 InitBoat, sizeof(BOAT_OBJ),
00112 InitSpeedup, sizeof(SPEEDUP_OBJ),
00113 InitRadar, sizeof(RADAR_OBJ),
00114 InitBalloon, sizeof(BALLOON_OBJ),
00115 InitHorse, sizeof(HORSE_OBJ),
00116 InitTrain, sizeof(TRAIN_OBJ),
00117 InitStrobe, sizeof(STROBE_OBJ),
00118 InitFootball, 0,
00119 InitSparkGen, sizeof(SPARK_GEN),
00120 InitSpaceman, sizeof(SPACEMAN_OBJ),
00121
00122 InitShockwave, sizeof(SHOCKWAVE_OBJ),
00123 InitFirework, sizeof(FIREWORK_OBJ),
00124 InitPuttyBomb, 0,
00125 InitWaterBomb, sizeof(WATERBOMB_OBJ),
00126 InitElectroPulse, 0,
00127 InitOilSlick, sizeof(OILSLICK_OBJ),
00128 InitOilSlickDropper, sizeof(OILSLICK_DROPPER_OBJ),
00129 InitChromeBall, sizeof(CHROMEBALL_OBJ),
00130 InitClone, sizeof(CLONE_OBJ),
00131 InitTurbo2, sizeof(TURBO2_OBJ),
00132 InitElectroZapped, 0,
00133 InitSpring, sizeof(SPRING_OBJ),
00134
00135 InitPickup, sizeof(PICKUP_OBJ),
00136 InitDissolveModel, 0,
00137
00138 InitFlap, 0,
00139 InitLaser, sizeof(LASER_OBJ),
00140 InitSplash, sizeof(SPLASH_OBJ),
00141 InitBombGlow, 0,
00142 #endif
00143 };
00144
00146
00148
00149 #ifdef _PC
00150 void LoadObjects(char *file)
00151 {
00152 long i;
00153 FILE *fp;
00154 FILE_OBJECT fileobj;
00155 MAT mat;
00156
00157
00158
00159 if (EditMode == EDIT_OBJECTS)
00160 return;
00161
00162
00163
00164 fp = fopen(file, "rb");
00165 if (!fp)
00166 return;
00167
00168
00169
00170 fread(&i, sizeof(i), 1, fp);
00171
00172 for ( ; i ; i--)
00173 {
00174
00175
00176
00177 fread(&fileobj, sizeof(fileobj), 1, fp);
00178
00179
00180
00181 CopyVec(&fileobj.Up, &mat.mv[U]);
00182 CopyVec(&fileobj.Look, &mat.mv[L]);
00183 CrossProduct(&mat.mv[U], &mat.mv[L], &mat.mv[R]);
00184
00185 CreateObject(&fileobj.Pos, &mat, fileobj.ID, fileobj.Flag);
00186 }
00187
00188
00189
00190 fclose(fp);
00191 }
00192 #endif
00193
00194
00195
00196
00197
00198
00199 #ifdef _N64
00200 void LoadObjects()
00201 {
00202 long i, j;
00203 FIL *fp;
00204 FILE_OBJECT fileobj;
00205 MAT mat;
00206
00207
00208 printf("Loading level objects...\n");
00209 fp = FFS_Open(FFS_TYPE_TRACK | TRK_OBJECTS);
00210 if (!fp)
00211 {
00212 printf("...could not open object file.\n");
00213 return;
00214 }
00215
00216
00217
00218 FFS_Read(&i, sizeof(i), fp);
00219 i = EndConvLong(i);
00220
00221 for ( ; i ; i--)
00222 {
00223
00224
00225 FFS_Read(&fileobj, sizeof(fileobj), fp);
00226 fileobj.ID = EndConvLong(fileobj.ID);
00227 for (j = 0; j < FILE_OBJECT_FLAG_NUM; j++)
00228 {
00229 fileobj.Flag[j] = EndConvLong(fileobj.Flag[j]);
00230 }
00231 fileobj.Pos.v[0] = EndConvReal(fileobj.Pos.v[0]);
00232 fileobj.Pos.v[1] = EndConvReal(fileobj.Pos.v[1]);
00233 fileobj.Pos.v[2] = EndConvReal(fileobj.Pos.v[2]);
00234 fileobj.Up.v[0] = EndConvReal(fileobj.Up.v[0]);
00235 fileobj.Up.v[1] = EndConvReal(fileobj.Up.v[1]);
00236 fileobj.Up.v[2] = EndConvReal(fileobj.Up.v[2]);
00237 fileobj.Look.v[0] = EndConvReal(fileobj.Look.v[0]);
00238 fileobj.Look.v[1] = EndConvReal(fileobj.Look.v[1]);
00239 fileobj.Look.v[2] = EndConvReal(fileobj.Look.v[2]);
00240
00241
00242 CopyVec(&fileobj.Up, &mat.mv[U]);
00243 CopyVec(&fileobj.Look, &mat.mv[L]);
00244 CrossProduct(&mat.mv[U], &mat.mv[L], &mat.mv[R]);
00245
00246 CreateObject(&fileobj.Pos, &mat, fileobj.ID, fileobj.Flag);
00247 }
00248
00249
00250 FFS_Close(fp);
00251 }
00252 #endif
00253
00254
00256
00258
00259 OBJECT *CreateObject(VEC *pos, MAT *mat, long ID, long *flags)
00260 {
00261 OBJECT *obj;
00262
00263
00264
00265 #ifdef _N64
00266 if (ID > OBJECT_TYPE_WATER) return NULL;
00267 #else
00268 if (ID >= OBJECT_TYPE_MAX)
00269 return NULL;
00270 #endif
00271
00272
00273 obj = OBJ_AllocObject();
00274 if (!obj) return NULL;
00275
00276
00277
00278 obj->flag.Draw = TRUE;
00279 obj->flag.Move = TRUE;
00280
00281 obj->renderflag.envmap = TRUE;
00282 obj->renderflag.envonly = FALSE;
00283 obj->renderflag.light = TRUE;
00284 obj->renderflag.litsimple = FALSE;
00285 obj->renderflag.reflect = TRUE;
00286 obj->renderflag.fog = TRUE;
00287 obj->renderflag.glare = FALSE;
00288 obj->renderflag.meshfx = TRUE;
00289
00290 obj->objref = NULL;
00291 obj->priority = 0;
00292 obj->Type = ID;
00293 obj->EnvRGB = 0x808080;
00294 obj->DefaultModel = -1;
00295 obj->CollType = COLL_TYPE_NONE;
00296 obj->Light = NULL;
00297 obj->Field = NULL;
00298 #ifdef _PC
00299 obj->Sfx3D = NULL;
00300 #endif
00301
00302 obj->aihandler = NULL;
00303 obj->collhandler = NULL;
00304 obj->movehandler = NULL;
00305 obj->renderhandler = (RENDER_HANDLER)RenderObject;
00306 obj->freehandler = NULL;
00307
00308
00309
00310 InitBodyDefault(&obj->body);
00311
00312
00313
00314 SetBodyPos(&obj->body, pos, mat);
00315
00316
00317
00318 obj->Data = NULL;
00319 if (ObjInitData[ID].AllocSize)
00320 {
00321 obj->Data = malloc(ObjInitData[ID].AllocSize);
00322 if (!obj->Data)
00323 {
00324 OBJ_FreeObject(obj);
00325 return NULL;
00326 }
00327 }
00328
00329
00330
00331 if (ObjInitData[ID].InitFunc)
00332 {
00333 if (!ObjInitData[ID].InitFunc(obj, flags))
00334 {
00335 OBJ_FreeObject(obj);
00336 return NULL;
00337 }
00338 }
00339
00340
00341
00342 return obj;
00343 }
00344
00345
00347
00349
00350 static long InitBarrel(OBJECT *obj, long *flags)
00351 {
00352 BARREL_OBJ *barrel = (BARREL_OBJ*)obj->Data;
00353
00354
00355
00356 obj->renderflag.envmap = FALSE;
00357 obj->renderflag.reflect = FALSE;
00358
00359
00360
00361 barrel->SpinSpeed = (REAL)flags[0] / 32768.0f;
00362
00363
00364
00365 obj->aihandler = (AI_HANDLER)AI_BarrelHandler;
00366
00367
00368
00369 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_BARREL, TRUE, obj->renderflag, 0);
00370
00371
00372
00373 return TRUE;
00374 }
00375
00376
00377 #ifdef _PC
00379 // init football //
00381
00382 static long InitFootball(OBJECT *obj, long *flags)
00383 {
00384
00385
00386 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_FOOTBALL, TRUE, obj->renderflag, 0);
00387
00388
00389 obj->CollType = COLL_TYPE_BODY;
00390 obj->collhandler = (COLL_HANDLER)COL_BodyCollHandler;
00391
00392
00393 obj->movehandler = (MOVE_HANDLER)MOV_MoveBody;
00394
00395
00396 obj->body.Centre.Mass = Real(0.2f);
00397 obj->body.Centre.InvMass = ONE / Real(0.2f);
00398 SetMat(&obj->body.BodyInertia, Real(100), ZERO, ZERO, ZERO, Real(100), ZERO, ZERO, ZERO, Real(100));
00399 SetMat(&obj->body.BodyInvInertia, ONE / Real(100), ZERO, ZERO, ZERO, ONE / Real(100), ZERO, ZERO, ZERO, ONE / Real(100));
00400
00401 obj->body.Centre.Hardness = Real(0.6);
00402 obj->body.Centre.Resistance = Real(0.001);
00403 obj->body.DefaultAngRes = Real(0.005);
00404 obj->body.AngResistance = Real(0.005);
00405 obj->body.AngResMod = Real(1.0);
00406 obj->body.Centre.Grip = Real(0.005);
00407 obj->body.Centre.StaticFriction = Real(1.3);
00408 obj->body.Centre.KineticFriction = Real(0.8);
00409
00410
00411 SetBodySphere(&obj->body);
00412 obj->body.CollSkin.Sphere = (SPHERE *)malloc(sizeof(SPHERE));
00413 SetVecZero(&obj->body.CollSkin.Sphere[0].Pos);
00414 obj->body.CollSkin.Sphere[0].Radius = Real(30);
00415 obj->body.CollSkin.NSpheres = 1;
00416 CreateCopyCollSkin(&obj->body.CollSkin);
00417 MakeTightLocalBBox(&obj->body.CollSkin);
00418 BuildWorldSkin(&obj->body.CollSkin, &obj->body.Centre.Pos, &obj->body.Centre.WMatrix);
00419
00420 return TRUE;
00421 }
00422 #endif
00423
00425
00427
00428 static long InitBeachball(OBJECT *obj, long *flags)
00429 {
00430
00431
00432 obj->EnvRGB = 0x202000;
00433
00434
00435 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_BEACHBALL, TRUE, obj->renderflag, 0);
00436
00437
00438 obj->CollType = COLL_TYPE_BODY;
00439 obj->collhandler = (COLL_HANDLER)COL_BodyCollHandler;
00440
00441
00442 obj->movehandler = (MOVE_HANDLER)MOV_MoveBody;
00443
00444
00445 obj->body.Centre.Mass = Real(0.1f);
00446 obj->body.Centre.InvMass = ONE / Real(0.1f);
00447 SetMat(&obj->body.BodyInertia, Real(100), ZERO, ZERO, ZERO, Real(100), ZERO, ZERO, ZERO, Real(100));
00448 SetMat(&obj->body.BodyInvInertia, ONE / Real(100), ZERO, ZERO, ZERO, ONE / Real(100), ZERO, ZERO, ZERO, ONE / Real(100));
00449
00450 obj->body.Centre.Hardness = Real(0.6);
00451 obj->body.Centre.Resistance = Real(0.005);
00452 obj->body.DefaultAngRes = Real(0.005);
00453 obj->body.AngResistance = Real(0.005);
00454 obj->body.AngResMod = Real(1.0);
00455 obj->body.Centre.Grip = Real(0.005);
00456 obj->body.Centre.StaticFriction = Real(1.0);
00457 obj->body.Centre.KineticFriction = Real(0.5);
00458 obj->body.Centre.Boost = ZERO;
00459
00460
00461 SetBodySphere(&obj->body);
00462 obj->body.CollSkin.Sphere = (SPHERE *)malloc(sizeof(SPHERE));
00463 SetVecZero(&obj->body.CollSkin.Sphere[0].Pos);
00464 obj->body.CollSkin.Sphere[0].Radius = Real(100);
00465 obj->body.CollSkin.NSpheres = 1;
00466 CreateCopyCollSkin(&obj->body.CollSkin);
00467 MakeTightLocalBBox(&obj->body.CollSkin);
00468 BuildWorldSkin(&obj->body.CollSkin, &obj->body.Centre.Pos, &obj->body.Centre.WMatrix);
00469
00470 return TRUE;
00471 }
00472
00473
00475
00477
00478 static long InitPlanet(OBJECT *obj, long *flags)
00479 {
00480 long i;
00481 VEC vec;
00482 MAT mat;
00483 PLANET_OBJ *planet;
00484 SUN_OBJ *sun;
00485 BOUNDING_BOX box;
00486
00487
00488
00489 if (flags[0] != PLANET_SUN)
00490 obj->Data = malloc(sizeof(PLANET_OBJ));
00491 else
00492 obj->Data = malloc(sizeof(SUN_OBJ));
00493
00494 if (!obj->Data)
00495 return FALSE;
00496
00497 planet = (PLANET_OBJ*)obj->Data;
00498 sun = (SUN_OBJ*)obj->Data;
00499
00500
00501
00502 obj->renderflag.envmap = FALSE;
00503 obj->renderflag.reflect = FALSE;
00504
00505
00506
00507 planet->OwnPlanet = flags[0];
00508 planet->OrbitPlanet = flags[1];
00509
00510
00511
00512 planet->OrbitSpeed = (REAL)abs(flags[2]) / 32768.0f;
00513
00514
00515
00516 planet->SpinSpeed = (REAL)flags[3] / 4096.0f;
00517
00518
00519
00520 obj->aihandler = (AI_HANDLER)AI_PlanetHandler;
00521
00522
00523
00524 if (planet->OwnPlanet != PLANET_SUN)
00525 {
00526 obj->renderhandler = (RENDER_HANDLER)RenderPlanet;
00527 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_MERCURY + planet->OwnPlanet, TRUE, obj->renderflag, 0);
00528 }
00529
00530
00531
00532 else
00533 {
00534 obj->renderhandler = (RENDER_HANDLER)RenderSun;
00535 obj->Light = AllocLight();
00536 if (obj->Light)
00537 {
00538 obj->Light->x = obj->body.Centre.Pos.v[X];
00539 obj->Light->y = obj->body.Centre.Pos.v[Y];
00540 obj->Light->z = obj->body.Centre.Pos.v[Z];
00541 obj->Light->Reach = 12000;
00542 obj->Light->Flag = LIGHT_MOVING;
00543 obj->Light->Type= LIGHT_OMNINORMAL;
00544 obj->Light->r = 256;
00545 obj->Light->g = 256;
00546 obj->Light->b = 256;
00547 }
00548
00549 #ifdef _PC
00550 SunFacingPoly.Xsize = 1750;
00551 SunFacingPoly.Ysize = 1750;
00552 SunFacingPoly.U = 0.0f;
00553 SunFacingPoly.V = 0.0f;
00554 SunFacingPoly.Usize = 1.0f;
00555 SunFacingPoly.Vsize = 1.0f;
00556 SunFacingPoly.Tpage = TPAGE_MISC1;
00557 SunFacingPoly.RGB = 0xffffff;
00558
00559 LoadTextureClever("levels\\muse2\\sun.bmp", TPAGE_MISC1, 256, 256, 0, FxTextureSet, FALSE);
00560 #endif
00561 for (i = 0 ; i < SUN_OVERLAY_NUM ; i++)
00562 {
00563 sun->Overlay[i].Rot = frand(1.0f);
00564 sun->Overlay[i].RotVel = frand(0.001f) - 0.0005f;
00565 }
00566
00567 for (i = 0 ; i < SUN_STAR_NUM ; i++)
00568 {
00569 SetVector(&vec, 0, 0, 6144);
00570 RotMatrixZYX(&mat, frand(0.5f) - 0.25f, frand(1.0f), 0);
00571 RotVector(&mat, &vec, &sun->Star[i].Pos);
00572 sun->Star[i].rgb = ((rand() & 127) + 128) | ((rand() & 127) + 128) << 8 | ((rand() & 127) + 128) << 16;
00573 }
00574
00575 box.Xmin = obj->body.Centre.Pos.v[X] - 3072;
00576 box.Xmax = obj->body.Centre.Pos.v[X] + 3072;
00577 box.Ymin = obj->body.Centre.Pos.v[Y] - 3072;
00578 box.Ymax = obj->body.Centre.Pos.v[Y] + 3072;
00579 box.Zmin = obj->body.Centre.Pos.v[Z] - 3072;
00580 box.Zmax = obj->body.Centre.Pos.v[Z] + 3072;
00581
00582 sun->VisiMask = SetObjectVisiMask(&box);
00583 }
00584
00585
00586
00587 return TRUE;
00588 }
00589
00590
00592
00594
00595 static long InitPlane(OBJECT *obj, long *flags)
00596 {
00597 MAT mat, mat2;
00598 PLANE_OBJ *plane = (PLANE_OBJ*)obj->Data;
00599
00600
00601
00602 obj->renderflag.reflect = FALSE;
00603
00604
00605
00606 CopyVec(&obj->body.Centre.Pos, &plane->GenPos);
00607
00608
00609
00610 plane->Speed = (REAL)flags[0] / 16384.0f;
00611 plane->Rot = 0;
00612
00613
00614
00615 SetVector(&plane->Offset, 0, 0, (REAL)flags[1]);
00616
00617
00618
00619 if (plane->Speed > 0)
00620 RotMatrixY(&mat2, 0.25f);
00621 else
00622 RotMatrixY(&mat2, 0.75f);
00623
00624 RotMatrixZ(&mat, (REAL)flags[2] / 512.0f);
00625 MulMatrix(&mat2, &mat, &plane->BankMatrix);
00626
00627
00628
00629 obj->aihandler = (AI_HANDLER)AI_PlaneHandler;
00630
00631
00632
00633 obj->renderhandler = (RENDER_HANDLER)RenderPlane;
00634
00635
00636
00637 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_PLANE, TRUE, obj->renderflag, 0);
00638
00639
00640
00641 plane->PropModel = LoadOneLevelModel(LEVEL_MODEL_PLANE_PROPELLOR, TRUE, obj->renderflag, 0);
00642
00643
00644 #ifdef _PC
00645 obj->Sfx3D = CreateSfx3D(SFX_TOY_PLANE, SFX_MAX_VOL, flags[0] * 100 + 11025, TRUE, &obj->body.Centre.Pos);
00646 #endif
00647
00648
00649 return TRUE;
00650 }
00651
00653
00655
00656 static long InitCopter(OBJECT *obj, long *flags)
00657 {
00658 BBOX bBox = {-200, 200, -1000, 1000, -200, 200};
00659 VEC size = {200, 2000, 200};
00660
00661 COPTER_OBJ *copter = (COPTER_OBJ*)obj->Data;
00662
00663
00664
00665 obj->renderflag.reflect = FALSE;
00666
00667
00668
00669 obj->aihandler = (AI_HANDLER)AI_CopterHandler;
00670
00671
00672
00673 obj->renderhandler = (RENDER_HANDLER)RenderCopter;
00674
00675
00676
00677 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_COPTER, TRUE, obj->renderflag, 0);
00678
00679
00680
00681 copter->BladeModel1 = LoadOneLevelModel(LEVEL_MODEL_COPTER_BLADE1, TRUE, obj->renderflag, 0);
00682 copter->BladeModel2 = LoadOneLevelModel(LEVEL_MODEL_COPTER_BLADE2, TRUE, obj->renderflag, 0);
00683
00684
00685 #ifdef _PC
00686 obj->Sfx3D = CreateSfx3D(SFX_TOY_COPTER, SFX_MAX_VOL, 22050, TRUE, &obj->body.Centre.Pos);
00687 #endif
00688
00689
00690
00691 copter->FlyBox.XMin = obj->body.Centre.Pos.v[X] - (float)flags[0] * 10;
00692 copter->FlyBox.XMax = obj->body.Centre.Pos.v[X] + (float)flags[0] * 10;
00693 copter->FlyBox.YMin = obj->body.Centre.Pos.v[Y] - (float)flags[1] * 10 - (float)flags[3] * 50;
00694 copter->FlyBox.YMax = obj->body.Centre.Pos.v[Y] + (float)flags[1] * 10 - (float)flags[3] * 50;
00695 copter->FlyBox.ZMin = obj->body.Centre.Pos.v[Z] - (float)flags[2] * 10;
00696 copter->FlyBox.ZMax = obj->body.Centre.Pos.v[Z] + (float)flags[2] * 10;
00697
00698
00699 obj->CollType = COLL_TYPE_NONE;
00700 obj->collhandler = NULL;
00701
00702
00703 copter->State = COPTER_WAIT;
00704 copter->TurnTime = ZERO;
00705 copter->Acc = 100;
00706 copter->MaxVel = 300;
00707
00708 obj->movehandler = NULL;
00709
00710
00711 obj->body.Centre.Mass = ZERO;
00712 obj->body.Centre.InvMass = ZERO;
00713 SetMat(&obj->body.BodyInertia, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO);
00714 SetMat(&obj->body.BodyInvInertia, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO);
00715
00716 obj->body.Centre.Hardness = Real(0.5);
00717 obj->body.Centre.Resistance = Real(0.0);
00718 obj->body.DefaultAngRes = Real(0.0);
00719 obj->body.AngResistance = Real(0.0);
00720 obj->body.AngResMod = Real(0.0);
00721 obj->body.Centre.Grip = Real(0.01);
00722 obj->body.Centre.StaticFriction = Real(1.0);
00723 obj->body.Centre.KineticFriction = Real(0.5);
00724
00725
00726 MatToQuat(&obj->body.Centre.WMatrix, &copter->InitialQuat);
00727 CopyQuat(&copter->InitialQuat, &copter->CurrentUpQuat);
00728
00729
00730
00731
00732
00733
00734
00735
00736 obj->Field = AddLocalField(
00737 obj->ObjID,
00738 FIELD_PRIORITY_MAX,
00739 &obj->body.Centre.Pos,
00740 &obj->body.Centre.WMatrix,
00741 &bBox,
00742 &size,
00743 &obj->body.Centre.WMatrix.mv[U],
00744 500,
00745 ZERO);
00746
00747
00748
00749 return TRUE;
00750 }
00751
00752 #ifdef _PC
00754 // init dragon //
00756
00757 static long InitDragon(OBJECT *obj, long *flags)
00758 {
00759 long i;
00760 DRAGON_OBJ *dragon = (DRAGON_OBJ*)obj->Data;
00761
00762
00763
00764 obj->renderflag.reflect = FALSE;
00765
00766
00767
00768 obj->aihandler = (AI_HANDLER)AI_DragonHandler;
00769
00770
00771
00772 obj->renderhandler = (RENDER_HANDLER)RenderDragon;
00773
00774
00775
00776 dragon->BodyModel = LoadOneLevelModel(LEVEL_MODEL_DRAGON1, TRUE, obj->renderflag, 0);
00777
00778
00779
00780 dragon->HeadModel = LoadOneLevelModel(LEVEL_MODEL_DRAGON2, TRUE, obj->renderflag, 0);
00781 if (dragon->HeadModel != -1)
00782 {
00783 SetModelFrames(&LevelModel[dragon->HeadModel].Model, DragonMorphFrames, 2);
00784 }
00785
00786
00787
00788 dragon->Count = 0;
00789
00790
00791
00792 for (i = 0 ; i < DRAGON_FIRE_NUM ; i++)
00793 {
00794 dragon->Fire[i].Time = 0;
00795 }
00796
00797
00798
00799 RotTransVector(&obj->body.Centre.WMatrix, &obj->body.Centre.Pos, &DragonFireOffset, &dragon->FireGenPoint);
00800 RotVector(&obj->body.Centre.WMatrix, &DragonFireDir, &dragon->FireGenDir);
00801
00802
00803
00804 DragonFireFacingPoly.U = 64.0f / 256.0f;
00805 DragonFireFacingPoly.V = 0.0f;
00806 DragonFireFacingPoly.Usize = 64.0f / 256.0f;
00807 DragonFireFacingPoly.Vsize = 64.0f / 256.0f;
00808 DragonFireFacingPoly.Tpage = TPAGE_FX1;
00809
00810
00811
00812 dragon->FireGenTime = CurrentTimer();
00813
00814
00815
00816 return TRUE;
00817 }
00818 #endif
00819
00821
00823
00824 static long InitWater(OBJECT *obj, long *flags)
00825 {
00826 long i;
00827 WATER_OBJ *water;
00828 MODEL *model;
00829
00830
00831
00832 obj->renderflag.reflect = FALSE;
00833 obj->renderflag.envmap = FALSE;
00834 #ifdef _N64
00835 obj->renderflag.envonly = TRUE;
00836 obj->renderflag.litsimple = FALSE;
00837 obj->renderhandler = (RENDER_HANDLER)RenderWater;
00838 #endif
00839
00840
00841
00842 obj->aihandler = (AI_HANDLER)AI_WaterHandler;
00843
00844
00845
00846 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_WATER, TRUE, obj->renderflag, 0);
00847 if (obj->DefaultModel == -1) return FALSE;
00848 model = &LevelModel[obj->DefaultModel].Model;
00849
00850
00851
00852 #ifdef _PC
00853 obj->Data = (WATER_OBJ*)malloc(sizeof(WATER_OBJ) + sizeof(WATER_VERTEX) * (model->VertNum - 1));
00854 #endif
00855 #ifdef _N64
00856 obj->Data = (WATER_OBJ*)malloc(sizeof(WATER_OBJ) + sizeof(WATER_VERTEX) * (model->hdr->vtxnum - 1));
00857 #endif
00858 if (!obj->Data) return FALSE;
00859
00860
00861
00862 #ifdef _PC
00863 LoadTextureClever("levels\\toylite\\water.bmp", TPAGE_MISC1, 256, 256, 0, FxTextureSet, TRUE);
00864 #endif
00865
00866
00867
00868 water = (WATER_OBJ*)obj->Data;
00869
00870 water->Scale = 5;
00871
00872 #ifdef _PC
00873 water->VertNum = model->VertNum;
00874 #endif
00875 #ifdef _N64
00876 water->VertNum = model->hdr->vtxnum;
00877 #endif
00878
00879 for (i = 0 ; i < water->VertNum ; i++)
00880 {
00881 #ifdef _PC
00882 water->Vert[i].Height = model->VertPtr[i].y;
00883 #endif
00884 #ifdef _N64
00885 water->Vert[i].Height = model->hdr->evtxptr[i].v.ob[1];
00886 #endif
00887 water->Vert[i].Time = 0;
00888 water->Vert[i].TotalTime = frand(2.0f) + 1.0f;
00889 }
00890
00891
00892 #ifdef _PC
00893 model->QuadNumTex = 0;
00894 model->TriNumTex = model->PolyNum;
00895 model->QuadNumRGB = 0;
00896 model->TriNumRGB = 0;
00897
00898 for (i = 0 ; i < model->PolyNum ; i++)
00899 {
00900 model->PolyPtr[i].Type = POLY_SEMITRANS;
00901 model->PolyPtr[i].Tpage = TPAGE_MISC1;
00902
00903 *(long*)&model->PolyRGB[i].rgb[0] = 0xc0808080;
00904 *(long*)&model->PolyRGB[i].rgb[1] = 0xc0808080;
00905 *(long*)&model->PolyRGB[i].rgb[2] = 0xc0808080;
00906 }
00907 #endif
00908
00909
00910 return TRUE;
00911 }
00912
00913 #ifdef _PC
00915 //
00916
00917
00919
00920 static long InitTrolley(OBJECT *obj, long *flags)
00921 {
00922
00923 obj->player = (PLAYER *)obj->Data;
00924
00925
00926 obj->player->car.Body = &obj->body;
00927 obj->player->type = PLAYER_CPU;
00928 obj->player->ctrltype = CTRL_TYPE_NONE;
00929 obj->player->ownobj = obj;
00930 obj->player->Slot = 0;
00931
00932 obj->player->conhandler = NULL;
00933 obj->CollType = COLL_TYPE_CAR;
00934 obj->movehandler = (MOVE_HANDLER)MOV_MoveCarNew;
00935 obj->collhandler = (COLL_HANDLER)COL_CarCollHandler;
00936 obj->aihandler = NULL;
00937
00938 obj->flag.Draw = TRUE;
00939 obj->flag.Move = TRUE;
00940 obj->renderhandler = (RENDER_HANDLER)RenderTrolley;
00941 obj->freehandler = (FREE_HANDLER)FreeTrolley;
00942 obj->Type = OBJECT_TYPE_TROLLEY;
00943 obj->Field = NULL;
00944
00945 InitCar(&obj->player->car);
00946 SetupCar(obj->player, 28);
00947 SetCarPos(&obj->player->car, &obj->body.Centre.Pos, &obj->body.Centre.WMatrix);
00948
00949 return TRUE;
00950 }
00951
00952 static void FreeTrolley(OBJECT *obj)
00953 {
00954 FreeCar(obj->player);
00955 }
00956
00958
00960
00961 static long InitBoat(OBJECT *obj, long *flags)
00962 {
00963 BOAT_OBJ *boat = (BOAT_OBJ*)obj->Data;
00964
00965
00966
00967 obj->renderflag.reflect = FALSE;
00968 obj->EnvRGB = 0x404080;
00969
00970
00971
00972 obj->aihandler = (AI_HANDLER)AI_BoatHandler;
00973
00974
00975
00976 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_BOAT1 + flags[0], TRUE, obj->renderflag, 0);
00977 if (obj->DefaultModel == -1) return FALSE;
00978
00979
00980
00981 boat->Height = obj->body.Centre.Pos.v[Y];
00982
00983 CopyMat(&obj->body.Centre.WMatrix, &boat->Ori);
00984
00985 boat->TimeX = boat->TimeHeight = boat->TimeZ = 0;
00986
00987 boat->TotalTimeX = frand(2.0f) + 4.0f;
00988 boat->TotalTimeHeight = frand(1.0f) + 2.0f;
00989 boat->TotalTimeZ = frand(2.0f) + 4.0f;
00990 boat->SteamTime = ZERO;
00991
00992
00993
00994 return TRUE;
00995 }
00996
00998
01000
01001 static long InitRadar(OBJECT *obj, long *flags)
01002 {
01003 RADAR_OBJ *radar = (RADAR_OBJ*)obj->Data;
01004
01005
01006
01007 obj->renderflag.reflect = FALSE;
01008
01009
01010
01011 obj->aihandler = (AI_HANDLER)AI_RadarHandler;
01012
01013
01014
01015 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_RADAR, TRUE, obj->renderflag, 0);
01016 if (obj->DefaultModel == -1) return FALSE;
01017
01018
01019
01020 radar->Time = 0;
01021
01022 radar->Light1 = AllocLight();
01023 if (radar->Light1)
01024 {
01025 radar->Light1->x = obj->body.Centre.Pos.v[X];
01026 radar->Light1->y = obj->body.Centre.Pos.v[Y];
01027 radar->Light1->z = obj->body.Centre.Pos.v[Z];
01028 radar->Light1->Reach = 2500;
01029 radar->Light1->Flag = LIGHT_FIXED | LIGHT_MOVING;
01030 radar->Light1->Type= LIGHT_SPOTNORMAL;
01031 radar->Light1->Cone = 60.0f;
01032 radar->Light1->r = 0;
01033 radar->Light1->g = 0;
01034 radar->Light1->b = 512;
01035 }
01036
01037 radar->Light2 = AllocLight();
01038 if (radar->Light2)
01039 {
01040 radar->Light2->x = obj->body.Centre.Pos.v[X];
01041 radar->Light2->y = obj->body.Centre.Pos.v[Y];
01042 radar->Light2->z = obj->body.Centre.Pos.v[Z];
01043 radar->Light2->Reach = 2500;
01044 radar->Light2->Flag = LIGHT_FIXED | LIGHT_MOVING;
01045 radar->Light2->Type= LIGHT_SPOTNORMAL;
01046 radar->Light2->Cone = 60.0f;
01047 radar->Light2->r = 512;
01048 radar->Light2->g = 0;
01049 radar->Light2->b = 0;
01050 }
01051
01052
01053
01054 return TRUE;
01055 }
01056
01058
01060
01061 static long InitSpeedup(OBJECT *object, long *flags)
01062 {
01063 VEC pos;
01064
01065 MAT *objMat = &object->body.Centre.WMatrix;
01066 SPEEDUP_OBJ *speedup = (SPEEDUP_OBJ *)object->Data;
01067 NEWCOLLPOLY *collPoly = &speedup->CollPoly;
01068
01069
01070 object->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_SPEEDUP, TRUE, object->renderflag, TPAGE_FX1);
01071 if (object->DefaultModel == -1) return FALSE;
01072
01073
01074 object->aihandler = (AI_HANDLER)AI_SpeedupAIHandler;
01075 object->renderhandler = (RENDER_HANDLER)RenderSpeedup;
01076 object->CollType = COLL_TYPE_NONE;
01077
01078
01079
01080
01081 speedup->Width = 5.0f * (REAL)flags[0];
01082 speedup->LoSpeed = MPH2OGU_SPEED * (REAL)flags[1];
01083 speedup->HiSpeed = MPH2OGU_SPEED * (REAL)flags[2];
01084 speedup->Speed = speedup->LoSpeed;
01085 speedup->ChangeTime = (REAL)flags[3];
01086 speedup->Time = ZERO;
01087 speedup->Height = 120.0f;
01088 SetBBox(&collPoly->BBox, LARGEDIST, -LARGEDIST, LARGEDIST, -LARGEDIST, LARGEDIST, -LARGEDIST);
01089
01090
01091 VecPlusScalarVec(&object->body.Centre.Pos, -speedup->Width, &objMat->mv[R], &speedup->PostPos[0]);
01092 VecPlusScalarVec(&object->body.Centre.Pos, speedup->Width, &objMat->mv[R], &speedup->PostPos[1]);
01093
01094
01095 collPoly->Plane.v[A] = objMat->m[LX];
01096 collPoly->Plane.v[B] = objMat->m[LY];
01097 collPoly->Plane.v[C] = objMat->m[LZ];
01098 collPoly->Plane.v[D] = -VecDotVec(&objMat->mv[L], &object->body.Centre.Pos);
01099
01100 VecPlusScalarVec(&object->body.Centre.Pos, -speedup->Width, &objMat->mv[R], &pos);
01101 collPoly->EdgePlane[0].v[A] = -objMat->m[RX];
01102 collPoly->EdgePlane[0].v[B] = -objMat->m[RY];
01103 collPoly->EdgePlane[0].v[C] = -objMat->m[RZ];
01104 collPoly->EdgePlane[0].v[D] = VecDotVec(&objMat->mv[R], &pos);
01105 AddPointToBBox(&collPoly->BBox, &pos);
01106
01107 VecPlusScalarVec(&object->body.Centre.Pos, -speedup->Height, &objMat->mv[U], &pos);
01108 collPoly->EdgePlane[1].v[A] = -objMat->m[UX];
01109 collPoly->EdgePlane[1].v[B] = -objMat->m[UY];
01110 collPoly->EdgePlane[1].v[C] = -objMat->m[UZ];
01111 collPoly->EdgePlane[1].v[D] = VecDotVec(&objMat->mv[U], &pos);
01112 AddPointToBBox(&collPoly->BBox, &pos);
01113
01114 VecPlusScalarVec(&object->body.Centre.Pos, speedup->Width, &objMat->mv[R], &pos);
01115 collPoly->EdgePlane[2].v[A] = objMat->m[RX];
01116 collPoly->EdgePlane[2].v[B] = objMat->m[RY];
01117 collPoly->EdgePlane[2].v[C] = objMat->m[RZ];
01118 collPoly->EdgePlane[2].v[D] = -VecDotVec(&objMat->mv[R], &pos);
01119 AddPointToBBox(&collPoly->BBox, &pos);
01120
01121 CopyVec(&object->body.Centre.Pos, &pos);
01122 collPoly->EdgePlane[3].v[A] = objMat->m[UX];
01123 collPoly->EdgePlane[3].v[B] = objMat->m[UY];
01124 collPoly->EdgePlane[3].v[C] = objMat->m[UZ];
01125 collPoly->EdgePlane[3].v[D] = -VecDotVec(&objMat->mv[U], &pos);
01126 AddPointToBBox(&collPoly->BBox, &pos);
01127
01128 collPoly->Type = POLY_QUAD;
01129 collPoly->Material = MATERIAL_DEFAULT;
01130
01131 return TRUE;
01132 }
01133
01134
01136
01138
01139 static long InitBalloon(OBJECT *obj, long *flags)
01140 {
01141 BALLOON_OBJ *balloon = (BALLOON_OBJ*)obj->Data;
01142
01143
01144
01145 obj->aihandler = (AI_HANDLER)AI_BalloonHandler;
01146
01147
01148
01149 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_BALLOON, TRUE, obj->renderflag, 0);
01150 if (obj->DefaultModel == -1) return FALSE;
01151
01152
01153
01154 balloon->Time = frand(1.0f);
01155 balloon->Height = obj->body.Centre.Pos.v[Y];
01156
01157
01158
01159 return TRUE;
01160 }
01161
01163
01165
01166 static long InitHorse(OBJECT *obj, long *flags)
01167 {
01168 HORSE_OBJ *horse = (HORSE_OBJ*)obj->Data;
01169
01170
01171
01172 obj->renderflag.reflect = FALSE;
01173
01174
01175
01176 obj->aihandler = (AI_HANDLER)AI_HorseRipper;
01177
01178
01179
01180 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_HORSE, TRUE, obj->renderflag, 0);
01181 if (obj->DefaultModel == -1) return FALSE;
01182
01183
01184
01185 horse->Time = frand(1.0f);
01186 horse->Mat = obj->body.Centre.WMatrix;
01187 horse->CreakFlag = 0.5f;
01188
01189
01190
01191 return TRUE;
01192 }
01193
01195
01197
01198 static long InitTrain(OBJECT *obj, long *flags)
01199 {
01200 TRAIN_OBJ *train = (TRAIN_OBJ*)obj->Data;
01201
01202
01203
01204 obj->aihandler = (AI_HANDLER)AI_TrainHandler;
01205 obj->movehandler = (MOVE_HANDLER)MOV_MoveTrain;
01206
01207
01208
01209 obj->renderhandler = (RENDER_HANDLER)RenderTrain;
01210
01211
01212
01213 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_TRAIN, TRUE, obj->renderflag, 0);
01214 if (obj->DefaultModel == -1) return FALSE;
01215
01216
01217
01218 train->BackWheel = LoadOneLevelModel(LEVEL_MODEL_TRAIN2, TRUE, obj->renderflag, 0);
01219 train->FrontWheel = LoadOneLevelModel(LEVEL_MODEL_TRAIN3, TRUE, obj->renderflag, 0);
01220
01221
01222
01223 obj->Sfx3D = CreateSfx3D(SFX_TOY_TRAIN, SFX_MAX_VOL, 22050, TRUE, &obj->body.Centre.Pos);
01224
01225
01226
01227 train->SteamTime = 0;
01228 train->WhistleFlag = TRUE;
01229
01230
01231
01232 obj->body.Centre.Mass = ZERO;
01233 obj->body.Centre.InvMass = ZERO;
01234 SetMat(&obj->body.BodyInertia, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO);
01235 SetMat(&obj->body.BodyInvInertia, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO);
01236
01237 SetVector(&obj->body.AngVel, 0, 0, 0);
01238 SetVector(&obj->body.Centre.Vel, 0, 0, -200.0f);
01239
01240 obj->CollType = COLL_TYPE_BODY;
01241 obj->body.CollSkin.CollType = BODY_COLL_POLY;
01242 obj->body.CollSkin.AllowWorldColls = FALSE;
01243 obj->body.CollSkin.AllowObjColls = TRUE;
01244
01245 obj->body.CollSkin.NConvex = LevelModel[obj->DefaultModel].CollSkin.NConvex;
01246 obj->body.CollSkin.NSpheres = LevelModel[obj->DefaultModel].CollSkin.NSpheres;
01247 obj->body.CollSkin.NCollPolys = LevelModel[obj->DefaultModel].CollSkin.NCollPolys;
01248 obj->body.CollSkin.Convex = LevelModel[obj->DefaultModel].CollSkin.Convex;
01249 obj->body.CollSkin.Sphere = LevelModel[obj->DefaultModel].CollSkin.Sphere;
01250 obj->body.CollSkin.CollPoly = LevelModel[obj->DefaultModel].CollSkin.CollPoly;
01251 CopyBBox(&LevelModel[obj->DefaultModel].CollSkin.TightBBox, &obj->body.CollSkin.TightBBox);
01252
01253 SetBBox(&obj->body.CollSkin.TightBBox, -2000, 2000, -2000, 2000, -2000, 2000);
01254
01255 CreateCopyCollSkin(&obj->body.CollSkin);
01256 BuildWorldSkin(&obj->body.CollSkin, &obj->body.Centre.Pos, &obj->body.Centre.WMatrix);
01257 TransCollPolys(obj->body.CollSkin.CollPoly, obj->body.CollSkin.NCollPolys, &obj->body.Centre.Pos);
01258
01259
01260
01261 return TRUE;
01262 }
01263
01265
01267
01268 static long InitStrobe(OBJECT *obj, long *flags)
01269 {
01270 STROBE_OBJ *strobe = (STROBE_OBJ*)obj->Data;
01271
01272
01273
01274 obj->renderflag.reflect = FALSE;
01275 obj->renderflag.envmap = FALSE;
01276
01277
01278
01279 obj->aihandler = (AI_HANDLER)AI_StrobeHandler;
01280 obj->renderhandler = (RENDER_HANDLER)RenderStrobe;
01281
01282
01283
01284 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_LIGHT1 + flags[0], TRUE, obj->renderflag, 0);
01285 if (obj->DefaultModel == -1) return FALSE;
01286
01287
01288
01289 strobe->StrobeNum = flags[1];
01290 strobe->StrobeCount = flags[2];
01291
01292 strobe->FadeUp = StrobeTable[flags[0]].FadeUp;
01293 strobe->FadeDown = StrobeTable[flags[0]].FadeDown;
01294
01295 strobe->Range = StrobeTable[flags[0]].Range;
01296
01297 strobe->r = StrobeTable[flags[0]].rgb.r;
01298 strobe->g = StrobeTable[flags[0]].rgb.g;
01299 strobe->b = StrobeTable[flags[0]].rgb.b;
01300
01301
01302
01303 RotTransVector(&obj->body.Centre.WMatrix, &obj->body.Centre.Pos, &StrobeTable[flags[0]].GlowOffset, &strobe->LightPos);
01304
01305
01306
01307 return TRUE;
01308 }
01309
01310
01312
01313
01314
01316
01317 static long InitSparkGen(OBJECT *obj, long *flags)
01318 {
01319 SPARK_GEN *sparkGen = (SPARK_GEN *)obj->Data;
01320
01321 obj->aihandler = (AI_HANDLER)SparkGenHandler;
01322
01323 sparkGen->Type = (enum SparkTypeEnum)flags[0];
01324 sparkGen->Parent = NULL;
01325 VecEqScalarVec(&sparkGen->SparkVel, (REAL)(flags[1] * 10), &obj->body.Centre.WMatrix.mv[L]);
01326 sparkGen->SparkVelVar = REAL(flags[2] * 10);
01327 sparkGen->MaxTime = Real(5) / Real(flags[3]);
01328 AddPointToBBox(&obj->body.CollSkin.BBox, &obj->body.Centre.Pos);
01329 sparkGen->VisiMask = SetObjectVisiMask((BOUNDING_BOX *)&obj->body.CollSkin.BBox);
01330
01331 return TRUE;
01332 }
01333
01335
01337
01338 static long InitSpaceman(OBJECT *obj, long *flags)
01339 {
01340 SPACEMAN_OBJ *spaceman = (SPACEMAN_OBJ*)obj->Data;
01341
01342
01343
01344 obj->renderflag.reflect = FALSE;
01345
01346
01347
01348 obj->aihandler = (AI_HANDLER)AI_SpacemanHandler;
01349
01350
01351
01352 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_SPACEMAN, TRUE, obj->renderflag, 0);
01353 if (obj->DefaultModel == -1) return FALSE;
01354
01355
01356
01357 return TRUE;
01358 }
01359
01361
01363
01364 static long InitPickup(OBJECT *obj, long *flags)
01365 {
01366 PICKUP_OBJ *pickup = (PICKUP_OBJ*)obj->Data;
01367
01368
01369
01370 obj->renderflag.light = FALSE;
01371 obj->renderflag.glare = TRUE;
01372
01373
01374
01375 obj->aihandler = (AI_HANDLER)AI_PickupHandler;
01376 obj->renderhandler = (RENDER_HANDLER)RenderPickup;
01377
01378
01379
01380 obj->DefaultModel = LoadOneLevelModel(LEVEL_MODEL_PICKUP, FALSE, obj->renderflag, 0);
01381 if (obj->DefaultModel == -1) return FALSE;
01382
01383
01384
01385 pickup->Mode = 0;
01386 pickup->Timer = 1;
01387
01388 CopyVec(&obj->body.Centre.Pos, &pickup->Pos);
01389
01390
01391
01392 SetBodySphere(&obj->body);
01393 obj->body.CollSkin.Sphere = (SPHERE *)malloc(sizeof(SPHERE));
01394 SetVecZero(&obj->body.CollSkin.Sphere[0].Pos);
01395 obj->body.CollSkin.Sphere[0].Radius = LevelModel[obj->DefaultModel].Model.Radius;
01396 obj->body.CollSkin.NSpheres = 1;
01397 CreateCopyCollSkin(&obj->body.CollSkin);
01398 MakeTightLocalBBox(&obj->body.CollSkin);
01399 BuildWorldSkin(&obj->body.CollSkin, &obj->body.Centre.Pos, &obj->body.Centre.WMatrix);
01400
01401 SetVector(&obj->body.AngVel, 0, 0, 0);
01402 SetVector(&obj->body.Centre.Vel, 0, 0, 0);
01403
01404
01405
01406 return TRUE;
01407 }
01408
01410
01412
01413 static long InitDissolveModel(OBJECT *obj, long *flags)
01414 {
01415 long i, j, k, l, polynum, vertnum, mem, vcount, ltime, lrgb[4];
01416 MODEL *model = (MODEL*)flags[0];
01417 DISSOLVE_OBJ *dissolve;
01418 DISSOLVE_PARTICLE *particle;
01419 MODEL_POLY *mpsource, *mpdest;
01420 POLY_RGB *mrgbsource, *mrgbdest;
01421 MODEL_RGB crgb, rgb[4];
01422 MODEL_VERTEX **mvsource, *mvdest, cvert, vert[4];
01423 REAL *uvsource, time, cuv[2], uv[8];
01424 VEC centre;
01425
01426
01427
01428 polynum = (model->QuadNumTex + model->QuadNumRGB) * 4 + (model->TriNumTex + model->TriNumRGB) * 3;
01429 vertnum = (model->QuadNumTex + model->QuadNumRGB) * 16 + (model->TriNumTex + model->TriNumRGB) * 12;
01430
01431 mem = sizeof(DISSOLVE_OBJ);
01432 mem += sizeof(MODEL_POLY) * polynum;
01433 mem += sizeof(POLY_RGB) * polynum;
01434 mem += sizeof(MODEL_VERTEX) * vertnum;
01435
01436 mem += sizeof(DISSOLVE_PARTICLE) * polynum;
01437
01438 obj->Data = malloc(mem);
01439 if (!obj->Data) return FALSE;
01440 dissolve = (DISSOLVE_OBJ*)obj->Data;
01441
01442
01443
01444 memcpy(&dissolve->Model, model, sizeof(MODEL));
01445
01446 dissolve->Model.PolyNum = (short)polynum;
01447 dissolve->Model.VertNum = (short)vertnum;
01448
01449 dissolve->Model.QuadNumTex = model->QuadNumTex * 4 + model->TriNumTex * 3;
01450 dissolve->Model.QuadNumRGB = model->QuadNumRGB * 4 + model->TriNumRGB * 3;
01451 dissolve->Model.TriNumTex = 0;
01452 dissolve->Model.TriNumRGB = 0;
01453
01454 dissolve->Model.PolyPtr = (MODEL_POLY*)(dissolve + 1);
01455 dissolve->Model.PolyRGB = (POLY_RGB*)(dissolve->Model.PolyPtr + dissolve->Model.PolyNum);
01456 dissolve->Model.VertPtr = (MODEL_VERTEX*)(dissolve->Model.PolyRGB + dissolve->Model.PolyNum);
01457
01458
01459
01460 mpdest = dissolve->Model.PolyPtr;
01461 mrgbdest = dissolve->Model.PolyRGB;
01462 mvdest = dissolve->Model.VertPtr;
01463
01464 for (l = 0 ; l < 2 ; l++)
01465 {
01466 mpsource = model->PolyPtr;
01467 mrgbsource = model->PolyRGB;
01468
01469 for (i = 0 ; i < model->PolyNum ; i++, mpsource++, mrgbsource++)
01470 {
01471 if ((l + (mpsource->Type & POLY_QUAD)) != 1) continue;
01472
01473 vcount = 3 + (mpsource->Type & POLY_QUAD);
01474 mvsource = &mpsource->v0;
01475 uvsource = &mpsource->tu0;
01476
01477
01478
01479 ZeroMemory(&cvert, sizeof(cvert));
01480 cuv[0] = cuv[1] = 0.0f;
01481 lrgb[0] = lrgb[1] = lrgb[2] = lrgb[3] = 0;
01482
01483 for (j = 0 ; j < vcount ; j++)
01484 {
01485 k = (j + 1) % vcount;
01486 time = frand(0.5f) + 0.25f;
01487 FTOL(time * 256.0f, ltime);
01488
01489
01490
01491 vert[j].x = mvsource[j]->x + (mvsource[k]->x - mvsource[j]->x) * time;
01492 vert[j].y = mvsource[j]->y + (mvsource[k]->y - mvsource[j]->y) * time;
01493 vert[j].z = mvsource[j]->z + (mvsource[k]->z - mvsource[j]->z) * time;
01494
01495 vert[j].nx = mvsource[j]->nx + (mvsource[k]->nx - mvsource[j]->nx) * time;
01496 vert[j].ny = mvsource[j]->ny + (mvsource[k]->ny - mvsource[j]->ny) * time;
01497 vert[j].nz = mvsource[j]->nz + (mvsource[k]->nz - mvsource[j]->nz) * time;
01498 NormalizeVector((VEC*)&vert[j].nx);
01499
01500 uv[j * 2] = uvsource[j * 2] + (uvsource[k * 2] - uvsource[j * 2]) * time;
01501 uv[j * 2 + 1] = uvsource[j * 2 + 1] + (uvsource[k * 2 + 1] - uvsource[j * 2] + 1) * time;
01502
01503 rgb[j].r = mrgbsource->rgb[j].r + (unsigned char)(((mrgbsource->rgb[k].r - mrgbsource->rgb[j].r) * ltime) >> 8);
01504 rgb[j].g = mrgbsource->rgb[j].g + (unsigned char)(((mrgbsource->rgb[k].g - mrgbsource->rgb[j].g) * ltime) >> 8);
01505 rgb[j].b = mrgbsource->rgb[j].b + (unsigned char)(((mrgbsource->rgb[k].b - mrgbsource->rgb[j].b) * ltime) >> 8);
01506 rgb[j].a = mrgbsource->rgb[j].a + (unsigned char)(((mrgbsource->rgb[k].b - mrgbsource->rgb[j].b) * ltime) >> 8);
01507
01508
01509
01510 AddVector((VEC*)&cvert.x, (VEC*)&mvsource[j]->x, (VEC*)&cvert.x);
01511 AddVector((VEC*)&cvert.nx, (VEC*)&mvsource[j]->nx, (VEC*)&cvert.nx);
01512
01513 cuv[0] += uvsource[j * 2];
01514 cuv[1] += uvsource[j * 2 + 1];
01515
01516 lrgb[0] += mrgbsource->rgb[j].b;
01517 lrgb[1] += mrgbsource->rgb[j].g;
01518 lrgb[2] += mrgbsource->rgb[j].r;
01519 lrgb[3] += mrgbsource->rgb[j].a;
01520 }
01521
01522
01523
01524 cvert.x /= (float)vcount;
01525 cvert.y /= (float)vcount;
01526 cvert.z /= (float)vcount;
01527
01528 NormalizeVector((VEC*)&cvert.nx);
01529
01530 cuv[0] /= (float)vcount;
01531 cuv[1] /= (float)vcount;
01532
01533 crgb.b = (unsigned char)(lrgb[0] / vcount);
01534 crgb.g = (unsigned char)(lrgb[1] / vcount);
01535 crgb.r = (unsigned char)(lrgb[2] / vcount);
01536 crgb.a = (unsigned char)(lrgb[3] / vcount);
01537
01538
01539
01540 if (mpsource->Type & POLY_QUAD)
01541 {
01542
01543 mpdest->Type = (mpsource->Type | POLY_DOUBLE | POLY_SEMITRANS) & ~POLY_SEMITRANS_ONE;
01544 mpdest->Tpage = mpsource->Tpage;
01545
01546 mpdest->tu0 = mpsource->tu0;
01547 mpdest->tv0 = mpsource->tv0;
01548 mpdest->tu1 = uv[0];
01549 mpdest->tv1 = uv[1];
01550 mpdest->tu2 = cuv[0];
01551 mpdest->tv2 = cuv[1];
01552 mpdest->tu3 = uv[6];
01553 mpdest->tv3 = uv[7];
01554
01555 mrgbdest->rgb[0] = mrgbsource->rgb[0];
01556 mrgbdest->rgb[1] = rgb[0];
01557 mrgbdest->rgb[2] = crgb;
01558 mrgbdest->rgb[3] = rgb[3];
01559
01560 mpdest->v0 = mvdest;
01561 *mvdest++ = *mpsource->v0;
01562 mpdest->v1 = mvdest;
01563 *mvdest++ = vert[0];
01564 mpdest->v2 = mvdest;
01565 *mvdest++ = cvert;
01566 mpdest->v3 = mvdest;
01567 *mvdest++ = vert[3];
01568
01569 mpdest++;
01570 mrgbdest++;
01571
01572 mpdest->Type = (mpsource->Type | POLY_DOUBLE | POLY_SEMITRANS) & ~POLY_SEMITRANS_ONE;
01573 mpdest->Tpage = mpsource->Tpage;
01574
01575 mpdest->tu0 = uv[0];
01576 mpdest->tv0 = uv[1];
01577 mpdest->tu1 = mpsource->tu1;
01578 mpdest->tv1 = mpsource->tv1;
01579 mpdest->tu2 = uv[2];
01580 mpdest->tv2 = uv[3];
01581 mpdest->tu3 = cuv[0];
01582 mpdest->tv3 = cuv[1];
01583
01584 mrgbdest->rgb[0] = rgb[0];
01585 mrgbdest->rgb[1] = mrgbsource->rgb[1];
01586 mrgbdest->rgb[2] = rgb[1];
01587 mrgbdest->rgb[3] = crgb;
01588
01589 mpdest->v0 = mvdest;
01590 *mvdest++ = vert[0];
01591 mpdest->v1 = mvdest;
01592 *mvdest++ = *mpsource->v1;
01593 mpdest->v2 = mvdest;
01594 *mvdest++ = vert[1];
01595 mpdest->v3 = mvdest;
01596 *mvdest++ = cvert;
01597
01598 mpdest++;
01599 mrgbdest++;
01600
01601 mpdest->Type = (mpsource->Type | POLY_DOUBLE | POLY_SEMITRANS) & ~POLY_SEMITRANS_ONE;
01602 mpdest->Tpage = mpsource->Tpage;
01603
01604 mpdest->tu0 = cuv[0];
01605 mpdest->tv0 = cuv[1];
01606 mpdest->tu1 = uv[2];
01607 mpdest->tv1 = uv[3];
01608 mpdest->tu2 = mpsource->tu2;
01609 mpdest->tv2 = mpsource->tv2;
01610 mpdest->tu3 = uv[4];
01611 mpdest->tv3 = uv[5];
01612
01613 mrgbdest->rgb[0] = crgb;
01614 mrgbdest->rgb[1] = rgb[1];
01615 mrgbdest->rgb[2] = mrgbsource->rgb[2];
01616 mrgbdest->rgb[3] = rgb[2];
01617
01618 mpdest->v0 = mvdest;
01619 *mvdest++ = cvert;
01620 mpdest->v1 = mvdest;
01621 *mvdest++ = vert[1];
01622 mpdest->v2 = mvdest;
01623 *mvdest++ = *mpsource->v2;
01624 mpdest->v3 = mvdest;
01625 *mvdest++ = vert[2];
01626
01627 mpdest++;
01628 mrgbdest++;
01629
01630 mpdest->Type = (mpsource->Type | POLY_DOUBLE | POLY_SEMITRANS) & ~POLY_SEMITRANS_ONE;
01631 mpdest->Tpage = mpsource->Tpage;
01632
01633 mpdest->tu0 = uv[6];
01634 mpdest->tv0 = uv[7];
01635 mpdest->tu1 = cuv[0];
01636 mpdest->tv1 = cuv[1];
01637 mpdest->tu2 = uv[4];
01638 mpdest->tv2 = uv[5];
01639 mpdest->tu3 = mpsource->tu3;
01640 mpdest->tv3 = mpsource->tv3;
01641
01642 mrgbdest->rgb[0] = rgb[3];
01643 mrgbdest->rgb[1] = crgb;
01644 mrgbdest->rgb[2] = rgb[2];
01645 mrgbdest->rgb[3] = mrgbsource->rgb[3];
01646
01647 mpdest->v0 = mvdest;
01648 *mvdest++ = vert[3];
01649 mpdest->v1 = mvdest;
01650 *mvdest++ = cvert;
01651 mpdest->v2 = mvdest;
01652 *mvdest++ = vert[2];
01653 mpdest->v3 = mvdest;
01654 *mvdest++ = *mpsource->v3;
01655
01656 mpdest++;
01657 mrgbdest++;
01658 }
01659 else
01660 {
01661
01662 mpdest->Type = (mpsource->Type | POLY_DOUBLE | POLY_SEMITRANS | POLY_QUAD) & ~POLY_SEMITRANS_ONE;
01663 mpdest->Tpage = mpsource->Tpage;
01664
01665 mpdest->tu0 = mpsource->tu0;
01666 mpdest->tv0 = mpsource->tv0;
01667 mpdest->tu1 = uv[0];
01668 mpdest->tv1 = uv[1];
01669 mpdest->tu2 = cuv[0];
01670 mpdest->tv2 = cuv[1];
01671 mpdest->tu3 = uv[4];
01672 mpdest->tv3 = uv[5];
01673
01674 mrgbdest->rgb[0] = mrgbsource->rgb[0];
01675 mrgbdest->rgb[1] = rgb[0];
01676 mrgbdest->rgb[2] = crgb;
01677 mrgbdest->rgb[3] = rgb[2];
01678
01679 mpdest->v0 = mvdest;
01680 *mvdest++ = *mpsource->v0;
01681 mpdest->v1 = mvdest;
01682 *mvdest++ = vert[0];
01683 mpdest->v2 = mvdest;
01684 *mvdest++ = cvert;
01685 mpdest->v3 = mvdest;
01686 *mvdest++ = vert[2];
01687
01688 mpdest++;
01689 mrgbdest++;
01690
01691 mpdest->Type = (mpsource->Type | POLY_DOUBLE | POLY_SEMITRANS | POLY_QUAD) & ~POLY_SEMITRANS_ONE;
01692 mpdest->Tpage = mpsource->Tpage;
01693
01694 mpdest->tu0 = uv[0];
01695 mpdest->tv0 = uv[1];
01696 mpdest->tu1 = mpsource->tu1;
01697 mpdest->tv1 = mpsource->tv1;
01698 mpdest->tu2 = uv[2];
01699 mpdest->tv2 = uv[3];
01700 mpdest->tu3 = cuv[0];
01701 mpdest->tv3 = cuv[1];
01702
01703 mrgbdest->rgb[0] = rgb[0];
01704 mrgbdest->rgb[1] = mrgbsource->rgb[1];
01705 mrgbdest->rgb[2] = rgb[1];
01706 mrgbdest->rgb[3] = crgb;
01707
01708 mpdest->v0 = mvdest;
01709 *mvdest++ = vert[0];
01710 mpdest->v1 = mvdest;
01711 *mvdest++ = *mpsource->v1;
01712 mpdest->v2 = mvdest;
01713 *mvdest++ = vert[1];
01714 mpdest->v3 = mvdest;
01715 *mvdest++ = cvert;
01716
01717 mpdest++;
01718 mrgbdest++;
01719
01720 mpdest->Type = (mpsource->Type | POLY_DOUBLE | POLY_SEMITRANS | POLY_QUAD) & ~POLY_SEMITRANS_ONE;
01721 mpdest->Tpage = mpsource->Tpage;
01722
01723 mpdest->tu0 = cuv[0];
01724 mpdest->tv0 = cuv[1];
01725 mpdest->tu1 = uv[2];
01726 mpdest->tv1 = uv[3];
01727 mpdest->tu2 = mpsource->tu2;
01728 mpdest->tv2 = mpsource->tv2;
01729 mpdest->tu3 = uv[4];
01730 mpdest->tv3 = uv[5];
01731
01732 mrgbdest->rgb[0] = crgb;
01733 mrgbdest->rgb[1] = rgb[1];
01734 mrgbdest->rgb[2] = mrgbsource->rgb[2];
01735 mrgbdest->rgb[3] = rgb[2];
01736
01737 mpdest->v0 = mvdest;
01738 *mvdest++ = cvert;
01739 mpdest->v1 = mvdest;
01740 *mvdest++ = vert[1];
01741 mpdest->v2 = mvdest;
01742 *mvdest++ = *mpsource->v2;
01743 mpdest->v3 = mvdest;
01744 *mvdest++ = vert[2];
01745
01746 mpdest++;
01747 mrgbdest++;
01748 }
01749 }
01750 }
01751
01752
01753
01754 particle = (DISSOLVE_PARTICLE*)(dissolve->Model.VertPtr + vertnum);
01755 mpsource = dissolve->Model.PolyPtr;
01756
01757 for (i = 0 ; i < polynum ; i++, particle++, mpsource++)
01758 {
01759 centre.v[X] = (mpsource->v0->x + mpsource->v1->x + mpsource->v2->x + mpsource->v3->x) / 4.0f;
01760 centre.v[Y] = (mpsource->v0->y + mpsource->v1->y + mpsource->v2->y + mpsource->v3->y) / 4.0f;
01761 centre.v[Z] = (mpsource->v0->z + mpsource->v1->z + mpsource->v2->z + mpsource->v3->z) / 4.0f;
01762
01763 NormalizeVector(¢re);
01764
01765 particle->Vel.v[X] = centre.v[X] * (frand(96.0f) + 96.0f);
01766 particle->Vel.v[Y] = centre.v[Y] * frand(96.0f) - 192.0f;
01767 particle->Vel.v[Z] = centre.v[Z] * (frand(96.0f) + 96.0f);
01768
01769 particle->Rot.v[X] = frand(1.0f) - 0.5f;
01770 particle->Rot.v[Y] = frand(1.0f) - 0.5f;
01771 particle->Rot.v[Z] = frand(1.0f) - 0.5f;
01772 }
01773
01774
01775
01776 dissolve->Age = 0.0f;
01777
01778 CopyMatrix(&Identity, &obj->body.Centre.WMatrix);
01779
01780
01781
01782 obj->renderflag.envmap = FALSE;
01783 obj->renderflag.light = FALSE;
01784 obj->renderflag.reflect = FALSE;
01785
01786
01787
01788 obj->aihandler = (AI_HANDLER)AI_DissolveModelHandler;
01789 obj->renderhandler = (RENDER_HANDLER)RenderDissolveModel;
01790
01791
01792
01793 return TRUE;
01794 }
01795
01796
01798
01799
01800
01802
01803 long InitFlap(OBJECT *obj, long *flags)
01804 {
01805
01806 return TRUE;
01807 }
01808
01809
01811
01812
01813
01815
01816 long InitLaser(OBJECT *obj, long *flags)
01817 {
01818 REAL dist;
01819 VEC dest;
01820 LASER_OBJ *laser = (LASER_OBJ *)obj->Data;
01821
01822 obj->aihandler = (AI_HANDLER)AI_LaserHandler;
01823 obj->renderhandler = (RENDER_HANDLER)RenderLaser;
01824
01825
01826 VecPlusScalarVec(&obj->body.Centre.Pos, 10000, &obj->body.Centre.WMatrix.mv[L], &dest);
01827 if (!LineOfSightDist(&obj->body.Centre.Pos, &dest, &dist, NULL)) {
01828 Box("Error", "Laser goes on for ever.........", MB_OK | MB_ICONWARNING);
01829 }
01830 VecPlusScalarVec(&obj->body.Centre.Pos, 10000 * dist, &obj->body.Centre.WMatrix.mv[L], &laser->Dest);
01831 VecMinusVec(&laser->Dest, &obj->body.Centre.Pos, &laser->Delta);
01832 SetBBox(&obj->body.CollSkin.BBox, LARGEDIST, -LARGEDIST, LARGEDIST, -LARGEDIST, LARGEDIST, -LARGEDIST);
01833 AddPointToBBox(&obj->body.CollSkin.BBox, &obj->body.Centre.Pos);
01834 AddPointToBBox(&obj->body.CollSkin.BBox, &laser->Dest);
01835 obj->body.CollSkin.Radius = obj->body.CollSkin.BBox.XMax - obj->body.CollSkin.BBox.XMin;
01836 obj->body.CollSkin.Radius = Max(obj->body.CollSkin.Radius, obj->body.CollSkin.BBox.YMax - obj->body.CollSkin.BBox.YMin);
01837 obj->body.CollSkin.Radius = Max(obj->body.CollSkin.Radius, obj->body.CollSkin.BBox.ZMax - obj->body.CollSkin.BBox.ZMin);
01838
01839 laser->Width = (REAL)flags[0];
01840 laser->RandWidth = (REAL)flags[1];
01841 laser->Length = VecLen(&laser->Delta);
01842 laser->ObjectCollide = (bool)flags[2];
01843 laser->Phase = (long)frand(1000);
01844 laser->VisiMask = SetObjectVisiMask((BOUNDING_BOX *)&obj->body.CollSkin.BBox);
01845
01846 return TRUE;
01847 }
01848
01850
01852
01853 long InitSplash(OBJECT *obj, long *flags)
01854 {
01855 SPLASH_OBJ *splash = (SPLASH_OBJ*)obj->Data;
01856 SPLASH_POLY *spoly;
01857 long i;
01858 REAL rad, size, mul;
01859 MAT mat, mat2;
01860 VEC v0, v1, v2, v3, vel;
01861
01862
01863
01864 obj->aihandler = (AI_HANDLER)AI_SplashHandler;
01865 obj->renderhandler = (RENDER_HANDLER)RenderSplash;
01866
01867
01868
01869 splash->Count = SPLASH_POLY_NUM;
01870
01871
01872
01873 spoly = splash->Poly;
01874
01875 for (i = 0 ; i < SPLASH_POLY_NUM ; i++, spoly++)
01876 {
01877 spoly->Frame = 0.0f;
01878 spoly->FrameAdd = (frand(0.5f) + 1.0f) * 16.0f;
01879
01880 RotMatrixY(&mat, frand(1.0f));
01881 MulMatrix(&obj->body.Centre.WMatrix, &mat, &mat2);
01882
01883 rad = frand(48.0f);
01884
01885 size = frand(rad * 0.666f) + 8.0f;
01886
01887 SetVector(&v0, -size, -size * 4.0f, rad * 1.8f);
01888 SetVector(&v1, size, -size * 4.0f, rad * 1.8f);
01889 SetVector(&v2, size, 0.0f, rad);
01890 SetVector(&v3, -size, 0.0f, rad);
01891
01892 RotTransVector(&mat2, &obj->body.Centre.Pos, &v0, &spoly->Pos[0]);
01893 RotTransVector(&mat2, &obj->body.Centre.Pos, &v1, &spoly->Pos[1]);
01894 RotTransVector(&mat2, &obj->body.Centre.Pos, &v2, &spoly->Pos[2]);
01895 RotTransVector(&mat2, &obj->body.Centre.Pos, &v3, &spoly->Pos[3]);
01896
01897 SubVector(&spoly->Pos[0], &spoly->Pos[3], &vel);
01898 mul = (frand(256.0f) + 128.0f) / Length(&vel);
01899 VecMulScalar(&vel, mul);
01900
01901 SetVector(&spoly->Vel[0], vel.v[X] + frand(32.0f) - 16.0f, vel.v[Y] + frand(32.0f) - 16.0f, vel.v[Z] + frand(32.0f) - 16.0f);
01902 SetVector(&spoly->Vel[1], vel.v[X] + frand(32.0f) - 16.0f, vel.v[Y] + frand(32.0f) - 16.0f, vel.v[Z] + frand(32.0f) - 16.0f);
01903 SetVector(&spoly->Vel[2], vel.v[X] + frand(32.0f) - 16.0f, vel.v[Y] + frand(32.0f) - 16.0f, vel.v[Z] + frand(32.0f) - 16.0f);
01904 SetVector(&spoly->Vel[3], vel.v[X] + frand(32.0f) - 16.0f, vel.v[Y] + frand(32.0f) - 16.0f, vel.v[Z] + frand(32.0f) - 16.0f);
01905 }
01906
01907
01908
01909 return TRUE;
01910 }
01911
01912 #endif
01913
01914
01915 #ifdef _N64
01916
01917
01918
01919
01920
01921
01922 long LoadOneLevelModel(long id, long UseMRGBper, struct renderflags renderflag, long tpage)
01923 {
01924 long ii;
01925 FIL *fp;
01926 long rgbper;
01927 long Flag = 0;
01928
01929
01930 #if 0
01931 for (ii = 0; ii < MAX_LEVEL_MODELS ; ii++)
01932 {
01933 if (LevelModel[ii].ID == id)
01934 {
01935 LevelModel[ii].RefCount++;
01936 return ii;
01937 }
01938 }
01939 #endif
01940
01941 for (ii = 0; ii < MAX_LEVEL_MODELS; ii++)
01942 {
01943 if (LevelModel[ii].ID == -1)
01944 {
01945
01946 if (UseMRGBper)
01947 rgbper = LevelInf[GameSettings.Level].ModelRGBper;
01948 else
01949 rgbper = 100;
01950
01951 if (renderflag.envmap) Flag |= MODEL_ENV;
01952 if (renderflag.envonly) Flag |= MODEL_ENVONLY;
01953 if (renderflag.light) Flag |= MODEL_LIT;
01954
01955 MOD_LoadModel(LevelModelList[id].Model, LevelModelList[id].Tex, &LevelModel[ii].Model, 0x808080, rgbper, Flag);
01956
01957
01958 if (LevelModelList[id].Coll)
01959 {
01960 if ((fp = FFS_Open(LevelModelList[id].Coll)) != NULL)
01961 {
01962 if ((LevelModel[ii].CollSkin.Convex = LoadConvex(fp, &LevelModel[ii].CollSkin.NConvex, 0)) != NULL)
01963 {
01964 if ((LevelModel[ii].CollSkin.Sphere = LoadSpheres(fp, &LevelModel[ii].CollSkin.NSpheres)) != NULL)
01965 {
01966 LevelModel[ii].CollSkin.CollType = BODY_COLL_CONVEX;
01967 MakeTightLocalBBox(&LevelModel[ii].CollSkin);
01968 }
01969 }
01970 FFS_Close(fp);
01971 }
01972 }
01973
01974
01975 LevelModel[ii].ID = id;
01976 LevelModel[ii].RefCount = 1;
01977 return ii;
01978 }
01979 }
01980
01981
01982
01983 return -1;
01984 }
01985 #endif