Skip to content

Commit d44f770

Browse files
committed
- add decompiled birds code from Driver 1, adjust so it works
1 parent c91805f commit d44f770

File tree

6 files changed

+205
-8
lines changed

6 files changed

+205
-8
lines changed

src_rebuild/Game/C/bcollide.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,12 +895,20 @@ int CarBuildingCollision(CAR_DATA *cp, BUILDING_BOX *building, CELL_OBJECT *cop,
895895
{
896896
if (model->flags2 & MODEL_FLAG_TREE)
897897
{
898+
int rnd;
898899
VECTOR LeafPosition;
899900
LeafPosition.vx = collisionResult.hit.vx;
900-
LeafPosition.vy = -((rand() & 0xfe) + 600) - collisionResult.hit.vy;
901+
LeafPosition.vy = -((rand() & 254) + 600) - collisionResult.hit.vy;
901902
LeafPosition.vz = collisionResult.hit.vz;
902903

903904
AddLeaf(&LeafPosition, 3, 1);
905+
906+
rnd = rand();
907+
if ((rnd & 1) == 0)
908+
{
909+
LeafPosition.vy -= 1100;
910+
CreateBirds(&LeafPosition, (rnd >> 8) & 7);
911+
}
904912
}
905913
else
906914
{

src_rebuild/Game/C/debris.c

Lines changed: 185 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ struct LEAF
8888
char sin_addition2;
8989
};
9090

91+
struct BIRD
92+
{
93+
VECTOR_NOPAD position;
94+
SVECTOR_NOPAD direction;
95+
short life;
96+
short step;
97+
};
98+
9199
struct TRI_POINT
92100
{
93101
BVECTOR v0;
@@ -389,6 +397,9 @@ LEAF leaf[MAX_LEAVES];
389397
SVECTOR debris_rotvec;
390398
DEBRIS debris[MAX_DEBRIS];
391399

400+
BIRD birds[MAX_BIRDS];
401+
int gNumBirds = 0;
402+
392403
int StreakCount1 = 0;
393404
int main_cop_light_pos = 0;
394405
int NextDamagedLamp = 0;
@@ -755,6 +766,174 @@ void AddLeaf(VECTOR *Position, int num_leaves, int Type)
755766
}
756767
}
757768

769+
// [D] [T]
770+
void CreateBirds(VECTOR* pos, int count)
771+
{
772+
BIRD *bird;
773+
int i;
774+
775+
if (bird_texture1.tpageid == 0 || bird_texture2.tpageid == 0)
776+
{
777+
return;
778+
}
779+
780+
if (count >= MAX_BIRDS)
781+
count = MAX_BIRDS-1;
782+
783+
if (birds[0].life != 0)
784+
{
785+
return;
786+
}
787+
788+
gNumBirds = count;
789+
for (i = 0; i < count; ++i)
790+
{
791+
bird = &birds[i];
792+
bird->position.vx = pos->vx - 32 + (rand() & 63);
793+
bird->position.vy = pos->vy - 32 + (rand() & 63);
794+
bird->position.vz = pos->vz - 32 + (rand() & 63);
795+
bird->direction.vx = (rand() & 63) - 32;
796+
bird->direction.vy = -10 - (rand() & 16);
797+
bird->direction.vz = (rand() & 63) - 32;
798+
bird->life = 120;
799+
bird->step = rand() & 7;
800+
}
801+
}
802+
803+
// [D] [T]
804+
void HandleBirds()
805+
{
806+
BIRD* bird;
807+
POLY_FT4* primptr;
808+
VECTOR pos;
809+
SVECTOR vertPos[4];
810+
u_short clutid;
811+
short sizeX;
812+
short sizeY;
813+
int i;
814+
int z;
815+
int bright;
816+
817+
if (birds[0].life == 0 || gNumBirds == 0)
818+
{
819+
return;
820+
}
821+
822+
gte_SetRotMatrix(&identity);
823+
824+
bright = 128;
825+
if (gNight != 0)
826+
bright = 64;
827+
828+
for(i = 0; i < gNumBirds; ++i)
829+
{
830+
bird = &birds[i];
831+
if (bird->life <= 0)
832+
{
833+
continue;
834+
}
835+
836+
pos.vx = bird->position.vx - camera_position.vx;
837+
pos.vy = bird->position.vy - camera_position.vy;
838+
pos.vz = bird->position.vz - camera_position.vz;
839+
Apply_Inv_CameraMatrix(&pos);
840+
841+
gte_SetTransVector(&pos);
842+
843+
if (pauseflag == 0 && pos.vz > 13500)
844+
{
845+
bird->life = 0;
846+
return;
847+
}
848+
849+
sizeX = 40;
850+
if (bird->step < 4)
851+
{
852+
sizeY = 19;
853+
}
854+
else
855+
{
856+
sizeX = 64;
857+
sizeY = 24;
858+
}
859+
vertPos[0].vy = -sizeY;
860+
vertPos[1].vy = -sizeY;
861+
vertPos[0].vx = -sizeX;
862+
vertPos[0].vz = 0;
863+
vertPos[1].vx = sizeX;
864+
vertPos[1].vz = 0;
865+
vertPos[2].vx = -sizeX;
866+
vertPos[2].vy = sizeY;
867+
vertPos[2].vz = 0;
868+
vertPos[3].vx = sizeX;
869+
vertPos[3].vy = sizeY;
870+
vertPos[3].vz = 0;
871+
872+
gte_ldv3(&vertPos[0], &vertPos[1], &vertPos[2]);
873+
gte_rtpt();
874+
875+
primptr = (POLY_FT4*)current->primptr;
876+
if (bird->step < 4)
877+
{
878+
primptr->u0 = bird_texture2.coords.u0;
879+
primptr->v0 = bird_texture2.coords.v0;
880+
primptr->u1 = bird_texture2.coords.u1;
881+
primptr->v1 = bird_texture2.coords.v1;
882+
primptr->u2 = bird_texture2.coords.u2;
883+
primptr->v2 = bird_texture2.coords.v2;
884+
primptr->u3 = bird_texture2.coords.u3;
885+
primptr->v3 = bird_texture2.coords.v3;
886+
primptr->tpage = bird_texture2.tpageid;
887+
clutid = bird_texture2.clutid;
888+
}
889+
else
890+
{
891+
primptr->u0 = bird_texture1.coords.u0;
892+
primptr->v0 = bird_texture1.coords.v0;
893+
primptr->u1 = bird_texture1.coords.u1;
894+
primptr->v1 = bird_texture1.coords.v1;
895+
primptr->u2 = bird_texture1.coords.u2;
896+
primptr->v2 = bird_texture1.coords.v2;
897+
primptr->u3 = bird_texture1.coords.u3;
898+
primptr->v3 = bird_texture1.coords.v3;
899+
primptr->tpage = bird_texture1.tpageid;
900+
clutid = bird_texture1.clutid;
901+
}
902+
903+
primptr->clut = clutid;
904+
setPolyFT4(primptr);
905+
primptr->r0 = bright;
906+
primptr->g0 = bright;
907+
primptr->b0 = bright;
908+
909+
gte_stsz(&z);
910+
if (z < 150)
911+
continue;
912+
913+
gte_stsxy3(&primptr->x0, &primptr->x1, &primptr->x2);
914+
915+
gte_ldv0(&vertPos[3]);
916+
gte_rtps();
917+
918+
gte_stsxy(&primptr->x3);
919+
920+
addPrim(current->ot + (z >> 3), primptr);
921+
922+
current->primptr += sizeof(POLY_FT4);
923+
924+
if (pauseflag == 0)
925+
{
926+
bird->position.vx += bird->direction.vx;
927+
bird->position.vy += bird->direction.vy;
928+
bird->position.vz = bird->position.vz + bird->direction.vz;
929+
930+
if (--bird->step == -1)
931+
bird->step = 8;
932+
--bird->life;
933+
}
934+
}
935+
}
936+
758937
// [D] [T]
759938
void SwirlLeaves(CAR_DATA *cp)
760939
{
@@ -801,8 +980,8 @@ void InitDebrisNames(void)
801980
GetTextureDetails("SKID", &gTyreTexture);
802981
GetTextureDetails("FLARE", &flare_texture);
803982
GetTextureDetails("SPLASH", &sea_texture);
804-
GetTextureDetails("SWBIRD1", &bird_texture1);
805-
GetTextureDetails("SWBIRD2", &bird_texture2);
983+
GetTextureDetails("SWBIRD1", &bird_texture1, 0);
984+
GetTextureDetails("SWBIRD2", &bird_texture2, 0);
806985
GetTextureDetails("LENSFLR", &lensflare_texture);
807986
GetTextureDetails("SKYSUN", &sun_texture);
808987
GetTextureDetails("SKYMOON", &moon_texture);
@@ -933,6 +1112,8 @@ void InitDebris(void)
9331112
}
9341113
}
9351114

