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.
19 static char rcsid[] = "$Id: fuelcen.c,v 1.3 2001-10-25 02:15:56 bradleyb Exp $";
29 #include "game.h" // For FrameTime
56 // The max number of fuel stations per mine.
58 fix Fuelcen_refill_speed = i2f(1);
59 fix Fuelcen_give_amount = i2f(25);
60 fix Fuelcen_max_amount = i2f(100);
62 // Every time a robot is created in the morphing code, it decreases capacity of the morpher
63 // by this amount... when capacity gets to 0, no more morphers...
64 fix EnergyToCreateOneRobot = i2f(1);
66 #define MATCEN_HP_DEFAULT F1_0*500; // Hitpoints
67 #define MATCEN_INTERVAL_DEFAULT F1_0*5; // 5 seconds
69 matcen_info RobotCenters[MAX_ROBOT_CENTERS];
70 int Num_robot_centers;
72 FuelCenter Station[MAX_NUM_FUELCENS];
73 int Num_fuelcenters = 0;
75 segment * PlayerSegment= NULL;
78 char Special_names[MAX_CENTER_TYPES][11] = {
89 //------------------------------------------------------------
90 // Resets all fuel center info
96 //mprintf( (0, "All fuel centers reset.\n"));
98 for(i=0; i<MAX_SEGMENTS; i++ )
99 Segment2s[i].special = SEGMENT_IS_NOTHING;
101 Num_robot_centers = 0;
105 #ifndef NDEBUG //this is sometimes called by people from the debugger
106 void reset_all_robot_centers()
110 // Remove all materialization centers
111 for (i=0; i<Num_segments; i++)
112 if (Segment2s[i].special == SEGMENT_IS_ROBOTMAKER) {
113 Segment2s[i].special = SEGMENT_IS_NOTHING;
114 Segment2s[i].matcen_num = -1;
119 //------------------------------------------------------------
120 // Turns a segment into a fully charged up fuel center...
121 void fuelcen_create( segment *segp)
123 segment2 *seg2p = &Segment2s[segp-Segments];
127 station_type = seg2p->special;
129 switch( station_type ) {
130 case SEGMENT_IS_NOTHING:
131 case SEGMENT_IS_GOAL_BLUE:
132 case SEGMENT_IS_GOAL_RED:
134 case SEGMENT_IS_FUELCEN:
135 case SEGMENT_IS_REPAIRCEN:
136 case SEGMENT_IS_CONTROLCEN:
137 case SEGMENT_IS_ROBOTMAKER:
140 Error( "Invalid station type %d in fuelcen.c\n", station_type );
143 Assert( (seg2p != NULL) );
144 if ( seg2p == NULL ) return;
146 Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
147 Assert( Num_fuelcenters > -1 );
149 seg2p->value = Num_fuelcenters;
150 Station[Num_fuelcenters].Type = station_type;
151 Station[Num_fuelcenters].MaxCapacity = Fuelcen_max_amount;
152 Station[Num_fuelcenters].Capacity = Station[Num_fuelcenters].MaxCapacity;
153 Station[Num_fuelcenters].segnum = seg2p-Segment2s;
154 Station[Num_fuelcenters].Timer = -1;
155 Station[Num_fuelcenters].Flag = 0;
156 // Station[Num_fuelcenters].NextRobotType = -1;
157 // Station[Num_fuelcenters].last_created_obj=NULL;
158 // Station[Num_fuelcenters].last_created_sig = -1;
159 compute_segment_center(&Station[Num_fuelcenters].Center, segp);
161 // if (station_type == SEGMENT_IS_ROBOTMAKER)
162 // Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
164 //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
168 //------------------------------------------------------------
169 // Adds a matcen that already is a special type into the Station array.
170 // This function is separate from other fuelcens because we don't want values reset.
171 void matcen_create( segment *segp)
173 segment2 *seg2p = &Segment2s[segp-Segments];
175 int station_type = seg2p->special;
177 Assert( (seg2p != NULL) );
178 Assert(station_type == SEGMENT_IS_ROBOTMAKER);
179 if ( seg2p == NULL ) return;
181 Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
182 Assert( Num_fuelcenters > -1 );
184 seg2p->value = Num_fuelcenters;
185 Station[Num_fuelcenters].Type = station_type;
186 Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
187 Station[Num_fuelcenters].MaxCapacity = Station[Num_fuelcenters].Capacity;
189 Station[Num_fuelcenters].segnum = seg2p-Segment2s;
190 Station[Num_fuelcenters].Timer = -1;
191 Station[Num_fuelcenters].Flag = 0;
192 // Station[Num_fuelcenters].NextRobotType = -1;
193 // Station[Num_fuelcenters].last_created_obj=NULL;
194 // Station[Num_fuelcenters].last_created_sig = -1;
195 compute_segment_center(&Station[Num_fuelcenters].Center, &Segments[seg2p-Segment2s] );
197 seg2p->matcen_num = Num_robot_centers;
200 RobotCenters[seg2p->matcen_num].hit_points = MATCEN_HP_DEFAULT;
201 RobotCenters[seg2p->matcen_num].interval = MATCEN_INTERVAL_DEFAULT;
202 RobotCenters[seg2p->matcen_num].segnum = seg2p-Segment2s;
203 RobotCenters[seg2p->matcen_num].fuelcen_num = Num_fuelcenters;
205 //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
209 //------------------------------------------------------------
210 // Adds a segment that already is a special type into the Station array.
211 void fuelcen_activate( segment * segp, int station_type )
213 segment2 *seg2p = &Segment2s[segp-Segments];
215 seg2p->special = station_type;
217 if (seg2p->special == SEGMENT_IS_ROBOTMAKER)
218 matcen_create( segp);
220 fuelcen_create( segp);
224 // The lower this number is, the more quickly the center can be re-triggered.
225 // If it's too low, it can mean all the robots won't be put out, but for about 5
226 // robots, that's not real likely.
227 #define MATCEN_LIFE (i2f(30-2*Difficulty_level))
229 //------------------------------------------------------------
230 // Trigger (enable) the materialization center in segment segnum
231 void trigger_matcen(int segnum)
233 // -- segment *segp = &Segments[segnum];
234 segment2 *seg2p = &Segment2s[segnum];
235 vms_vector pos, delta;
236 FuelCenter *robotcen;
239 mprintf((0, "Trigger matcen, segment %i\n", segnum));
241 Assert(seg2p->special == SEGMENT_IS_ROBOTMAKER);
242 Assert(seg2p->matcen_num < Num_fuelcenters);
243 Assert((seg2p->matcen_num >= 0) && (seg2p->matcen_num <= Highest_segment_index));
245 robotcen = &Station[RobotCenters[seg2p->matcen_num].fuelcen_num];
247 if (robotcen->Enabled == 1)
250 if (!robotcen->Lives)
253 // MK: 11/18/95, At insane, matcens work forever!
254 if (Difficulty_level+1 < NDL)
257 robotcen->Timer = F1_0*1000; // Make sure the first robot gets emitted right away.
258 robotcen->Enabled = 1; // Say this center is enabled, it can create robots.
259 robotcen->Capacity = i2f(Difficulty_level + 3);
260 robotcen->Disable_time = MATCEN_LIFE;
262 // Create a bright object in the segment.
263 pos = robotcen->Center;
264 vm_vec_sub(&delta, &Vertices[Segments[segnum].verts[0]], &robotcen->Center);
265 vm_vec_scale_add2(&pos, &delta, F1_0/2);
266 objnum = obj_create( OBJ_LIGHT, 0, segnum, &pos, NULL, 0, CT_LIGHT, MT_NONE, RT_NONE );
268 Objects[objnum].lifeleft = MATCEN_LIFE;
269 Objects[objnum].ctype.light_info.intensity = i2f(8); // Light cast by a fuelcen.
271 mprintf((1, "Can't create invisible flare for matcen.\n"));
274 // mprintf((0, "Created invisibile flare, object=%i, segment=%i, pos=%7.3f %7.3f%7.3f\n", objnum, segnum, f2fl(pos.x), f2fl(pos.y), f2fl(pos.z)));
278 //------------------------------------------------------------
279 // Takes away a segment's fuel center properties.
280 // Deletes the segment point entry in the FuelCenter list.
281 void fuelcen_delete( segment * segp )
283 segment2 *seg2p = &Segment2s[segp-Segments];
290 for (i=0; i<Num_fuelcenters; i++ ) {
291 if ( Station[i].segnum == segp-Segments ) {
293 // If Robot maker is deleted, fix Segments and RobotCenters.
294 if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
296 Assert(Num_robot_centers >= 0);
298 for (j=seg2p->matcen_num; j<Num_robot_centers; j++)
299 RobotCenters[j] = RobotCenters[j+1];
301 for (j=0; j<Num_fuelcenters; j++) {
302 if ( Station[j].Type == SEGMENT_IS_ROBOTMAKER )
303 if ( Segment2s[Station[j].segnum].matcen_num > seg2p->matcen_num )
304 Segment2s[Station[j].segnum].matcen_num--;
308 //fix RobotCenters so they point to correct fuelcenter
309 for (j=0; j<Num_robot_centers; j++ )
310 if (RobotCenters[j].fuelcen_num > i) //this robotcenter's fuelcen is changing
311 RobotCenters[j].fuelcen_num--;
314 Assert(Num_fuelcenters >= 0);
315 for (j=i; j<Num_fuelcenters; j++ ) {
316 Station[j] = Station[j+1];
317 Segment2s[Station[j].segnum].value = j;
326 #define ROBOT_GEN_TIME (i2f(5))
328 object * create_morph_robot( segment *segp, vms_vector *object_pos, int object_id)
332 int default_behavior;
334 Players[Player_num].num_robots_level++;
335 Players[Player_num].num_robots_total++;
337 objnum = obj_create(OBJ_ROBOT, object_id, segp-Segments, object_pos,
338 &vmd_identity_matrix, Polygon_models[Robot_info[object_id].model_num].rad,
339 CT_AI, MT_PHYSICS, RT_POLYOBJ);
342 mprintf((1, "Can't create morph robot. Aborting morph.\n"));
347 obj = &Objects[objnum];
349 //Set polygon-object-specific data
351 obj->rtype.pobj_info.model_num = Robot_info[obj->id].model_num;
352 obj->rtype.pobj_info.subobj_flags = 0;
356 obj->mtype.phys_info.mass = Robot_info[obj->id].mass;
357 obj->mtype.phys_info.drag = Robot_info[obj->id].drag;
359 obj->mtype.phys_info.flags |= (PF_LEVELLING);
361 obj->shields = Robot_info[obj->id].strength;
363 default_behavior = Robot_info[obj->id].behavior;
365 init_ai_object(obj-Objects, default_behavior, -1 ); // Note, -1 = segment this robot goes to to hide, should probably be something useful
367 create_n_segment_path(obj, 6, -1); // Create a 6 segment path from creation point.
369 Ai_local_info[objnum].mode = ai_behavior_to_mode(default_behavior);
374 int Num_extry_robots = 15;
377 int FrameCount_last_msg = 0;
380 // ----------------------------------------------------------------------------------------------------------
381 void robotmaker_proc( FuelCenter * robotcen )
384 vms_vector cur_object_loc; //, direction;
385 int matcen_num, segnum, objnum;
388 vms_vector direction;
390 if (robotcen->Enabled == 0)
393 if (robotcen->Disable_time > 0) {
394 robotcen->Disable_time -= FrameTime;
395 if (robotcen->Disable_time <= 0) {
396 mprintf((0, "Robot center #%i gets disabled due to time running out.\n", robotcen-Station));
397 robotcen->Enabled = 0;
401 // mprintf((0, "Capacity of robot maker #%i is %i\n", robotcen - Station, robotcen->Capacity));
403 // No robot making in multiplayer mode.
406 if ((Game_mode & GM_MULTI) && (!(Game_mode & GM_MULTI_ROBOTS) || !network_i_am_master()))
409 if (Game_mode & GM_MULTI)
414 // Wait until transmorgafier has capacity to make a robot...
415 if ( robotcen->Capacity <= 0 ) {
419 matcen_num = Segment2s[robotcen->segnum].matcen_num;
420 //mprintf((0, "Robotmaker #%i flags = %8x\n", matcen_num, RobotCenters[matcen_num].robot_flags));
422 if ( matcen_num == -1 ) {
423 mprintf((0, "Non-functional robotcen at %d\n", robotcen->segnum));
427 if (RobotCenters[matcen_num].robot_flags[0]==0 && RobotCenters[matcen_num].robot_flags[1]==0) {
428 //mprintf((0, "robot_flags = 0 at robot maker #%i\n", RobotCenters[matcen_num].robot_flags));
432 // Wait until we have a free slot for this puppy...
433 // <<<<<<<<<<<<<<<< Num robots in mine >>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<< Max robots in mine >>>>>>>>>>>>>>>
434 if ( (Players[Player_num].num_robots_level - Players[Player_num].num_kills_level) >= (Gamesave_num_org_robots + Num_extry_robots ) ) {
436 if (FrameCount > FrameCount_last_msg + 20) {
437 mprintf((0, "Cannot morph until you kill one!\n"));
438 FrameCount_last_msg = FrameCount;
444 robotcen->Timer += FrameTime;
446 switch( robotcen->Flag ) {
447 case 0: // Wait until next robot can generate
448 if (Game_mode & GM_MULTI)
450 top_time = ROBOT_GEN_TIME;
454 dist_to_player = vm_vec_dist_quick( &ConsoleObject->pos, &robotcen->Center );
455 top_time = dist_to_player/64 + d_rand() * 2 + F1_0*2;
456 if ( top_time > ROBOT_GEN_TIME )
457 top_time = ROBOT_GEN_TIME + d_rand();
458 if ( top_time < F1_0*2 )
459 top_time = F1_0*3/2 + d_rand()*2;
462 // mprintf( (0, "Time between morphs %d seconds, dist_to_player = %7.3f\n", f2i(top_time), f2fl(dist_to_player) ));
464 if (robotcen->Timer > top_time ) {
466 int i, my_station_num = robotcen-Station;
469 // Make sure this robotmaker hasn't put out its max without having any of them killed.
470 for (i=0; i<=Highest_object_index; i++)
471 if (Objects[i].type == OBJ_ROBOT)
472 if ((Objects[i].matcen_creator^0x80) == my_station_num)
474 if (count > Difficulty_level + 3) {
475 mprintf((0, "Cannot morph: center %i has already put out %i robots.\n", my_station_num, count));
476 robotcen->Timer /= 2;
480 // Whack on any robot or player in the matcen segment.
482 segnum = robotcen->segnum;
483 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
485 if ( count > MAX_OBJECTS ) {
486 mprintf((0, "Object list in segment %d is circular.", segnum ));
490 if (Objects[objnum].type==OBJ_ROBOT) {
491 collide_robot_and_materialization_center(&Objects[objnum]);
492 robotcen->Timer = top_time/2;
494 } else if (Objects[objnum].type==OBJ_PLAYER ) {
495 collide_player_and_materialization_center(&Objects[objnum]);
496 robotcen->Timer = top_time/2;
501 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
502 // HACK!!! The 10 under here should be something equal to the 1/2 the size of the segment.
503 obj = object_create_explosion(robotcen->segnum, &cur_object_loc, i2f(10), VCLIP_MORPHING_ROBOT );
506 extract_orient_from_segment(&obj->orient,&Segments[robotcen->segnum]);
508 if ( Vclip[VCLIP_MORPHING_ROBOT].sound_num > -1 ) {
509 digi_link_sound_to_pos( Vclip[VCLIP_MORPHING_ROBOT].sound_num, robotcen->segnum, 0, &cur_object_loc, 0, F1_0 );
516 case 1: // Wait until 1/2 second after VCLIP started.
517 if (robotcen->Timer > (Vclip[VCLIP_MORPHING_ROBOT].play_time/2) ) {
519 robotcen->Capacity -= EnergyToCreateOneRobot;
523 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
525 // If this is the first materialization, set to valid robot.
526 if (RobotCenters[matcen_num].robot_flags[0] != 0 || RobotCenters[matcen_num].robot_flags[1] != 0) {
529 byte legal_types[64]; // 64 bits, the width of robot_flags[].
530 int num_types, robot_index, i;
535 flags = RobotCenters[matcen_num].robot_flags[i];
538 legal_types[num_types++] = robot_index;
544 //mprintf((0, "Flags = %08x, %2i legal types to morph: \n", RobotCenters[matcen_num].robot_flags, num_types));
545 //for (i=0; i<num_types; i++)
546 // mprintf((0, "%2i ", legal_types[i]));
547 //mprintf((0, "\n"));
550 type = legal_types[0];
552 type = legal_types[(d_rand() * num_types) / 32768];
554 mprintf((0, "Morph: (type = %i) (seg = %i) (capacity = %08x)\n", type, robotcen->segnum, robotcen->Capacity));
555 obj = create_morph_robot(&Segments[robotcen->segnum], &cur_object_loc, type );
559 if (Game_mode & GM_MULTI)
560 multi_send_create_robot(robotcen-Station, obj-Objects, type);
563 obj->matcen_creator = (robotcen-Station) | 0x80;
565 // Make object faces player...
566 vm_vec_sub( &direction, &ConsoleObject->pos,&obj->pos );
567 vm_vector_2_matrix( &obj->orient, &direction, &obj->orient.uvec, NULL);
570 //robotcen->last_created_obj = obj;
571 //robotcen->last_created_sig = robotcen->last_created_obj->signature;
573 mprintf((0, "Warning: create_morph_robot returned NULL (no objects left?)\n"));
586 //-------------------------------------------------------------
587 // Called once per frame, replenishes fuel supply.
588 void fuelcen_update_all()
591 fix AmountToreplenish;
593 AmountToreplenish = fixmul(FrameTime,Fuelcen_refill_speed);
595 for (i=0; i<Num_fuelcenters; i++ ) {
596 if ( Station[i].Type == SEGMENT_IS_ROBOTMAKER ) {
597 if (! (Game_suspended & SUSP_ROBOTS))
598 robotmaker_proc( &Station[i] );
599 } else if ( Station[i].Type == SEGMENT_IS_CONTROLCEN ) {
600 //controlcen_proc( &Station[i] );
602 } else if ( (Station[i].MaxCapacity > 0) && (PlayerSegment!=&Segments[Station[i].segnum]) ) {
603 if ( Station[i].Capacity < Station[i].MaxCapacity ) {
604 Station[i].Capacity += AmountToreplenish;
605 //mprintf( (0, "Fuel center %d replenished to %d.\n", i, f2i(Station[i].Capacity) ));
606 if ( Station[i].Capacity >= Station[i].MaxCapacity ) {
607 Station[i].Capacity = Station[i].MaxCapacity;
608 //gauge_message( "Fuel center is fully recharged! " );
615 //--unused-- //-------------------------------------------------------------
616 //--unused-- // replenishes all fuel supplies.
617 //--unused-- void fuelcen_replenish_all()
621 //--unused-- for (i=0; i<Num_fuelcenters; i++ ) {
622 //--unused-- Station[i].Capacity = Station[i].MaxCapacity;
624 //--unused-- //mprintf( (0, "All fuel centers are replenished\n" ));
628 #define FUELCEN_SOUND_DELAY (f1_0/4) //play every half second
630 //-------------------------------------------------------------
631 fix fuelcen_give_fuel(segment *segp, fix MaxAmountCanTake )
633 segment2 *seg2p = &Segment2s[segp-Segments];
635 static fix last_play_time=0;
637 Assert( segp != NULL );
639 PlayerSegment = segp;
641 if ( (segp) && (seg2p->special==SEGMENT_IS_FUELCEN) ) {
644 detect_escort_goal_accomplished(-4); // UGLY! Hack! -4 means went through fuelcen.
646 // if (Station[segp->value].MaxCapacity<=0) {
647 // HUD_init_message( "Fuelcenter %d is destroyed.", segp->value );
651 // if (Station[segp->value].Capacity<=0) {
652 // HUD_init_message( "Fuelcenter %d is empty.", segp->value );
656 if (MaxAmountCanTake <= 0 ) {
657 // //gauge_message( "Fueled up!");
661 amount = fixmul(FrameTime,Fuelcen_give_amount);
663 if (amount > MaxAmountCanTake )
664 amount = MaxAmountCanTake;
666 // if (!(Game_mode & GM_MULTI))
667 // if ( Station[segp->value].Capacity < amount ) {
668 // amount = Station[segp->value].Capacity;
669 // Station[segp->value].Capacity = 0;
671 // Station[segp->value].Capacity -= amount;
674 if (last_play_time > GameTime)
677 if (GameTime > last_play_time+FUELCEN_SOUND_DELAY) {
679 digi_play_sample( SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2 );
681 if (Game_mode & GM_MULTI)
682 multi_send_play_sound(SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2);
685 last_play_time = GameTime;
689 //HUD_init_message( "Fuelcen %d has %d/%d fuel", segp->value,f2i(Station[segp->value].Capacity),f2i(Station[segp->value].MaxCapacity) );
697 //--unused-- //-----------------------------------------------------------
698 //--unused-- // Damages a fuel center
699 //--unused-- void fuelcen_damage(segment *segp, fix damage )
701 //--unused-- //int i;
702 //--unused-- // int station_num = segp->value;
704 //--unused-- Assert( segp != NULL );
705 //--unused-- if ( segp == NULL ) return;
707 //--unused-- mprintf((0, "Obsolete function fuelcen_damage() called with seg=%i, damage=%7.3f\n", segp-Segments, f2fl(damage)));
708 //--unused-- switch( segp->special ) {
709 //--unused-- case SEGMENT_IS_NOTHING:
711 //--unused-- case SEGMENT_IS_ROBOTMAKER:
712 //--unused-- //-- // Robotmaker hit by laser
713 //--unused-- //-- if (Station[station_num].MaxCapacity<=0 ) {
714 //--unused-- //-- // Shooting a already destroyed materializer
715 //--unused-- //-- } else {
716 //--unused-- //-- Station[station_num].MaxCapacity -= damage;
717 //--unused-- //-- if (Station[station_num].Capacity > Station[station_num].MaxCapacity ) {
718 //--unused-- //-- Station[station_num].Capacity = Station[station_num].MaxCapacity;
720 //--unused-- //-- if (Station[station_num].MaxCapacity <= 0 ) {
721 //--unused-- //-- Station[station_num].MaxCapacity = 0;
722 //--unused-- //-- // Robotmaker dead
723 //--unused-- //-- for (i=0; i<6; i++ )
724 //--unused-- //-- segp->sides[i].tmap_num2 = 0;
727 //--unused-- //-- //mprintf( (0, "Materializatormografier has %x capacity left\n", Station[station_num].MaxCapacity ));
729 //--unused-- case SEGMENT_IS_FUELCEN:
730 //--unused-- //-- digi_play_sample( SOUND_REFUEL_STATION_HIT );
731 //--unused-- //-- if (Station[station_num].MaxCapacity>0 ) {
732 //--unused-- //-- Station[station_num].MaxCapacity -= damage;
733 //--unused-- //-- if (Station[station_num].Capacity > Station[station_num].MaxCapacity ) {
734 //--unused-- //-- Station[station_num].Capacity = Station[station_num].MaxCapacity;
736 //--unused-- //-- if (Station[station_num].MaxCapacity <= 0 ) {
737 //--unused-- //-- Station[station_num].MaxCapacity = 0;
738 //--unused-- //-- digi_play_sample( SOUND_REFUEL_STATION_DESTROYED );
740 //--unused-- //-- } else {
741 //--unused-- //-- Station[station_num].MaxCapacity = 0;
743 //--unused-- //-- HUD_init_message( "Fuelcenter %d damaged", station_num );
745 //--unused-- case SEGMENT_IS_REPAIRCEN:
747 //--unused-- case SEGMENT_IS_CONTROLCEN:
749 //--unused-- default:
750 //--unused-- Error( "Invalid type in fuelcen.c" );
754 //--unused-- // ----------------------------------------------------------------------------------------------------------
755 //--unused-- fixang my_delta_ang(fixang a,fixang b)
757 //--unused-- fixang delta0,delta1;
759 //--unused-- return (abs(delta0 = a - b) < abs(delta1 = b - a)) ? delta0 : delta1;
763 //--unused-- // ----------------------------------------------------------------------------------------------------------
764 //--unused-- //return though which side of seg0 is seg1
765 //--unused-- int john_find_connect_side(int seg0,int seg1)
767 //--unused-- segment *Seg=&Segments[seg0];
770 //--unused-- for (i=MAX_SIDES_PER_SEGMENT;i--;) if (Seg->children[i]==seg1) return i;
772 //--unused-- return -1;
775 // ----------------------------------------------------------------------------------------------------------
776 //--unused-- vms_angvec start_angles, delta_angles, goal_angles;
777 //--unused-- vms_vector start_pos, delta_pos, goal_pos;
778 //--unused-- int FuelStationSeg;
779 //--unused-- fix current_time,delta_time;
780 //--unused-- int next_side, side_index;
781 //--unused-- int * sidelist;
783 //--repair-- int Repairing;
784 //--repair-- vms_vector repair_save_uvec; //the player's upvec when enter repaircen
785 //--repair-- object *RepairObj=NULL; //which object getting repaired
786 //--repair-- int disable_repair_center=0;
787 //--repair-- fix repair_rate;
788 //--repair-- #define FULL_REPAIR_RATE i2f(10)
790 //--unused-- ubyte save_control_type,save_movement_type;
792 //--unused-- int SideOrderBack[] = {WFRONT, WRIGHT, WTOP, WLEFT, WBOTTOM, WBACK};
793 //--unused-- int SideOrderFront[] = {WBACK, WLEFT, WTOP, WRIGHT, WBOTTOM, WFRONT};
794 //--unused-- int SideOrderLeft[] = { WRIGHT, WBACK, WTOP, WFRONT, WBOTTOM, WLEFT };
795 //--unused-- int SideOrderRight[] = { WLEFT, WFRONT, WTOP, WBACK, WBOTTOM, WRIGHT };
796 //--unused-- int SideOrderTop[] = { WBOTTOM, WLEFT, WBACK, WRIGHT, WFRONT, WTOP };
797 //--unused-- int SideOrderBottom[] = { WTOP, WLEFT, WFRONT, WRIGHT, WBACK, WBOTTOM };
799 //--unused-- int SideUpVector[] = {WBOTTOM, WFRONT, WBOTTOM, WFRONT, WBOTTOM, WBOTTOM };
801 //--repair-- // ----------------------------------------------------------------------------------------------------------
802 //--repair-- void refuel_calc_deltas(object *obj, int next_side, int repair_seg)
804 //--repair-- vms_vector nextcenter, headfvec, *headuvec;
805 //--repair-- vms_matrix goal_orient;
807 //--repair-- // Find time for this movement
808 //--repair-- delta_time = F1_0; // one second...
810 //--repair-- // Find start and goal position
811 //--repair-- start_pos = obj->pos;
813 //--repair-- // Find delta position to get to goal position
814 //--repair-- compute_segment_center(&goal_pos,&Segments[repair_seg]);
815 //--repair-- vm_vec_sub( &delta_pos,&goal_pos,&start_pos);
817 //--repair-- // Find start angles
818 //--repair-- //angles_from_vector(&start_angles,&obj->orient.fvec);
819 //--repair-- vm_extract_angles_matrix(&start_angles,&obj->orient);
821 //--repair-- // Find delta angles to get to goal orientation
822 //--repair-- med_compute_center_point_on_side(&nextcenter,&Segments[repair_seg],next_side);
823 //--repair-- vm_vec_sub(&headfvec,&nextcenter,&goal_pos);
824 //--repair-- //mprintf( (0, "Next_side = %d, Head fvec = %d,%d,%d\n", next_side, headfvec.x, headfvec.y, headfvec.z ));
826 //--repair-- if (next_side == 5) //last side
827 //--repair-- headuvec = &repair_save_uvec;
829 //--repair-- headuvec = &Segments[repair_seg].sides[SideUpVector[next_side]].normals[0];
831 //--repair-- vm_vector_2_matrix(&goal_orient,&headfvec,headuvec,NULL);
832 //--repair-- vm_extract_angles_matrix(&goal_angles,&goal_orient);
833 //--repair-- delta_angles.p = my_delta_ang(start_angles.p,goal_angles.p);
834 //--repair-- delta_angles.b = my_delta_ang(start_angles.b,goal_angles.b);
835 //--repair-- delta_angles.h = my_delta_ang(start_angles.h,goal_angles.h);
836 //--repair-- current_time = 0;
837 //--repair-- Repairing = 0;
840 //--repair-- // ----------------------------------------------------------------------------------------------------------
841 //--repair-- //if repairing, cut it short
842 //--repair-- abort_repair_center()
844 //--repair-- if (!RepairObj || side_index==5)
847 //--repair-- current_time = 0;
848 //--repair-- side_index = 5;
849 //--repair-- next_side = sidelist[side_index];
850 //--repair-- refuel_calc_deltas(RepairObj, next_side, FuelStationSeg);
853 //--repair-- // ----------------------------------------------------------------------------------------------------------
854 //--repair-- void repair_ship_damage()
856 //--repair-- //mprintf((0,"Repairing ship damage\n"));
859 //--repair-- // ----------------------------------------------------------------------------------------------------------
860 //--repair-- int refuel_do_repair_effect( object * obj, int first_time, int repair_seg ) {
862 //--repair-- obj->mtype.phys_info.velocity.x = 0;
863 //--repair-- obj->mtype.phys_info.velocity.y = 0;
864 //--repair-- obj->mtype.phys_info.velocity.z = 0;
866 //--repair-- if (first_time) {
867 //--repair-- int entry_side;
868 //--repair-- current_time = 0;
870 //--repair-- digi_play_sample( SOUND_REPAIR_STATION_PLAYER_ENTERING, F1_0 );
872 //--repair-- entry_side = john_find_connect_side(repair_seg,obj->segnum );
873 //--repair-- Assert( entry_side > -1 );
875 //--repair-- switch( entry_side ) {
876 //--repair-- case WBACK: sidelist = SideOrderBack; break;
877 //--repair-- case WFRONT: sidelist = SideOrderFront; break;
878 //--repair-- case WLEFT: sidelist = SideOrderLeft; break;
879 //--repair-- case WRIGHT: sidelist = SideOrderRight; break;
880 //--repair-- case WTOP: sidelist = SideOrderTop; break;
881 //--repair-- case WBOTTOM: sidelist = SideOrderBottom; break;
883 //--repair-- side_index = 0;
884 //--repair-- next_side = sidelist[side_index];
886 //--repair-- refuel_calc_deltas(obj,next_side, repair_seg);
889 //--repair-- //update shields
890 //--repair-- if (Players[Player_num].shields < MAX_SHIELDS) { //if above max, don't mess with it
892 //--repair-- Players[Player_num].shields += fixmul(FrameTime,repair_rate);
894 //--repair-- if (Players[Player_num].shields > MAX_SHIELDS)
895 //--repair-- Players[Player_num].shields = MAX_SHIELDS;
898 //--repair-- current_time += FrameTime;
900 //--repair-- if (current_time >= delta_time ) {
901 //--repair-- vms_angvec av;
902 //--repair-- obj->pos = goal_pos;
903 //--repair-- av = goal_angles;
904 //--repair-- vm_angles_2_matrix(&obj->orient,&av);
906 //--repair-- if (side_index >= 5 )
907 //--repair-- return 1; // Done being repaired...
909 //--repair-- if (Repairing==0) {
910 //--repair-- //mprintf( (0, "<MACHINE EFFECT ON SIDE %d>\n", next_side ));
911 //--repair-- //digi_play_sample( SOUND_REPAIR_STATION_FIXING );
912 //--repair-- Repairing=1;
914 //--repair-- switch( next_side ) {
915 //--repair-- case 0: digi_play_sample( SOUND_REPAIR_STATION_FIXING_1,F1_0 ); break;
916 //--repair-- case 1: digi_play_sample( SOUND_REPAIR_STATION_FIXING_2,F1_0 ); break;
917 //--repair-- case 2: digi_play_sample( SOUND_REPAIR_STATION_FIXING_3,F1_0 ); break;
918 //--repair-- case 3: digi_play_sample( SOUND_REPAIR_STATION_FIXING_4,F1_0 ); break;
919 //--repair-- case 4: digi_play_sample( SOUND_REPAIR_STATION_FIXING_1,F1_0 ); break;
920 //--repair-- case 5: digi_play_sample( SOUND_REPAIR_STATION_FIXING_2,F1_0 ); break;
923 //--repair-- repair_ship_damage();
927 //--repair-- if (current_time >= (delta_time+(F1_0/2)) ) {
928 //--repair-- current_time = 0;
929 //--repair-- // Find next side...
930 //--repair-- side_index++;
931 //--repair-- if (side_index >= 6 ) return 1;
932 //--repair-- next_side = sidelist[side_index];
934 //--repair-- refuel_calc_deltas(obj, next_side, repair_seg);
937 //--repair-- } else {
938 //--repair-- fix factor, p,b,h;
939 //--repair-- vms_angvec av;
941 //--repair-- factor = fixdiv( current_time,delta_time );
943 //--repair-- // Find object's current position
944 //--repair-- obj->pos = delta_pos;
945 //--repair-- vm_vec_scale( &obj->pos, factor );
946 //--repair-- vm_vec_add2( &obj->pos, &start_pos );
948 //--repair-- // Find object's current orientation
949 //--repair-- p = fixmul(delta_angles.p,factor);
950 //--repair-- b = fixmul(delta_angles.b,factor);
951 //--repair-- h = fixmul(delta_angles.h,factor);
952 //--repair-- av.p = (fixang)p + start_angles.p;
953 //--repair-- av.b = (fixang)b + start_angles.b;
954 //--repair-- av.h = (fixang)h + start_angles.h;
955 //--repair-- vm_angles_2_matrix(&obj->orient,&av);
959 //--repair-- update_object_seg(obj); //update segment
961 //--repair-- return 0;
964 //--repair-- // ----------------------------------------------------------------------------------------------------------
965 //--repair-- //do the repair center for this frame
966 //--repair-- void do_repair_sequence(object *obj)
968 //--repair-- Assert(obj == RepairObj);
970 //--repair-- if (refuel_do_repair_effect( obj, 0, FuelStationSeg )) {
971 //--repair-- if (Players[Player_num].shields < MAX_SHIELDS)
972 //--repair-- Players[Player_num].shields = MAX_SHIELDS;
973 //--repair-- obj->control_type = save_control_type;
974 //--repair-- obj->movement_type = save_movement_type;
975 //--repair-- disable_repair_center=1;
976 //--repair-- RepairObj = NULL;
979 //--repair-- //the two lines below will spit the player out of the rapair center,
980 //--repair-- //but what happen is that the ship just bangs into the door
981 //--repair-- //if (obj->movement_type == MT_PHYSICS)
982 //--repair-- // vm_vec_copy_scale(&obj->mtype.phys_info.velocity,&obj->orient.fvec,i2f(200));
987 //--repair-- // ----------------------------------------------------------------------------------------------------------
988 //--repair-- //see if we should start the repair center
989 //--repair-- void check_start_repair_center(object *obj)
991 //--repair-- if (RepairObj != NULL) return; //already in repair center
993 //--repair-- if (Lsegments[obj->segnum].special_type & SS_REPAIR_CENTER) {
995 //--repair-- if (!disable_repair_center) {
996 //--repair-- //have just entered repair center
998 //--repair-- RepairObj = obj;
999 //--repair-- repair_save_uvec = obj->orient.uvec;
1001 //--repair-- repair_rate = fixmuldiv(FULL_REPAIR_RATE,(MAX_SHIELDS - Players[Player_num].shields),MAX_SHIELDS);
1003 //--repair-- save_control_type = obj->control_type;
1004 //--repair-- save_movement_type = obj->movement_type;
1006 //--repair-- obj->control_type = CT_REPAIRCEN;
1007 //--repair-- obj->movement_type = MT_NONE;
1009 //--repair-- FuelStationSeg = Lsegments[obj->segnum].special_segment;
1010 //--repair-- Assert(FuelStationSeg != -1);
1012 //--repair-- if (refuel_do_repair_effect( obj, 1, FuelStationSeg )) {
1013 //--repair-- Int3(); //can this happen?
1014 //--repair-- obj->control_type = CT_FLYING;
1015 //--repair-- obj->movement_type = MT_PHYSICS;
1020 //--repair-- disable_repair_center=0;
1024 // --------------------------------------------------------------------------------------------
1025 void disable_matcens(void)
1029 for (i=0; i<Num_robot_centers; i++) {
1030 Station[i].Enabled = 0;
1031 Station[i].Disable_time = 0;
1035 // --------------------------------------------------------------------------------------------
1036 // Initialize all materialization centers.
1037 // Give them all the right number of lives.
1038 void init_all_matcens(void)
1042 for (i=0; i<Num_fuelcenters; i++)
1043 if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
1044 Station[i].Lives = 3;
1045 Station[i].Enabled = 0;
1046 Station[i].Disable_time = 0;
1049 // Make sure this fuelcen is pointed at by a matcen.
1051 for (j=0; j<Num_robot_centers; j++) {
1052 if (RobotCenters[j].fuelcen_num == i)
1055 Assert(j != Num_robot_centers);
1062 // Make sure all matcens point at a fuelcen
1063 for (i=0; i<Num_robot_centers; i++) {
1064 int fuelcen_num = RobotCenters[i].fuelcen_num;
1066 Assert(fuelcen_num < Num_fuelcenters);
1067 Assert(Station[fuelcen_num].Type == SEGMENT_IS_ROBOTMAKER);
1074 extern void multi_send_capture_bonus (char);
1076 void fuelcen_check_for_goal(segment *segp)
1078 segment2 *seg2p = &Segment2s[segp-Segments];
1080 Assert( segp != NULL );
1081 Assert (Game_mode & GM_CAPTURE);
1083 if (seg2p->special==SEGMENT_IS_GOAL_BLUE ) {
1085 if ((get_team(Player_num)==TEAM_BLUE) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1087 mprintf ((0,"In goal segment BLUE\n"));
1089 multi_send_capture_bonus (Player_num);
1090 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1091 maybe_drop_net_powerup (POW_FLAG_RED);
1094 if ( seg2p->special==SEGMENT_IS_GOAL_RED) {
1096 if ((get_team(Player_num)==TEAM_RED) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1098 mprintf ((0,"In goal segment RED\n"));
1099 multi_send_capture_bonus (Player_num);
1100 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1101 maybe_drop_net_powerup (POW_FLAG_BLUE);
1106 void fuelcen_check_for_hoard_goal(segment *segp)
1108 segment2 *seg2p = &Segment2s[segp-Segments];
1110 Assert( segp != NULL );
1111 Assert (Game_mode & GM_HOARD);
1116 if (seg2p->special==SEGMENT_IS_GOAL_BLUE || seg2p->special==SEGMENT_IS_GOAL_RED )
1118 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX])
1120 mprintf ((0,"In orb goal!\n"));
1121 multi_send_orb_bonus (Player_num);
1122 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1123 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]=0;