2 * Elite - The New Kind.
4 * Reverse engineered from the BBC disk version of Elite.
5 * Additional material by C.J.Pinder.
7 * The original Elite code is (C) I.Bell & D.Braben 1984.
8 * This version re-engineered in C by C.J.Pinder 1999-2001.
10 * email: <christian@newkind.co.uk>
18 * Special Weapons And Tactics.
50 struct univ_object universe
[MAX_UNIV_OBJECTS
];
51 int ship_count
[NO_OF_SHIPS
+ 1]; /* many */
54 int initial_flags
[NO_OF_SHIPS
+ 1] =
57 FLG_TARGET
, // missile
59 FLG_SLOW
| FLG_FLY_TO_PLANET
, // escape
60 FLG_INACTIVE
| FLG_TARGET
, // alloy
61 FLG_INACTIVE
| FLG_TARGET
, // cargo
62 FLG_INACTIVE
| FLG_TARGET
, // boulder
63 FLG_INACTIVE
| FLG_TARGET
, // asteroid
64 FLG_INACTIVE
| FLG_TARGET
, // rock
65 FLG_FLY_TO_PLANET
| FLG_SLOW
, // shuttle
66 FLG_FLY_TO_PLANET
| FLG_SLOW
, // transporter
72 FLG_BOLD
| FLG_POLICE
, // viper
73 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // sidewinder
74 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // mamba
75 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // krait
76 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // adder
77 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // gecko
78 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // cobra1
79 FLG_SLOW
| FLG_ANGRY
| FLG_TARGET
, // worm
80 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // cobra3
81 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // asp2
82 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // python
83 FLG_POLICE
, // fer_de_lance
84 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // moray
85 FLG_BOLD
| FLG_ANGRY
| FLG_TARGET
, // thargoid
86 FLG_ANGRY
| FLG_TARGET
, // thargon
87 FLG_ANGRY
, // constrictor
88 FLG_POLICE
| FLG_CLOAKED
, // cougar
95 void clear_universe (void)
99 for (i
= 0; i
< MAX_UNIV_OBJECTS
; i
++)
100 universe
[i
].type
= 0;
102 for (i
= 0; i
<= NO_OF_SHIPS
; i
++)
109 int add_new_ship (int ship_type
, int x
, int y
, int z
, struct vector
*rotmat
, int rotx
, int rotz
)
113 for (i
= 0; i
< MAX_UNIV_OBJECTS
; i
++)
115 if (universe
[i
].type
== 0)
117 universe
[i
].type
= ship_type
;
118 universe
[i
].location
.x
= x
;
119 universe
[i
].location
.y
= y
;
120 universe
[i
].location
.z
= z
;
122 universe
[i
].distance
= sqrt(x
*x
+ y
*y
+ z
*z
);
124 universe
[i
].rotmat
[0] = rotmat
[0];
125 universe
[i
].rotmat
[1] = rotmat
[1];
126 universe
[i
].rotmat
[2] = rotmat
[2];
128 universe
[i
].rotx
= rotx
;
129 universe
[i
].rotz
= rotz
;
131 universe
[i
].velocity
= 0;
132 universe
[i
].acceleration
= 0;
133 universe
[i
].bravery
= 0;
134 universe
[i
].target
= 0;
136 universe
[i
].flags
= initial_flags
[ship_type
];
138 if ((ship_type
!= SHIP_PLANET
) && (ship_type
!= SHIP_SUN
))
140 universe
[i
].energy
= ship_list
[ship_type
]->energy
;
141 universe
[i
].missiles
= ship_list
[ship_type
]->missiles
;
142 ship_count
[ship_type
]++;
155 void check_missiles (int un
)
159 if (missile_target
== un
)
161 missile_target
= MISSILE_UNARMED
;
162 info_message ("Target Lost");
165 for (i
= 0; i
< MAX_UNIV_OBJECTS
; i
++)
167 if ((universe
[i
].type
== SHIP_MISSILE
) && (universe
[i
].target
== un
))
168 universe
[i
].flags
|= FLG_DEAD
;
173 void remove_ship (int un
)
179 type
= universe
[un
].type
;
187 universe
[un
].type
= 0;
191 if ((type
== SHIP_CORIOLIS
) || (type
== SHIP_DODEC
))
193 set_init_matrix (rotmat
);
194 px
= universe
[un
].location
.x
;
195 py
= universe
[un
].location
.y
;
196 pz
= universe
[un
].location
.z
;
201 add_new_ship (SHIP_SUN
, px
, py
, pz
, rotmat
, 0, 0);
206 void add_new_station (double sx
, double sy
, double sz
, Matrix rotmat
)
210 station
= (current_planet_data
.techlevel
>= 10) ? SHIP_DODEC
: SHIP_CORIOLIS
;
211 universe
[1].type
= 0;
212 add_new_ship (station
, sx
, sy
, sz
, rotmat
, 0, -127);
218 void reset_weapons (void)
224 missile_target
= MISSILE_UNARMED
;
228 void launch_enemy (int un
, int type
, int flags
, int bravery
)
231 struct univ_object
*ns
;
233 newship
= add_new_ship (type
, universe
[un
].location
.x
, universe
[un
].location
.y
,
234 universe
[un
].location
.z
, universe
[un
].rotmat
,
235 universe
[un
].rotx
, universe
[un
].rotz
);
242 ns
= &universe
[newship
];
244 if ((universe
[un
].type
== SHIP_CORIOLIS
) || (universe
[un
].type
== SHIP_DODEC
))
247 ns
->location
.x
+= ns
->rotmat
[2].x
* 2;
248 ns
->location
.y
+= ns
->rotmat
[2].y
* 2;
249 ns
->location
.z
+= ns
->rotmat
[2].z
* 2;
255 ns
->bravery
= bravery
;
257 if ((type
== SHIP_CARGO
) || (type
== SHIP_ALLOY
) || (type
== SHIP_ROCK
))
259 ns
->rotz
= ((rand255() * 2) & 255) - 128;
260 ns
->rotx
= ((rand255() * 2) & 255) - 128;
261 ns
->velocity
= rand255() & 15;
266 void launch_loot (int un
, int loot
)
270 if (loot
== SHIP_ROCK
)
280 cnt
&= ship_list
[universe
[un
].type
]->max_loot
;
284 for (i
= 0; i
< cnt
; i
++)
286 launch_enemy (un
, loot
, 0,0);
293 int in_target (int type
, double x
, double y
, double z
)
300 size
= ship_list
[type
]->size
;
302 return ((x
*x
+ y
*y
) <= size
);
307 void make_angry (int un
)
312 type
= universe
[un
].type
;
313 flags
= universe
[un
].flags
;
315 if (flags
& FLG_INACTIVE
) {
316 universe
[un
].flags
|= FLG_TACTICAL
;
320 if ((type
== SHIP_CORIOLIS
) || (type
== SHIP_DODEC
))
322 universe
[un
].flags
|= FLG_ANGRY
;
326 if (!(universe
[un
].flags
& FLG_TARGET
) &&
327 (universe
[1].type
== SHIP_CORIOLIS
||
328 universe
[1].type
== SHIP_DODEC
))
329 universe
[1].flags
|= FLG_ANGRY
;
331 if (type
> SHIP_ROCK
)
333 universe
[un
].rotx
= 4;
334 universe
[un
].acceleration
= 2;
335 universe
[un
].flags
|= FLG_ANGRY
| FLG_TACTICAL
;
340 void explode_object (int un
)
345 if ((cmdr
.score
& 255) == 0)
346 info_message ("Right On Commander!");
348 snd_play_sample (SND_EXPLODE
);
349 universe
[un
].flags
|= FLG_DEAD
;
351 if (universe
[un
].type
== SHIP_CONSTRICTOR
)
356 void check_target (int un
, struct univ_object
*flip
)
358 struct univ_object
*univ
;
361 univ
= &universe
[un
];
363 if (in_target (univ
->type
, flip
->location
.x
, flip
->location
.y
, flip
->location
.z
))
365 if ((missile_target
== MISSILE_ARMED
) && (univ
->type
>= 0))
368 sprintf(buf
, "Target Locked (%s)",
369 ship_list
[univ
->type
]->name
);
371 snd_play_sample (SND_BEEP
);
376 snd_play_sample (SND_HIT_ENEMY
);
378 if ((univ
->type
!= SHIP_CORIOLIS
) && (univ
->type
!= SHIP_DODEC
))
380 if ((univ
->type
== SHIP_CONSTRICTOR
) || (univ
->type
== SHIP_COUGAR
))
382 if (laser
== (MILITARY_LASER
& 127))
383 univ
->energy
-= laser
/ 4;
387 univ
->energy
-= laser
;
391 if (univ
->energy
<= 0)
395 if (univ
->type
== SHIP_ASTEROID
)
397 if (laser
== (MINING_LASER
& 127))
398 launch_loot (un
, SHIP_ROCK
);
402 launch_loot (un
, SHIP_ALLOY
);
403 launch_loot (un
, SHIP_CARGO
);
414 void activate_ecm (int ours
)
420 snd_play_sample (SND_ECM
);
431 decrease_energy (-1);
436 void arm_missile (void)
438 if ((cmdr
.missiles
!= 0) && (missile_target
== MISSILE_UNARMED
))
439 missile_target
= MISSILE_ARMED
;
443 void unarm_missile (void)
445 missile_target
= MISSILE_UNARMED
;
446 snd_play_sample (SND_BOOP
);
449 void fire_missile (void)
452 struct univ_object
*ns
;
455 if (missile_target
< 0)
458 set_init_matrix (rotmat
);
462 newship
= add_new_ship (SHIP_MISSILE
, 0, -28, 14, rotmat
, 0, 0);
466 info_message ("Missile Jammed");
470 ns
= &universe
[newship
];
472 ns
->velocity
= flight_speed
* 2;
473 ns
->flags
|= FLG_TACTICAL
;
474 ns
->target
= missile_target
;
476 if (universe
[missile_target
].type
> SHIP_ROCK
)
477 universe
[missile_target
].flags
|= FLG_ANGRY
;
480 missile_target
= MISSILE_UNARMED
;
482 snd_play_sample (SND_MISSILE
);
487 void track_object (struct univ_object
*ship
, double direction
, Vector nvec
)
496 dir
= vector_dot_product (&nvec
, &ship
->rotmat
[1]);
498 if (direction
< -0.861)
500 ship
->rotx
= (dir
< 0) ?
7 : -7;
507 if ((fabs(dir
) * 2) >= rat2
)
509 ship
->rotx
= (dir
< 0) ? rat
: -rat
;
512 if (abs(ship
->rotz
) < 16)
514 dir
= vector_dot_product (&nvec
, &ship
->rotmat
[0]);
518 if ((fabs(dir
) * 2) > rat2
)
520 ship
->rotz
= (dir
< 0) ? rat
: -rat
;
523 ship
->rotz
= -ship
->rotz
;
530 void missile_tactics (int un
)
532 struct univ_object
*missile
;
533 struct univ_object
*target
;
539 missile
= &universe
[un
];
543 snd_play_sample (SND_EXPLODE
);
544 missile
->flags
|= FLG_DEAD
;
548 if (missile
->target
== 0)
550 if (missile
->distance
< 256)
552 missile
->flags
|= FLG_DEAD
;
553 snd_play_sample (SND_EXPLODE
);
554 damage_ship (250, missile
->location
.z
>= 0.0);
558 vec
.x
= missile
->location
.x
;
559 vec
.y
= missile
->location
.y
;
560 vec
.z
= missile
->location
.z
;
564 target
= &universe
[missile
->target
];
566 vec
.x
= missile
->location
.x
- target
->location
.x
;
567 vec
.y
= missile
->location
.y
- target
->location
.y
;
568 vec
.z
= missile
->location
.z
- target
->location
.z
;
570 if ((fabs(vec
.x
) < 256) && (fabs(vec
.y
) < 256) && (fabs(vec
.z
) < 256))
572 missile
->flags
|= FLG_DEAD
;
574 if ((target
->type
!= SHIP_CORIOLIS
) && (target
->type
!= SHIP_DODEC
))
575 explode_object (missile
->target
);
577 snd_play_sample (SND_EXPLODE
);
582 if ((rand255() < 16) && (target
->flags
& FLG_HAS_ECM
))
589 if ((rand255() < 16) &&
590 (ship_count
[SHIP_CORIOLIS
] || ship_count
[SHIP_DODEC
])) {
595 nvec
= unit_vector(&vec
);
596 direction
= vector_dot_product (&nvec
, &missile
->rotmat
[2]);
600 direction
= -direction
;
602 track_object (missile
, direction
, nvec
);
604 if (direction
<= -0.167)
606 missile
->acceleration
= -2;
610 if (direction
>= cnt2
)
612 missile
->acceleration
= 3;
616 if (missile
->velocity
< 6)
617 missile
->acceleration
= 3;
619 if (rand255() >= 200)
620 missile
->acceleration
= -2;
626 void launch_shuttle (void)
630 if ((ship_count
[SHIP_TRANSPORTER
] != 0) ||
631 (ship_count
[SHIP_SHUTTLE
] != 0) ||
632 (rand255() < 253) || (auto_pilot
))
635 type
= rand255() & 1 ? SHIP_SHUTTLE
: SHIP_TRANSPORTER
;
636 launch_enemy (1, type
, FLG_HAS_ECM
| FLG_FLY_TO_PLANET
, 113);
640 void tactics (int un
)
646 struct univ_object
*ship
;
652 ship
= &universe
[un
];
656 if ((type
== SHIP_PLANET
) || (type
== SHIP_SUN
))
659 if (flags
& FLG_DEAD
)
662 if (flags
& FLG_INACTIVE
)
665 if (type
== SHIP_MISSILE
)
667 if (flags
& FLG_ANGRY
)
668 missile_tactics (un
);
672 if (((un
^ mcount
) & 7) != 0)
675 if ((type
== SHIP_CORIOLIS
) || (type
== SHIP_DODEC
))
677 if (flags
& FLG_ANGRY
)
679 if ((rand() & 255) < 240)
682 if (ship_count
[SHIP_VIPER
] >= 4)
685 launch_enemy (un
, SHIP_VIPER
, FLG_ANGRY
| FLG_HAS_ECM
, 113);
693 if (type
== SHIP_HERMIT
)
697 launch_enemy (un
, SHIP_SIDEWINDER
+ (rand255() & 3), FLG_ANGRY
| FLG_HAS_ECM
, 113);
698 ship
->flags
|= FLG_INACTIVE
| FLG_TARGET
;
705 if (ship
->energy
< ship_list
[type
]->energy
)
708 if ((type
== SHIP_THARGLET
) && (ship_count
[SHIP_THARGOID
] == 0))
710 ship
->flags
&= FLG_TARGET
| FLG_TACTICAL
;
715 if (flags
& FLG_SLOW
)
721 if (flags
& FLG_POLICE
)
723 if (cmdr
.legal_status
>= 64)
725 flags
|= FLG_ANGRY
| FLG_TARGET
;
730 if ((flags
& FLG_ANGRY
) == 0)
732 if ((flags
& FLG_FLY_TO_PLANET
) || (flags
& FLG_FLY_TO_STATION
))
734 auto_pilot_ship (&universe
[un
]);
741 /* If we get to here then the ship is angry so start attacking... */
743 if (ship_count
[SHIP_CORIOLIS
] || ship_count
[SHIP_DODEC
])
745 if ((flags
& FLG_BOLD
) == 0)
750 if (type
== SHIP_ANACONDA
)
754 launch_enemy (un
, rand255() > 100 ? SHIP_WORM
: SHIP_SIDEWINDER
,
755 FLG_ANGRY
| FLG_HAS_ECM
, 113);
761 if (rand255() >= 250)
763 ship
->rotz
= rand255() | 0x68;
764 if (ship
->rotz
> 127)
765 ship
->rotz
= -(ship
->rotz
& 127);
768 maxeng
= ship_list
[type
]->energy
;
769 energy
= ship
->energy
;
771 if (energy
< (maxeng
/ 2))
773 if ((energy
< (maxeng
/ 8)) && (rand255() > 230) && (type
!= SHIP_THARGOID
))
775 ship
->flags
&= ~FLG_ANGRY
;
776 ship
->flags
|= FLG_INACTIVE
;
777 launch_enemy (un
, SHIP_ESCAPE_CAPSULE
, 0, 126);
781 if ((ship
->missiles
!= 0) && (ecm_active
== 0) &&
782 (ship
->missiles
>= (rand255() & 31)))
785 ship
->flags
|= FLG_TACTICAL
;
786 if (type
== SHIP_THARGOID
)
787 launch_enemy (un
, SHIP_THARGLET
, FLG_ANGRY
, ship
->bravery
);
790 launch_enemy (un
, SHIP_MISSILE
, FLG_ANGRY
, 126);
791 ship
->flags
|= FLG_HOSTILE
;
792 info_message ("INCOMING MISSILE");
798 nvec
= unit_vector(&universe
[un
].location
);
799 direction
= vector_dot_product (&nvec
, &ship
->rotmat
[2]);
801 if ((ship
->distance
< 8192) && (direction
<= -0.833) &&
802 (ship_list
[type
]->laser_strength
!= 0))
804 if (direction
<= -0.917)
805 ship
->flags
|= FLG_FIRING
| FLG_HOSTILE
| FLG_TACTICAL
;
807 if (direction
<= -0.972)
809 damage_ship (ship_list
[type
]->laser_strength
, ship
->location
.z
>= 0.0);
810 ship
->acceleration
--;
811 if (((ship
->location
.z
>= 0.0) && (front_shield
== 0)) ||
812 ((ship
->location
.z
< 0.0) && (aft_shield
== 0)))
813 snd_play_sample (SND_INCOMMING_FIRE_2
);
815 snd_play_sample (SND_INCOMMING_FIRE_1
);
822 direction
= -direction
;
823 track_object (&universe
[un
], direction
, nvec
);
826 // if ((fabs(ship->location.z) < 768) && (ship->bravery <= ((rand255() & 127) | 64)))
827 if (fabs(ship
->location
.z
) < 768)
829 ship
->rotx
= rand255() & 0x87;
830 if (ship
->rotx
> 127)
831 ship
->rotx
= -(ship
->rotx
& 127);
833 ship
->acceleration
= 3;
837 if (ship
->distance
< 8192)
838 ship
->acceleration
= -1;
840 ship
->acceleration
= 3;
846 if ((fabs(ship
->location
.z
) >= 768) ||
847 (fabs(ship
->location
.x
) >= 512) ||
848 (fabs(ship
->location
.y
) >= 512))
850 if (ship
->bravery
> (rand255() & 127))
856 direction
= -direction
;
860 track_object (&universe
[un
], direction
, nvec
);
862 if ((attacking
== 1) && (ship
->distance
< 2048))
864 if (direction
>= cnt2
)
866 ship
->acceleration
= -1;
870 if (ship
->velocity
< 6)
871 ship
->acceleration
= 3;
873 if (rand255() >= 200)
874 ship
->acceleration
= -1;
878 if (direction
<= -0.167)
880 ship
->acceleration
= -1;
884 if (direction
>= cnt2
)
886 ship
->acceleration
= 3;
890 if (ship
->velocity
< 6)
891 ship
->acceleration
= 3;
893 if (rand255() >= 200)
894 ship
->acceleration
= -1;
898 void draw_laser_lines (void)
902 gfx_draw_colour_line (32 * GFX_SCALE
, GFX_VIEW_BY
, laser_x
, laser_y
, GFX_COL_WHITE
);
903 gfx_draw_colour_line (48 * GFX_SCALE
, GFX_VIEW_BY
, laser_x
, laser_y
, GFX_COL_WHITE
);
904 gfx_draw_colour_line (208 * GFX_SCALE
, GFX_VIEW_BY
, laser_x
, laser_y
, GFX_COL_WHITE
);
905 gfx_draw_colour_line (224 * GFX_SCALE
, GFX_VIEW_BY
, laser_x
, laser_y
, GFX_COL_WHITE
);
909 gfx_draw_triangle (32 * GFX_SCALE
, GFX_VIEW_BY
, laser_x
, laser_y
, 48 * GFX_SCALE
, GFX_VIEW_BY
, GFX_COL_RED
);
910 gfx_draw_triangle (208 * GFX_SCALE
, GFX_VIEW_BY
, laser_x
, laser_y
, 224 * GFX_SCALE
, GFX_VIEW_BY
, GFX_COL_RED
);
915 int fire_laser (void)
917 if ((laser_counter
== 0) && (laser_temp
< 242))
919 switch (current_screen
)
922 laser
= cmdr
.front_laser
;
926 laser
= cmdr
.rear_laser
;
930 laser
= cmdr
.right_laser
;
934 laser
= cmdr
.left_laser
;
943 laser_counter
= (laser
> 127) ?
0 : (laser
& 0xFA);
947 snd_play_sample (SND_PULSE
);
952 laser_x
= ((rand() & 3) + 128 - 2) * GFX_SCALE
;
953 laser_y
= ((rand() & 3) + 96 - 2) * GFX_SCALE
;
963 void cool_laser (void)
970 if (laser_counter
> 0)
973 if (laser_counter
> 0)
978 int create_other_ship (int type
)
984 set_init_matrix (rotmat
);
987 x
= 1000 + (randint() & 8191);
988 y
= 1000 + (randint() & 8191);
995 newship
= add_new_ship (type
, x
, y
, z
, rotmat
, 0, 0);
1001 void create_thargoid (void)
1005 newship
= create_other_ship (SHIP_THARGOID
);
1008 universe
[newship
].flags
= FLG_ANGRY
| FLG_HAS_ECM
| FLG_TARGET
;
1009 universe
[newship
].bravery
= 113;
1012 launch_enemy (newship
, SHIP_THARGLET
, FLG_ANGRY
| FLG_HAS_ECM
,
1020 void create_cougar (void)
1024 if (ship_count
[SHIP_COUGAR
] != 0)
1027 newship
= create_other_ship (SHIP_COUGAR
);
1030 universe
[newship
].flags
= FLG_HAS_ECM
; // | FLG_CLOAKED;
1031 universe
[newship
].bravery
= 121;
1032 universe
[newship
].velocity
= 18;
1038 void create_trader (void)
1044 type
= SHIP_COBRA3
+ (rand255() & 3);
1046 newship
= create_other_ship (type
);
1050 universe
[newship
].rotmat
[2].z
= -1.0;
1051 universe
[newship
].rotz
= rand255() & 7;
1054 universe
[newship
].velocity
= (rnd
& 31) | 16;
1055 universe
[newship
].bravery
= rnd
/ 2;
1058 universe
[newship
].flags
|= FLG_HAS_ECM
;
1060 if (rnd
> (type
== SHIP_ANACONDA ?
250 : 220))
1061 universe
[newship
].flags
|= FLG_ANGRY
| FLG_TARGET
;
1066 void create_lone_hunter (void)
1072 if ((cmdr
.mission
== 1) && (cmdr
.galaxy_number
== 1) &&
1073 (docked_planet
.d
== 144) && (docked_planet
.b
== 33) &&
1074 (ship_count
[SHIP_CONSTRICTOR
] == 0))
1076 type
= SHIP_CONSTRICTOR
;
1081 type
= SHIP_COBRA3_LONE
+ (rnd
& 3) + (rnd
> 127);
1084 newship
= create_other_ship (type
);
1088 // universe[newship].flags = FLG_ANGRY;
1089 if ((rand255() > 200) || (type
== SHIP_CONSTRICTOR
))
1090 universe
[newship
].flags
|= FLG_HAS_ECM
;
1092 universe
[newship
].bravery
= ((rand255() * 2) | 64) & 127;
1093 if (type
== SHIP_FER_DE_LANCE
) {
1094 if (rand255() > 160)
1095 universe
[newship
].flags
|= FLG_ANGRY
| FLG_TARGET
;
1097 universe
[newship
].rotmat
[2].z
= -1.0;
1098 universe
[newship
].rotz
= rand255() & 7;
1100 universe
[newship
].velocity
= (rnd
& 31) | 16;
1104 if (universe
[newship
].flags
& FLG_ANGRY
)
1111 /* Check for a random asteroid encounter... */
1113 void check_for_asteroids (void)
1118 if ((rand255() >= 35) || (ship_count
[SHIP_ASTEROID
] >= 3))
1121 if (rand255() > 253)
1124 type
= SHIP_ASTEROID
;
1126 newship
= create_other_ship (type
);
1130 // universe[newship].velocity = (rand255() & 31) | 16;
1131 universe
[newship
].velocity
= 8;
1132 universe
[newship
].rotz
= rand255() > 127 ?
-127 : 127;
1133 universe
[newship
].rotx
= 16;
1139 /* If we've been a bad boy then send the cops after us... */
1141 void check_for_cops (void)
1146 offense
= carrying_contraband() * 2;
1147 if (ship_count
[SHIP_VIPER
] == 0)
1148 offense
|= cmdr
.legal_status
;
1150 if (rand255() >= offense
)
1153 newship
= create_other_ship (SHIP_VIPER
);
1157 universe
[newship
].flags
|= FLG_ANGRY
| FLG_TARGET
;
1158 if (rand255() > 245)
1159 universe
[newship
].flags
|= FLG_HAS_ECM
;
1161 universe
[newship
].bravery
= ((rand255() * 2) | 64) & 127;
1166 void check_for_others (void)
1176 gov
= current_planet_data
.government
;
1179 if ((gov
!= 0) && ((rnd
>= 90) || ((rnd
& 7) < gov
)))
1182 if (rand255() < 100)
1184 create_lone_hunter();
1188 /* Pack hunters... */
1190 set_init_matrix (rotmat
);
1193 x
= 1000 + (randint() & 8191);
1194 y
= 1000 + (randint() & 8191);
1196 if (rand255() > 127)
1198 if (rand255() > 127)
1201 rnd
= rand255() & 3;
1203 for (i
= 0; i
<= rnd
; i
++)
1205 type
= SHIP_SIDEWINDER
+ (rand255() & rand255() & 7);
1206 newship
= add_new_ship (type
, x
, y
, z
, rotmat
, 0, 0);
1209 universe
[newship
].flags
|= FLG_ANGRY
| FLG_TARGET
;
1210 if (rand255() > 245)
1211 universe
[newship
].flags
|= FLG_HAS_ECM
;
1213 universe
[newship
].bravery
= ((rand255() * 2) | 64) & 127;
1221 void random_encounter (void)
1223 if ((ship_count
[SHIP_CORIOLIS
] != 0) || (ship_count
[SHIP_DODEC
] != 0))
1226 if (rand255() == 136)
1228 if (((int)(universe
[0].location
.z
) & 0x3e) != 0)
1236 if ((rand255() & 7) == 0)
1242 check_for_asteroids();
1246 if (ship_count
[SHIP_VIPER
] != 0)
1252 if ((cmdr
.mission
== 5) && (rand255() >= 200))
1259 void abandon_ship (void)
1263 cmdr
.escape_pod
= 0;
1264 cmdr
.legal_status
= 0;
1265 cmdr
.fuel
= myship
.max_fuel
;
1267 for (i
= 0; i
< NO_OF_STOCK_ITEMS
; i
++)
1268 cmdr
.current_cargo
[i
] = 0;
1270 snd_play_sample (SND_DOCK
);
1272 current_screen
= SCR_BREAK_PATTERN
;