1115+
birds[0].life = 0;
1116+
9361117
for (i = 0; i < MAX_SMOKE; i++)
9371118
{
9381119
smoke_alloc[i] = i;
@@ -3135,7 +3316,7 @@ void HandleDebris(void)
31353316
GetSmokeDrift(&Drift);
31363317

31373318
MoveHubcap();
3138-
3319+
HandleBirds();
31393320
SetRotMatrix(&inv_camera_matrix);
31403321

31413322
gte_SetTransVector(&dummy);
@@ -3530,7 +3711,7 @@ void DrawRainDrops(void)
35303711
bright = 50;
35313712

35323713
if (gNight != 0)
3533-
bright -= -15;
3714+
bright -= 15;
35343715

35353716
col = bright >> 1 | (bright >> 1) << 8;
35363717
col |= col | col << 0x10;

src_rebuild/Game/C/debris.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ extern void InitFXPos(VECTOR* vec, SVECTOR* svec, CAR_DATA* cp); // 0x00039C90
7777
extern void SwirlLeaves(CAR_DATA* cp); // 0x00039E54
7878
extern void AddLeaf(VECTOR* Position, int num_leaves, int Type); // 0x00033574
7979

80+
extern void CreateBirds(VECTOR* pos, int count);
81+
8082
extern void ShowCarlight(SVECTOR *v1, CAR_DATA *cp, CVECTOR *col, short size, short flare_size, TEXTURE_DETAILS *texture, int flag); // 0x000352CC
8183
extern void ShowLight1(VECTOR *v1, CVECTOR *col, short size, TEXTURE_DETAILS *texture); // 0x0003555C
8284
extern void ShowLight(VECTOR *v1, CVECTOR *col, short size, TEXTURE_DETAILS *texture); // 0x00035750

src_rebuild/Game/C/texture.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ void ReloadIcons(void)
599599
}
600600

