2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
55 #include "gr.h" // for powerup outline drawing
56 #include "editor/editor.h"
59 int N_powerup_types = 0;
60 powerup_type_info Powerup_info[MAX_POWERUP_TYPES];
62 //process this powerup for this frame
63 void do_powerup_frame(object *obj)
66 vclip_info *vci = &obj->rtype.vclip_info;
67 vclip *vc = &Vclip[vci->vclip_num];
69 fudge = (FrameTime * ((obj-Objects)&3)) >> 4;
71 vci->frametime -= FrameTime+fudge;
73 while (vci->frametime < 0 ) {
75 vci->frametime += vc->frame_time;
82 if (vci->framenum >= vc->num_frames)
85 if (vci->framenum < 0)
86 vci->framenum = vc->num_frames-1;
89 if (obj->lifeleft <= 0) {
90 object_create_explosion(obj->segnum, &obj->pos, F1_0*7/2, VCLIP_POWERUP_DISAPPEARANCE );
92 if ( Vclip[VCLIP_POWERUP_DISAPPEARANCE].sound_num > -1 )
93 digi_link_sound_to_object( Vclip[VCLIP_POWERUP_DISAPPEARANCE].sound_num, obj-Objects, 0, F1_0);
98 extern fix blob_vertices[];
100 // blob_vertices has 3 vertices in it, 4th must be computed
101 void draw_blob_outline(void)
105 v3x = blob_vertices[4] - blob_vertices[2] + blob_vertices[0];
106 v3y = blob_vertices[5] - blob_vertices[3] + blob_vertices[1];
108 gr_setcolor(BM_XRGB(63, 63, 63));
110 mprintf((0, "[%7.3f %7.3f] [%7.3f %7.3f] [%7.3f %7.3f]\n", f2fl(blob_vertices[0]), f2fl(blob_vertices[1]), f2fl(blob_vertices[2]), f2fl(blob_vertices[3]), f2fl(blob_vertices[4]), f2fl(blob_vertices[5]) ));
112 gr_line(blob_vertices[0], blob_vertices[1], blob_vertices[2], blob_vertices[3]);
113 gr_line(blob_vertices[2], blob_vertices[3], blob_vertices[4], blob_vertices[5]);
114 gr_line(blob_vertices[4], blob_vertices[5], v3x, v3y);
116 gr_line(v3x, v3y, blob_vertices[0], blob_vertices[1]);
120 void draw_powerup(object *obj)
123 blob_vertices[0] = 0x80000;
126 draw_object_blob(obj, Vclip[obj->rtype.vclip_info.vclip_num].frames[obj->rtype.vclip_info.framenum] );
129 if ((Function_mode == FMODE_EDITOR) && (Cur_object_index == obj-Objects))
130 if (blob_vertices[0] != 0x80000)
136 //void mprintf_powerup_info(void)
139 //mprintf((0, "Powerup: %s\n", text));
140 //for (i=0; i<5; i++) {
141 // char has_text[12];
143 // if (Players[Player_num].primary_weapon_flags & (1 << i))
144 // strcpy(has_text,"PRESENT");
146 // strcpy(has_text,"NOPE ");
149 // mprintf((0, "Weapon %i = %s, ammo = %6i, name = %s\n", i, has_text, Players[Player_num].primary_ammo[i], Primary_weapon_names[i]));
152 //for (i=0; i<5; i++) {
153 // char has_text[12];
155 // if (Players[Player_num].secondary_weapon_flags & (1 << i))
156 // strcpy(has_text,"PRESENT");
158 // strcpy(has_text,"NOPE ");
160 // mprintf((0, "Weapon %i = %s, ammo = %6i, name = %s\n", i, has_text, Players[Player_num].secondary_ammo[i], Secondary_weapon_names[i]));
164 void powerup_basic(int redadd, int greenadd, int blueadd, int score, char *format, ...)
169 va_start(args, format );
170 vsprintf(text, format, args);
173 PALETTE_FLASH_ADD(redadd,greenadd,blueadd);
175 HUD_init_message(text);
177 //mprintf_powerup_info();
179 add_points_to_score(score);
184 // Give the megawow powerup!
185 void do_megawow_powerup(int quantity)
189 powerup_basic(30, 0, 30, 1, "MEGA-WOWIE-ZOWIE!");
190 Players[Player_num].primary_weapon_flags = 0xffff ^ HAS_FLAG(SUPER_LASER_INDEX); //no super laser
191 Players[Player_num].secondary_weapon_flags = 0xffff;
193 for (i=0; i<MAX_PRIMARY_WEAPONS; i++)
194 Players[Player_num].primary_ammo[i] = VULCAN_AMMO_MAX;
197 Players[Player_num].secondary_ammo[i] = quantity;
199 for (i=3; i<MAX_SECONDARY_WEAPONS; i++)
200 Players[Player_num].secondary_ammo[i] = quantity/5;
202 if (Newdemo_state == ND_STATE_RECORDING)
203 newdemo_record_laser_level(Players[Player_num].laser_level, MAX_LASER_LEVEL);
205 Players[Player_num].energy = F1_0*200;
206 Players[Player_num].shields = F1_0*200;
207 Players[Player_num].flags |= PLAYER_FLAGS_QUAD_LASERS;
208 Players[Player_num].laser_level = MAX_SUPER_LASER_LEVEL;
210 if (Game_mode & GM_HOARD)
211 Players[Player_num].secondary_ammo[PROXIMITY_INDEX] = 12;
214 update_laser_weapon_info();
219 int pick_up_energy(void)
223 if (Players[Player_num].energy < MAX_ENERGY) {
225 boost = 3*F1_0 + 3*F1_0*(NDL - Difficulty_level);
226 if (Difficulty_level == 0)
228 Players[Player_num].energy += boost;
229 if (Players[Player_num].energy > MAX_ENERGY)
230 Players[Player_num].energy = MAX_ENERGY;
231 powerup_basic(15,15,7, ENERGY_SCORE, "%s %s %d",TXT_ENERGY,TXT_BOOSTED_TO,f2ir(Players[Player_num].energy));
234 HUD_init_message(TXT_MAXED_OUT,TXT_ENERGY);
239 int pick_up_vulcan_ammo(void)
243 int pwsave = Primary_weapon; // Ugh, save selected primary weapon around the picking up of the ammo. I apologize for this code. Matthew A. Toschlog
244 if (pick_up_ammo(CLASS_PRIMARY, VULCAN_INDEX, VULCAN_AMMO_AMOUNT)) {
245 powerup_basic(7, 14, 21, VULCAN_AMMO_SCORE, "%s!", TXT_VULCAN_AMMO);
248 max = Primary_ammo_max[VULCAN_INDEX];
249 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK)
251 HUD_init_message("%s %d %s!",TXT_ALREADY_HAVE,f2i((unsigned) VULCAN_AMMO_SCALE * (unsigned) max),TXT_VULCAN_ROUNDS);
254 Primary_weapon = pwsave;
259 extern void invalidate_escort_goal(void);
260 extern char GetKeyValue(char);
261 extern void check_to_use_primary(int);
262 extern void multi_send_got_flag (char);
264 int Headlight_active_default=1; //is headlight on when picked up?
265 extern int PlayerMessage;
267 // returns true if powerup consumed
268 int do_powerup(object *obj)
271 int special_used=0; //for when hitting vulcan cannon gets vulcan ammo
272 char temp_string[50];
275 if ((Player_is_dead) || (ConsoleObject->type == OBJ_GHOST) || (Players[Player_num].shields < 0))
278 if (obj->ctype.powerup_info.creation_time > GameTime) //gametime wrapped!
279 obj->ctype.powerup_info.creation_time = 0; //allow player to pick up
281 if ((obj->ctype.powerup_info.flags & PF_SPAT_BY_PLAYER) && obj->ctype.powerup_info.creation_time>0 && GameTime<obj->ctype.powerup_info.creation_time+i2f(2))
282 return 0; //not enough time elapsed
284 PlayerMessage=0; // Prevent messages from going to HUD if -PlayerMessages switch is set
288 Players[Player_num].lives++;
289 powerup_basic(15, 15, 15, 0, TXT_EXTRA_LIFE);
293 used = pick_up_energy();
295 case POW_SHIELD_BOOST:
296 if (Players[Player_num].shields < MAX_SHIELDS) {
297 fix boost = 3*F1_0 + 3*F1_0*(NDL - Difficulty_level);
298 if (Difficulty_level == 0)
300 Players[Player_num].shields += boost;
301 if (Players[Player_num].shields > MAX_SHIELDS)
302 Players[Player_num].shields = MAX_SHIELDS;
303 powerup_basic(0, 0, 15, SHIELD_SCORE, "%s %s %d",TXT_SHIELD,TXT_BOOSTED_TO,f2ir(Players[Player_num].shields));
306 HUD_init_message(TXT_MAXED_OUT,TXT_SHIELD);
309 if (Players[Player_num].laser_level >= MAX_LASER_LEVEL) {
310 //Players[Player_num].laser_level = MAX_LASER_LEVEL;
311 HUD_init_message(TXT_MAXED_OUT,TXT_LASER);
313 if (Newdemo_state == ND_STATE_RECORDING)
314 newdemo_record_laser_level(Players[Player_num].laser_level, Players[Player_num].laser_level + 1);
315 Players[Player_num].laser_level++;
316 powerup_basic(10, 0, 10, LASER_SCORE, "%s %s %d",TXT_LASER,TXT_BOOSTED_TO, Players[Player_num].laser_level+1);
317 update_laser_weapon_info();
318 pick_up_primary (LASER_INDEX);
321 if (!used && !(Game_mode & GM_MULTI) )
322 used = pick_up_energy();
325 used=pick_up_secondary(CONCUSSION_INDEX,1);
328 used=pick_up_secondary(CONCUSSION_INDEX,4);
332 if (Players[Player_num].flags & PLAYER_FLAGS_BLUE_KEY)
335 multi_send_play_sound(Powerup_info[obj->id].hit_sound, F1_0);
337 digi_play_sample( Powerup_info[obj->id].hit_sound, F1_0 );
338 Players[Player_num].flags |= PLAYER_FLAGS_BLUE_KEY;
339 powerup_basic(0, 0, 15, KEY_SCORE, "%s %s",TXT_BLUE,TXT_ACCESS_GRANTED);
340 if (Game_mode & GM_MULTI)
344 invalidate_escort_goal();
347 if (Players[Player_num].flags & PLAYER_FLAGS_RED_KEY)
350 multi_send_play_sound(Powerup_info[obj->id].hit_sound, F1_0);
352 digi_play_sample( Powerup_info[obj->id].hit_sound, F1_0 );
353 Players[Player_num].flags |= PLAYER_FLAGS_RED_KEY;
354 powerup_basic(15, 0, 0, KEY_SCORE, "%s %s",TXT_RED,TXT_ACCESS_GRANTED);
355 if (Game_mode & GM_MULTI)
359 invalidate_escort_goal();
362 if (Players[Player_num].flags & PLAYER_FLAGS_GOLD_KEY)
365 multi_send_play_sound(Powerup_info[obj->id].hit_sound, F1_0);
367 digi_play_sample( Powerup_info[obj->id].hit_sound, F1_0 );
368 Players[Player_num].flags |= PLAYER_FLAGS_GOLD_KEY;
369 powerup_basic(15, 15, 7, KEY_SCORE, "%s %s",TXT_YELLOW,TXT_ACCESS_GRANTED);
370 if (Game_mode & GM_MULTI)
374 invalidate_escort_goal();
377 if (!(Players[Player_num].flags & PLAYER_FLAGS_QUAD_LASERS)) {
378 Players[Player_num].flags |= PLAYER_FLAGS_QUAD_LASERS;
379 powerup_basic(15, 15, 7, QUAD_FIRE_SCORE, "%s!",TXT_QUAD_LASERS);
380 update_laser_weapon_info();
383 HUD_init_message("%s %s!",TXT_ALREADY_HAVE,TXT_QUAD_LASERS);
384 if (!used && !(Game_mode & GM_MULTI) )
385 used = pick_up_energy();
388 case POW_VULCAN_WEAPON:
389 case POW_GAUSS_WEAPON: {
390 int ammo = obj->ctype.powerup_info.count;
392 used = pick_up_primary((obj->id==POW_VULCAN_WEAPON)?VULCAN_INDEX:GAUSS_INDEX);
394 //didn't get the weapon (because we already have it), but
395 //maybe snag some of the ammo. if single-player, grab all the ammo
396 //and remove the powerup. If multi-player take ammo in excess of
397 //the amount in a powerup, and leave the rest.
399 if ((Game_mode & GM_MULTI) )
400 ammo -= VULCAN_AMMO_AMOUNT; //don't let take all ammo
404 ammo_used = pick_up_ammo(CLASS_PRIMARY, VULCAN_INDEX, ammo);
405 obj->ctype.powerup_info.count -= ammo_used;
406 if (!used && ammo_used) {
407 powerup_basic(7, 14, 21, VULCAN_AMMO_SCORE, "%s!", TXT_VULCAN_AMMO);
409 id = POW_VULCAN_AMMO; //set new id for making sound at end of this function
410 if (obj->ctype.powerup_info.count == 0)
411 used = 1; //say used if all ammo taken
418 case POW_SPREADFIRE_WEAPON:
419 used = pick_up_primary(SPREADFIRE_INDEX);
420 if (!used && !(Game_mode & GM_MULTI) )
421 used = pick_up_energy();
423 case POW_PLASMA_WEAPON:
424 used = pick_up_primary(PLASMA_INDEX);
425 if (!used && !(Game_mode & GM_MULTI) )
426 used = pick_up_energy();
428 case POW_FUSION_WEAPON:
429 used = pick_up_primary(FUSION_INDEX);
430 if (!used && !(Game_mode & GM_MULTI) )
431 used = pick_up_energy();
434 case POW_HELIX_WEAPON:
435 used = pick_up_primary(HELIX_INDEX);
436 if (!used && !(Game_mode & GM_MULTI) )
437 used = pick_up_energy();
440 case POW_PHOENIX_WEAPON:
441 used = pick_up_primary(PHOENIX_INDEX);
442 if (!used && !(Game_mode & GM_MULTI) )
443 used = pick_up_energy();
446 case POW_OMEGA_WEAPON:
447 used = pick_up_primary(OMEGA_INDEX);
449 Omega_charge = obj->ctype.powerup_info.count;
450 if (!used && !(Game_mode & GM_MULTI) )
451 used = pick_up_energy();
454 case POW_PROXIMITY_WEAPON:
455 used=pick_up_secondary(PROXIMITY_INDEX,4);
457 case POW_SMARTBOMB_WEAPON:
458 used=pick_up_secondary(SMART_INDEX,1);
460 case POW_MEGA_WEAPON:
461 used=pick_up_secondary(MEGA_INDEX,1);
463 case POW_SMISSILE1_1:
464 used=pick_up_secondary(SMISSILE1_INDEX,1);
466 case POW_SMISSILE1_4:
467 used=pick_up_secondary(SMISSILE1_INDEX,4);
469 case POW_GUIDED_MISSILE_1:
470 used=pick_up_secondary(GUIDED_INDEX,1);
472 case POW_GUIDED_MISSILE_4:
473 used=pick_up_secondary(GUIDED_INDEX,4);
476 used=pick_up_secondary(SMART_MINE_INDEX,4);
478 case POW_MERCURY_MISSILE_1:
479 used=pick_up_secondary(SMISSILE4_INDEX,1);
481 case POW_MERCURY_MISSILE_4:
482 used=pick_up_secondary(SMISSILE4_INDEX,4);
484 case POW_EARTHSHAKER_MISSILE:
485 used=pick_up_secondary(SMISSILE5_INDEX,1);
487 case POW_VULCAN_AMMO:
488 used = pick_up_vulcan_ammo();
490 case POW_HOMING_AMMO_1:
491 used=pick_up_secondary(HOMING_INDEX,1);
493 case POW_HOMING_AMMO_4:
494 used=pick_up_secondary(HOMING_INDEX,4);
497 if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED) {
498 HUD_init_message("%s %s!",TXT_ALREADY_ARE,TXT_CLOAKED);
501 Players[Player_num].cloak_time = GameTime; // Not! changed by awareness events (like player fires laser).
502 Players[Player_num].flags |= PLAYER_FLAGS_CLOAKED;
505 if (Game_mode & GM_MULTI)
508 powerup_basic(-10,-10,-10, CLOAK_SCORE, "%s!",TXT_CLOAKING_DEVICE);
512 case POW_INVULNERABILITY:
513 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
514 HUD_init_message("%s %s!",TXT_ALREADY_ARE,TXT_INVULNERABLE);
517 Players[Player_num].invulnerable_time = GameTime;
518 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
519 powerup_basic(7, 14, 21, INVULNERABILITY_SCORE, "%s!",TXT_INVULNERABILITY);
525 do_megawow_powerup(50);
531 if (Players[Player_num].flags & PLAYER_FLAGS_MAP_ALL) {
532 HUD_init_message("%s %s!",TXT_ALREADY_HAVE,"the FULL MAP");
533 if (!(Game_mode & GM_MULTI) )
534 used = pick_up_energy();
536 Players[Player_num].flags |= PLAYER_FLAGS_MAP_ALL;
537 powerup_basic(15, 0, 15, 0, "FULL MAP!");
543 if (Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) {
544 HUD_init_message("%s %s!",TXT_ALREADY_HAVE,"the Converter");
545 if (!(Game_mode & GM_MULTI) )
546 used = pick_up_energy();
548 Players[Player_num].flags |= PLAYER_FLAGS_CONVERTER;
549 // DPH: anyone know what the hell this is supposed to do? it's always true =)
550 /* if ((GetKeyValue(54))<255)
552 sprintf (temp_string,"Energy->Shield converter! (Press %c to use)",key_to_ascii(GetKeyValue(54)));
553 powerup_basic(15, 0, 15, 0, temp_string);
556 powerup_basic(15, 0, 15, 0, "Energy -> shield converter!"); */
563 case POW_SUPER_LASER:
564 if (Players[Player_num].laser_level >= MAX_SUPER_LASER_LEVEL) {
565 Players[Player_num].laser_level = MAX_SUPER_LASER_LEVEL;
566 HUD_init_message("SUPER LASER MAXED OUT!");
568 int old_level=Players[Player_num].laser_level;
570 if (Players[Player_num].laser_level <= MAX_LASER_LEVEL)
571 Players[Player_num].laser_level = MAX_LASER_LEVEL;
572 Players[Player_num].laser_level++;
573 if (Newdemo_state == ND_STATE_RECORDING)
574 newdemo_record_laser_level(old_level, Players[Player_num].laser_level);
575 powerup_basic(10, 0, 10, LASER_SCORE, "Super Boost to Laser level %d",Players[Player_num].laser_level+1);
576 update_laser_weapon_info();
577 if (Primary_weapon!=LASER_INDEX)
578 check_to_use_primary (SUPER_LASER_INDEX);
581 if (!used && !(Game_mode & GM_MULTI) )
582 used = pick_up_energy();
586 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK) {
587 HUD_init_message("%s %s!",TXT_ALREADY_HAVE,"the Ammo rack");
588 if (!(Game_mode & GM_MULTI) )
589 used = pick_up_energy();
592 Players[Player_num].flags |= PLAYER_FLAGS_AMMO_RACK;
594 multi_send_play_sound(Powerup_info[obj->id].hit_sound, F1_0);
596 digi_play_sample( Powerup_info[obj->id].hit_sound, F1_0 );
597 powerup_basic(15, 0, 15, 0, "AMMO RACK!");
602 case POW_AFTERBURNER:
603 if (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER) {
604 HUD_init_message("%s %s!",TXT_ALREADY_HAVE,"the Afterburner");
605 if (!(Game_mode & GM_MULTI) )
606 used = pick_up_energy();
609 Players[Player_num].flags |= PLAYER_FLAGS_AFTERBURNER;
611 multi_send_play_sound(Powerup_info[obj->id].hit_sound, F1_0);
613 digi_play_sample( Powerup_info[obj->id].hit_sound, F1_0 );
614 powerup_basic(15, 15, 15, 0, "AFTERBURNER!");
615 Afterburner_charge = f1_0;
621 if (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) {
622 HUD_init_message("%s %s!",TXT_ALREADY_HAVE,"the Headlight boost");
623 if (!(Game_mode & GM_MULTI) )
624 used = pick_up_energy();
628 Players[Player_num].flags |= PLAYER_FLAGS_HEADLIGHT;
630 multi_send_play_sound(Powerup_info[obj->id].hit_sound, F1_0);
632 digi_play_sample( Powerup_info[obj->id].hit_sound, F1_0 );
633 sprintf(msg,"HEADLIGHT BOOST! (Headlight is %s)",Headlight_active_default?"ON":"OFF");
634 powerup_basic(15, 0, 15, 0, msg );
635 if (Headlight_active_default)
636 Players[Player_num].flags |= PLAYER_FLAGS_HEADLIGHT_ON;
639 if (Game_mode & GM_MULTI)
640 multi_send_flags (Player_num);
647 if (Game_mode & GM_CAPTURE)
648 if (get_team(Player_num) == TEAM_RED) {
649 powerup_basic(15, 0, 15, 0, "BLUE FLAG!");
650 Players[Player_num].flags |= PLAYER_FLAGS_FLAG;
652 multi_send_got_flag (Player_num);
657 if (Game_mode & GM_HOARD)
658 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX]<12) {
659 powerup_basic(15, 0, 15, 0, "Orb!!!");
660 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]++;
661 Players[Player_num].flags |= PLAYER_FLAGS_FLAG;
663 multi_send_got_orb (Player_num);
668 if (Game_mode & GM_CAPTURE)
669 if (get_team(Player_num) == TEAM_BLUE) {
670 powerup_basic(15, 0, 15, 0, "RED FLAG!");
671 Players[Player_num].flags |= PLAYER_FLAGS_FLAG;
673 multi_send_got_flag (Player_num);
678 // case POW_HOARD_ORB:
685 //always say used, until physics problem (getting stuck on unused powerup)
686 //is solved. Note also the break statements above that are commented out
689 if ((used || special_used) && Powerup_info[id].hit_sound > -1 ) {
691 if (Game_mode & GM_MULTI) // Added by Rob, take this out if it turns out to be not good for net games!
692 multi_send_play_sound(Powerup_info[id].hit_sound, F1_0);
694 digi_play_sample( Powerup_info[id].hit_sound, F1_0 );
695 detect_escort_goal_accomplished(obj-Objects);
706 * reads n powerup_type_info structs from a CFILE
708 extern int powerup_type_info_read_n(powerup_type_info *pti, int n, CFILE *fp)
712 for (i = 0; i < n; i++) {
713 pti[i].vclip_num = cfile_read_int(fp);
714 pti[i].hit_sound = cfile_read_int(fp);
715 pti[i].size = cfile_read_fix(fp);
716 pti[i].light = cfile_read_fix(fp);