601601
// [D] [T]
602-
void GetTextureDetails(char *name, TEXTURE_DETAILS *info)
602+
void GetTextureDetails(char *name, TEXTURE_DETAILS *info, int defaultToSea)
603603
{
604604
int i, j;
605605
int texamt;
@@ -632,7 +632,12 @@ void GetTextureDetails(char *name, TEXTURE_DETAILS *info)
632632
}
633633
}
634634

635-
GetTextureDetails("SEA", info); // weird but ok, ok...
635+
info->tpageid = 0;
636+
info->clutid = 0;
637+
info->texture_number = 0;
638+
info->texture_page = 0;
639+
if (defaultToSea)
640+
GetTextureDetails("SEA", info); // weird but ok, ok...
636641
}
637642

638643

src_rebuild/Game/C/texture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extern int LoadTPageAndCluts(RECT16 *tpage, RECT16 *cluts, int tpage2send, char
4040
extern int Find_TexID(MODEL *model, int t_id); // 0x000805EC
4141
extern TEXINF* GetTEXINFName(char *name, int *tpagenum, int *texturenum); // 0x00080F3C
4242
extern TEXINF* GetTextureInfoName(char *name, TPAN *result); // 0x00080DA0
43-
extern void GetTextureDetails(char *name, TEXTURE_DETAILS *info); // 0x00080BB0
43+
extern void GetTextureDetails(char *name, TEXTURE_DETAILS *info, int defaultToSea = 1); // 0x00080BB0
4444

4545
extern void update_slotinfo(int tpage, int slot, RECT16 *pos); // 0x00081038
4646

src_rebuild/Game/dr2limits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
// debris limits
6868
#define MAX_SMOKE 80
6969
#define MAX_LEAVES 50
70+
#define MAX_BIRDS 7
7071
#define MAX_DEBRIS 60
7172
#define MAX_GROUND_DEBRIS 16
7273
#define MAX_DAMAGED_LAMPS 5

0 commit comments

Comments
 (0)