1 /* $Id: fuelcen.c,v 1.10 2004-08-28 23:17:45 schaffner Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Functions for refueling centers.
26 static char rcsid[] = "$Id: fuelcen.c,v 1.10 2004-08-28 23:17:45 schaffner Exp $";
36 #include "game.h" // For FrameTime
64 // The max number of fuel stations per mine.
66 fix Fuelcen_refill_speed = i2f(1);
67 fix Fuelcen_give_amount = i2f(25);
68 fix Fuelcen_max_amount = i2f(100);
70 // Every time a robot is created in the morphing code, it decreases capacity of the morpher
71 // by this amount... when capacity gets to 0, no more morphers...
72 fix EnergyToCreateOneRobot = i2f(1);
74 #define MATCEN_HP_DEFAULT F1_0*500; // Hitpoints
75 #define MATCEN_INTERVAL_DEFAULT F1_0*5; // 5 seconds
77 matcen_info RobotCenters[MAX_ROBOT_CENTERS];
78 int Num_robot_centers;
80 FuelCenter Station[MAX_NUM_FUELCENS];
81 int Num_fuelcenters = 0;
83 segment * PlayerSegment= NULL;
86 char Special_names[MAX_CENTER_TYPES][11] = {
97 //------------------------------------------------------------
98 // Resets all fuel center info
104 //mprintf( (0, "All fuel centers reset.\n"));
106 for(i=0; i<MAX_SEGMENTS; i++ )
107 Segment2s[i].special = SEGMENT_IS_NOTHING;
109 Num_robot_centers = 0;
113 #ifndef NDEBUG //this is sometimes called by people from the debugger
114 void reset_all_robot_centers()
118 // Remove all materialization centers
119 for (i=0; i<Num_segments; i++)
120 if (Segment2s[i].special == SEGMENT_IS_ROBOTMAKER) {
121 Segment2s[i].special = SEGMENT_IS_NOTHING;
122 Segment2s[i].matcen_num = -1;
127 //------------------------------------------------------------
128 // Turns a segment into a fully charged up fuel center...
129 void fuelcen_create( segment *segp)
131 segment2 *seg2p = &Segment2s[segp-Segments];
135 station_type = seg2p->special;
137 switch( station_type ) {
138 case SEGMENT_IS_NOTHING:
139 case SEGMENT_IS_GOAL_BLUE:
140 case SEGMENT_IS_GOAL_RED:
142 case SEGMENT_IS_FUELCEN:
143 case SEGMENT_IS_REPAIRCEN:
144 case SEGMENT_IS_CONTROLCEN:
145 case SEGMENT_IS_ROBOTMAKER:
148 Error( "Invalid station type %d in fuelcen.c\n", station_type );
151 Assert( (seg2p != NULL) );
152 if ( seg2p == NULL ) return;
154 Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
155 Assert( Num_fuelcenters > -1 );
157 seg2p->value = Num_fuelcenters;
158 Station[Num_fuelcenters].Type = station_type;
159 Station[Num_fuelcenters].MaxCapacity = Fuelcen_max_amount;
160 Station[Num_fuelcenters].Capacity = Station[Num_fuelcenters].MaxCapacity;
161 Station[Num_fuelcenters].segnum = seg2p-Segment2s;
162 Station[Num_fuelcenters].Timer = -1;
163 Station[Num_fuelcenters].Flag = 0;
164 // Station[Num_fuelcenters].NextRobotType = -1;
165 // Station[Num_fuelcenters].last_created_obj=NULL;
166 // Station[Num_fuelcenters].last_created_sig = -1;
167 compute_segment_center(&Station[Num_fuelcenters].Center, segp);
169 // if (station_type == SEGMENT_IS_ROBOTMAKER)
170 // Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
172 //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
176 //------------------------------------------------------------
177 // Adds a matcen that already is a special type into the Station array.
178 // This function is separate from other fuelcens because we don't want values reset.
179 void matcen_create( segment *segp)
181 segment2 *seg2p = &Segment2s[segp-Segments];
183 int station_type = seg2p->special;
185 Assert( (seg2p != NULL) );
186 Assert(station_type == SEGMENT_IS_ROBOTMAKER);
187 if ( seg2p == NULL ) return;
189 Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
190 Assert( Num_fuelcenters > -1 );
192 seg2p->value = Num_fuelcenters;
193 Station[Num_fuelcenters].Type = station_type;
194 Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
195 Station[Num_fuelcenters].MaxCapacity = Station[Num_fuelcenters].Capacity;
197 Station[Num_fuelcenters].segnum = seg2p-Segment2s;
198 Station[Num_fuelcenters].Timer = -1;
199 Station[Num_fuelcenters].Flag = 0;
200 // Station[Num_fuelcenters].NextRobotType = -1;
201 // Station[Num_fuelcenters].last_created_obj=NULL;
202 // Station[Num_fuelcenters].last_created_sig = -1;
203 compute_segment_center(&Station[Num_fuelcenters].Center, &Segments[seg2p-Segment2s] );
205 seg2p->matcen_num = Num_robot_centers;
208 RobotCenters[seg2p->matcen_num].hit_points = MATCEN_HP_DEFAULT;
209 RobotCenters[seg2p->matcen_num].interval = MATCEN_INTERVAL_DEFAULT;
210 RobotCenters[seg2p->matcen_num].segnum = seg2p-Segment2s;
211 RobotCenters[seg2p->matcen_num].fuelcen_num = Num_fuelcenters;
213 //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
217 //------------------------------------------------------------
218 // Adds a segment that already is a special type into the Station array.
219 void fuelcen_activate( segment * segp, int station_type )
221 segment2 *seg2p = &Segment2s[segp-Segments];
223 seg2p->special = station_type;
225 if (seg2p->special == SEGMENT_IS_ROBOTMAKER)
226 matcen_create( segp);
228 fuelcen_create( segp);
232 // The lower this number is, the more quickly the center can be re-triggered.
233 // If it's too low, it can mean all the robots won't be put out, but for about 5
234 // robots, that's not real likely.
235 #define MATCEN_LIFE (i2f(30-2*Difficulty_level))
237 //------------------------------------------------------------
238 // Trigger (enable) the materialization center in segment segnum
239 void trigger_matcen(int segnum)
241 // -- segment *segp = &Segments[segnum];
242 segment2 *seg2p = &Segment2s[segnum];
243 vms_vector pos, delta;
244 FuelCenter *robotcen;
247 mprintf((0, "Trigger matcen, segment %i\n", segnum));
249 Assert(seg2p->special == SEGMENT_IS_ROBOTMAKER);
250 Assert(seg2p->matcen_num < Num_fuelcenters);
251 Assert((seg2p->matcen_num >= 0) && (seg2p->matcen_num <= Highest_segment_index));
253 robotcen = &Station[RobotCenters[seg2p->matcen_num].fuelcen_num];
255 if (robotcen->Enabled == 1)
258 if (!robotcen->Lives)
261 // MK: 11/18/95, At insane, matcens work forever!
262 if (Difficulty_level+1 < NDL)
265 robotcen->Timer = F1_0*1000; // Make sure the first robot gets emitted right away.
266 robotcen->Enabled = 1; // Say this center is enabled, it can create robots.
267 robotcen->Capacity = i2f(Difficulty_level + 3);
268 robotcen->Disable_time = MATCEN_LIFE;
270 // Create a bright object in the segment.
271 pos = robotcen->Center;
272 vm_vec_sub(&delta, &Vertices[Segments[segnum].verts[0]], &robotcen->Center);
273 vm_vec_scale_add2(&pos, &delta, F1_0/2);
274 objnum = obj_create( OBJ_LIGHT, 0, segnum, &pos, NULL, 0, CT_LIGHT, MT_NONE, RT_NONE );
276 Objects[objnum].lifeleft = MATCEN_LIFE;
277 Objects[objnum].ctype.light_info.intensity = i2f(8); // Light cast by a fuelcen.
279 mprintf((1, "Can't create invisible flare for matcen.\n"));
282 // 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)));
286 //------------------------------------------------------------
287 // Takes away a segment's fuel center properties.
288 // Deletes the segment point entry in the FuelCenter list.
289 void fuelcen_delete( segment * segp )
291 segment2 *seg2p = &Segment2s[segp-Segments];
298 for (i=0; i<Num_fuelcenters; i++ ) {
299 if ( Station[i].segnum == segp-Segments ) {
301 // If Robot maker is deleted, fix Segments and RobotCenters.
302 if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
304 Assert(Num_robot_centers >= 0);
306 for (j=seg2p->matcen_num; j<Num_robot_centers; j++)
307 RobotCenters[j] = RobotCenters[j+1];
309 for (j=0; j<Num_fuelcenters; j++) {
310 if ( Station[j].Type == SEGMENT_IS_ROBOTMAKER )
311 if ( Segment2s[Station[j].segnum].matcen_num > seg2p->matcen_num )
312 Segment2s[Station[j].segnum].matcen_num--;
316 //fix RobotCenters so they point to correct fuelcenter
317 for (j=0; j<Num_robot_centers; j++ )
318 if (RobotCenters[j].fuelcen_num > i) //this robotcenter's fuelcen is changing
319 RobotCenters[j].fuelcen_num--;
322 Assert(Num_fuelcenters >= 0);
323 for (j=i; j<Num_fuelcenters; j++ ) {
324 Station[j] = Station[j+1];
325 Segment2s[Station[j].segnum].value = j;
334 #define ROBOT_GEN_TIME (i2f(5))
336 object * create_morph_robot( segment *segp, vms_vector *object_pos, int object_id)
340 int default_behavior;
342 Players[Player_num].num_robots_level++;
343 Players[Player_num].num_robots_total++;
345 objnum = obj_create(OBJ_ROBOT, object_id, segp-Segments, object_pos,
346 &vmd_identity_matrix, Polygon_models[Robot_info[object_id].model_num].rad,
347 CT_AI, MT_PHYSICS, RT_POLYOBJ);
350 mprintf((1, "Can't create morph robot. Aborting morph.\n"));
355 obj = &Objects[objnum];
357 //Set polygon-object-specific data
359 obj->rtype.pobj_info.model_num = Robot_info[obj->id].model_num;
360 obj->rtype.pobj_info.subobj_flags = 0;
364 obj->mtype.phys_info.mass = Robot_info[obj->id].mass;
365 obj->mtype.phys_info.drag = Robot_info[obj->id].drag;
367 obj->mtype.phys_info.flags |= (PF_LEVELLING);
369 obj->shields = Robot_info[obj->id].strength;
371 default_behavior = Robot_info[obj->id].behavior;
373 init_ai_object(obj-Objects, default_behavior, -1 ); // Note, -1 = segment this robot goes to to hide, should probably be something useful
375 create_n_segment_path(obj, 6, -1); // Create a 6 segment path from creation point.
377 Ai_local_info[objnum].mode = ai_behavior_to_mode(default_behavior);
382 int Num_extry_robots = 15;
385 int FrameCount_last_msg = 0;
388 // ----------------------------------------------------------------------------------------------------------
389 void robotmaker_proc( FuelCenter * robotcen )
392 vms_vector cur_object_loc; //, direction;
393 int matcen_num, segnum, objnum;
396 vms_vector direction;
398 if (robotcen->Enabled == 0)
401 if (robotcen->Disable_time > 0) {
402 robotcen->Disable_time -= FrameTime;
403 if (robotcen->Disable_time <= 0) {
404 mprintf((0, "Robot center #%i gets disabled due to time running out.\n", robotcen-Station));
405 robotcen->Enabled = 0;
409 // mprintf((0, "Capacity of robot maker #%i is %i\n", robotcen - Station, robotcen->Capacity));
411 // No robot making in multiplayer mode.
414 if ((Game_mode & GM_MULTI) && (!(Game_mode & GM_MULTI_ROBOTS) || !network_i_am_master()))
417 if (Game_mode & GM_MULTI)
422 // Wait until transmorgafier has capacity to make a robot...
423 if ( robotcen->Capacity <= 0 ) {
427 matcen_num = Segment2s[robotcen->segnum].matcen_num;
428 //mprintf((0, "Robotmaker #%i flags = %8x\n", matcen_num, RobotCenters[matcen_num].robot_flags));
430 if ( matcen_num == -1 ) {
431 mprintf((0, "Non-functional robotcen at %d\n", robotcen->segnum));
435 if (RobotCenters[matcen_num].robot_flags[0]==0 && RobotCenters[matcen_num].robot_flags[1]==0) {
436 //mprintf((0, "robot_flags = 0 at robot maker #%i\n", RobotCenters[matcen_num].robot_flags));
440 // Wait until we have a free slot for this puppy...
441 // <<<<<<<<<<<<<<<< Num robots in mine >>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<< Max robots in mine >>>>>>>>>>>>>>>
442 if ( (Players[Player_num].num_robots_level - Players[Player_num].num_kills_level) >= (Gamesave_num_org_robots + Num_extry_robots ) ) {
444 if (FrameCount > FrameCount_last_msg + 20) {
445 mprintf((0, "Cannot morph until you kill one!\n"));
446 FrameCount_last_msg = FrameCount;
452 robotcen->Timer += FrameTime;
454 switch( robotcen->Flag ) {
455 case 0: // Wait until next robot can generate
456 if (Game_mode & GM_MULTI)
458 top_time = ROBOT_GEN_TIME;
462 dist_to_player = vm_vec_dist_quick( &ConsoleObject->pos, &robotcen->Center );
463 top_time = dist_to_player/64 + d_rand() * 2 + F1_0*2;
464 if ( top_time > ROBOT_GEN_TIME )
465 top_time = ROBOT_GEN_TIME + d_rand();
466 if ( top_time < F1_0*2 )
467 top_time = F1_0*3/2 + d_rand()*2;
470 // mprintf( (0, "Time between morphs %d seconds, dist_to_player = %7.3f\n", f2i(top_time), f2fl(dist_to_player) ));
472 if (robotcen->Timer > top_time ) {
474 int i, my_station_num = robotcen-Station;
477 // Make sure this robotmaker hasn't put out its max without having any of them killed.
478 for (i=0; i<=Highest_object_index; i++)
479 if (Objects[i].type == OBJ_ROBOT)
480 if ((Objects[i].matcen_creator^0x80) == my_station_num)
482 if (count > Difficulty_level + 3) {
483 mprintf((0, "Cannot morph: center %i has already put out %i robots.\n", my_station_num, count));
484 robotcen->Timer /= 2;
488 // Whack on any robot or player in the matcen segment.
490 segnum = robotcen->segnum;
491 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
493 if ( count > MAX_OBJECTS ) {
494 mprintf((0, "Object list in segment %d is circular.", segnum ));
498 if (Objects[objnum].type==OBJ_ROBOT) {
499 collide_robot_and_materialization_center(&Objects[objnum]);
500 robotcen->Timer = top_time/2;
502 } else if (Objects[objnum].type==OBJ_PLAYER ) {
503 collide_player_and_materialization_center(&Objects[objnum]);
504 robotcen->Timer = top_time/2;
509 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
510 // HACK!!! The 10 under here should be something equal to the 1/2 the size of the segment.
511 obj = object_create_explosion(robotcen->segnum, &cur_object_loc, i2f(10), VCLIP_MORPHING_ROBOT );
514 extract_orient_from_segment(&obj->orient,&Segments[robotcen->segnum]);
516 if ( Vclip[VCLIP_MORPHING_ROBOT].sound_num > -1 ) {
517 digi_link_sound_to_pos( Vclip[VCLIP_MORPHING_ROBOT].sound_num, robotcen->segnum, 0, &cur_object_loc, 0, F1_0 );
524 case 1: // Wait until 1/2 second after VCLIP started.
525 if (robotcen->Timer > (Vclip[VCLIP_MORPHING_ROBOT].play_time/2) ) {
527 robotcen->Capacity -= EnergyToCreateOneRobot;
531 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
533 // If this is the first materialization, set to valid robot.
534 if (RobotCenters[matcen_num].robot_flags[0] != 0 || RobotCenters[matcen_num].robot_flags[1] != 0) {
537 sbyte legal_types[64]; // 64 bits, the width of robot_flags[].
538 int num_types, robot_index, i;
543 flags = RobotCenters[matcen_num].robot_flags[i];
546 legal_types[num_types++] = robot_index;
552 //mprintf((0, "Flags = %08x, %2i legal types to morph: \n", RobotCenters[matcen_num].robot_flags, num_types));
553 //for (i=0; i<num_types; i++)
554 // mprintf((0, "%2i ", legal_types[i]));
555 //mprintf((0, "\n"));
558 type = legal_types[0];
560 type = legal_types[(d_rand() * num_types) / 32768];
562 mprintf((0, "Morph: (type = %i) (seg = %i) (capacity = %08x)\n", type, robotcen->segnum, robotcen->Capacity));
563 obj = create_morph_robot(&Segments[robotcen->segnum], &cur_object_loc, type );
567 if (Game_mode & GM_MULTI)
568 multi_send_create_robot(robotcen-Station, obj-Objects, type);
571 obj->matcen_creator = (robotcen-Station) | 0x80;
573 // Make object faces player...
574 vm_vec_sub( &direction, &ConsoleObject->pos,&obj->pos );
575 vm_vector_2_matrix( &obj->orient, &direction, &obj->orient.uvec, NULL);
578 //robotcen->last_created_obj = obj;
579 //robotcen->last_created_sig = robotcen->last_created_obj->signature;
581 mprintf((0, "Warning: create_morph_robot returned NULL (no objects left?)\n"));
594 //-------------------------------------------------------------
595 // Called once per frame, replenishes fuel supply.
596 void fuelcen_update_all()
599 fix AmountToreplenish;
601 AmountToreplenish = fixmul(FrameTime,Fuelcen_refill_speed);
603 for (i=0; i<Num_fuelcenters; i++ ) {
604 if ( Station[i].Type == SEGMENT_IS_ROBOTMAKER ) {
605 if (! (Game_suspended & SUSP_ROBOTS))
606 robotmaker_proc( &Station[i] );
607 } else if ( Station[i].Type == SEGMENT_IS_CONTROLCEN ) {
608 //controlcen_proc( &Station[i] );
610 } else if ( (Station[i].MaxCapacity > 0) && (PlayerSegment!=&Segments[Station[i].segnum]) ) {
611 if ( Station[i].Capacity < Station[i].MaxCapacity ) {
612 Station[i].Capacity += AmountToreplenish;
613 //mprintf( (0, "Fuel center %d replenished to %d.\n", i, f2i(Station[i].Capacity) ));
614 if ( Station[i].Capacity >= Station[i].MaxCapacity ) {
615 Station[i].Capacity = Station[i].MaxCapacity;
616 //gauge_message( "Fuel center is fully recharged! " );
623 //--unused-- //-------------------------------------------------------------
624 //--unused-- // replenishes all fuel supplies.
625 //--unused-- void fuelcen_replenish_all()
629 //--unused-- for (i=0; i<Num_fuelcenters; i++ ) {
630 //--unused-- Station[i].Capacity = Station[i].MaxCapacity;
632 //--unused-- //mprintf( (0, "All fuel centers are replenished\n" ));
636 #define FUELCEN_SOUND_DELAY (f1_0/4) //play every half second
638 //-------------------------------------------------------------
639 fix fuelcen_give_fuel(segment *segp, fix MaxAmountCanTake )
641 segment2 *seg2p = &Segment2s[segp-Segments];
643 static fix last_play_time=0;
645 Assert( segp != NULL );
647 PlayerSegment = segp;
649 if ( (segp) && (seg2p->special==SEGMENT_IS_FUELCEN) ) {
652 detect_escort_goal_accomplished(-4); // UGLY! Hack! -4 means went through fuelcen.
654 // if (Station[segp->value].MaxCapacity<=0) {
655 // HUD_init_message( "Fuelcenter %d is destroyed.", segp->value );
659 // if (Station[segp->value].Capacity<=0) {
660 // HUD_init_message( "Fuelcenter %d is empty.", segp->value );
664 if (MaxAmountCanTake <= 0 ) {
665 // //gauge_message( "Fueled up!");
669 amount = fixmul(FrameTime,Fuelcen_give_amount);
671 if (amount > MaxAmountCanTake )
672 amount = MaxAmountCanTake;
674 // if (!(Game_mode & GM_MULTI))
675 // if ( Station[segp->value].Capacity < amount ) {
676 // amount = Station[segp->value].Capacity;
677 // Station[segp->value].Capacity = 0;
679 // Station[segp->value].Capacity -= amount;
682 if (last_play_time > GameTime)
685 if (GameTime > last_play_time+FUELCEN_SOUND_DELAY) {
687 digi_play_sample( SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2 );
689 if (Game_mode & GM_MULTI)
690 multi_send_play_sound(SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2);
693 last_play_time = GameTime;
697 //HUD_init_message( "Fuelcen %d has %d/%d fuel", segp->value,f2i(Station[segp->value].Capacity),f2i(Station[segp->value].MaxCapacity) );
705 //-------------------------------------------------------------
708 // use same values as fuel centers
709 fix repaircen_give_shields(segment *segp, fix MaxAmountCanTake )
711 segment2 *seg2p = &Segment2s[segp-Segments];
712 static fix last_play_time=0;
714 Assert( segp != NULL );
715 PlayerSegment = segp;
716 if ( (segp) && (seg2p->special==SEGMENT_IS_REPAIRCEN) ) {
718 // detect_escort_goal_accomplished(-4); // UGLY! Hack! -4 means went through fuelcen.
719 // if (Station[segp->value].MaxCapacity<=0) {
720 // HUD_init_message( "Repaircenter %d is destroyed.", segp->value );
723 // if (Station[segp->value].Capacity<=0) {
724 // HUD_init_message( "Repaircenter %d is empty.", segp->value );
727 if (MaxAmountCanTake <= 0 ) {
728 //gauge_message( "Shields restored!");
731 amount = fixmul(FrameTime,Fuelcen_give_amount);
732 if (amount > MaxAmountCanTake )
733 amount = MaxAmountCanTake;
734 // if (!(Game_mode & GM_MULTI))
735 // if ( Station[segp->value].Capacity < amount ) {
736 // amount = Station[segp->value].Capacity;
737 // Station[segp->value].Capacity = 0;
739 // Station[segp->value].Capacity -= amount;
741 if (last_play_time > GameTime)
743 if (GameTime > last_play_time+FUELCEN_SOUND_DELAY) {
744 digi_play_sample( SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2 );
746 if (Game_mode & GM_MULTI)
747 multi_send_play_sound(SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2);
749 last_play_time = GameTime;
751 //HUD_init_message( "Fuelcen %d has %d/%d fuel", segp->value,f2i(Station[segp->value].Capacity),f2i(Station[segp->value].MaxCapacity) );
758 //--unused-- //-----------------------------------------------------------
759 //--unused-- // Damages a fuel center
760 //--unused-- void fuelcen_damage(segment *segp, fix damage )
762 //--unused-- //int i;
763 //--unused-- // int station_num = segp->value;
765 //--unused-- Assert( segp != NULL );
766 //--unused-- if ( segp == NULL ) return;
768 //--unused-- mprintf((0, "Obsolete function fuelcen_damage() called with seg=%i, damage=%7.3f\n", segp-Segments, f2fl(damage)));
769 //--unused-- switch( segp->special ) {
770 //--unused-- case SEGMENT_IS_NOTHING:
772 //--unused-- case SEGMENT_IS_ROBOTMAKER:
773 //--unused-- //-- // Robotmaker hit by laser
774 //--unused-- //-- if (Station[station_num].MaxCapacity<=0 ) {
775 //--unused-- //-- // Shooting a already destroyed materializer
776 //--unused-- //-- } else {
777 //--unused-- //-- Station[station_num].MaxCapacity -= damage;
778 //--unused-- //-- if (Station[station_num].Capacity > Station[station_num].MaxCapacity ) {
779 //--unused-- //-- Station[station_num].Capacity = Station[station_num].MaxCapacity;
781 //--unused-- //-- if (Station[station_num].MaxCapacity <= 0 ) {
782 //--unused-- //-- Station[station_num].MaxCapacity = 0;
783 //--unused-- //-- // Robotmaker dead
784 //--unused-- //-- for (i=0; i<6; i++ )
785 //--unused-- //-- segp->sides[i].tmap_num2 = 0;
788 //--unused-- //-- //mprintf( (0, "Materializatormografier has %x capacity left\n", Station[station_num].MaxCapacity ));
790 //--unused-- case SEGMENT_IS_FUELCEN:
791 //--unused-- //-- digi_play_sample( SOUND_REFUEL_STATION_HIT );
792 //--unused-- //-- if (Station[station_num].MaxCapacity>0 ) {
793 //--unused-- //-- Station[station_num].MaxCapacity -= damage;
794 //--unused-- //-- if (Station[station_num].Capacity > Station[station_num].MaxCapacity ) {
795 //--unused-- //-- Station[station_num].Capacity = Station[station_num].MaxCapacity;
797 //--unused-- //-- if (Station[station_num].MaxCapacity <= 0 ) {
798 //--unused-- //-- Station[station_num].MaxCapacity = 0;
799 //--unused-- //-- digi_play_sample( SOUND_REFUEL_STATION_DESTROYED );
801 //--unused-- //-- } else {
802 //--unused-- //-- Station[station_num].MaxCapacity = 0;
804 //--unused-- //-- HUD_init_message( "Fuelcenter %d damaged", station_num );
806 //--unused-- case SEGMENT_IS_REPAIRCEN:
808 //--unused-- case SEGMENT_IS_CONTROLCEN:
810 //--unused-- default:
811 //--unused-- Error( "Invalid type in fuelcen.c" );
815 //--unused-- // ----------------------------------------------------------------------------------------------------------
816 //--unused-- fixang my_delta_ang(fixang a,fixang b)
818 //--unused-- fixang delta0,delta1;
820 //--unused-- return (abs(delta0 = a - b) < abs(delta1 = b - a)) ? delta0 : delta1;
824 //--unused-- // ----------------------------------------------------------------------------------------------------------
825 //--unused-- //return though which side of seg0 is seg1
826 //--unused-- int john_find_connect_side(int seg0,int seg1)
828 //--unused-- segment *Seg=&Segments[seg0];
831 //--unused-- for (i=MAX_SIDES_PER_SEGMENT;i--;) if (Seg->children[i]==seg1) return i;
833 //--unused-- return -1;
836 // ----------------------------------------------------------------------------------------------------------
837 //--unused-- vms_angvec start_angles, delta_angles, goal_angles;
838 //--unused-- vms_vector start_pos, delta_pos, goal_pos;
839 //--unused-- int FuelStationSeg;
840 //--unused-- fix current_time,delta_time;
841 //--unused-- int next_side, side_index;
842 //--unused-- int * sidelist;
844 //--repair-- int Repairing;
845 //--repair-- vms_vector repair_save_uvec; //the player's upvec when enter repaircen
846 //--repair-- object *RepairObj=NULL; //which object getting repaired
847 //--repair-- int disable_repair_center=0;
848 //--repair-- fix repair_rate;
849 //--repair-- #define FULL_REPAIR_RATE i2f(10)
851 //--unused-- ubyte save_control_type,save_movement_type;
853 //--unused-- int SideOrderBack[] = {WFRONT, WRIGHT, WTOP, WLEFT, WBOTTOM, WBACK};
854 //--unused-- int SideOrderFront[] = {WBACK, WLEFT, WTOP, WRIGHT, WBOTTOM, WFRONT};
855 //--unused-- int SideOrderLeft[] = { WRIGHT, WBACK, WTOP, WFRONT, WBOTTOM, WLEFT };
856 //--unused-- int SideOrderRight[] = { WLEFT, WFRONT, WTOP, WBACK, WBOTTOM, WRIGHT };
857 //--unused-- int SideOrderTop[] = { WBOTTOM, WLEFT, WBACK, WRIGHT, WFRONT, WTOP };
858 //--unused-- int SideOrderBottom[] = { WTOP, WLEFT, WFRONT, WRIGHT, WBACK, WBOTTOM };
860 //--unused-- int SideUpVector[] = {WBOTTOM, WFRONT, WBOTTOM, WFRONT, WBOTTOM, WBOTTOM };
862 //--repair-- // ----------------------------------------------------------------------------------------------------------
863 //--repair-- void refuel_calc_deltas(object *obj, int next_side, int repair_seg)
865 //--repair-- vms_vector nextcenter, headfvec, *headuvec;
866 //--repair-- vms_matrix goal_orient;
868 //--repair-- // Find time for this movement
869 //--repair-- delta_time = F1_0; // one second...
871 //--repair-- // Find start and goal position
872 //--repair-- start_pos = obj->pos;
874 //--repair-- // Find delta position to get to goal position
875 //--repair-- compute_segment_center(&goal_pos,&Segments[repair_seg]);
876 //--repair-- vm_vec_sub( &delta_pos,&goal_pos,&start_pos);
878 //--repair-- // Find start angles
879 //--repair-- //angles_from_vector(&start_angles,&obj->orient.fvec);
880 //--repair-- vm_extract_angles_matrix(&start_angles,&obj->orient);
882 //--repair-- // Find delta angles to get to goal orientation
883 //--repair-- med_compute_center_point_on_side(&nextcenter,&Segments[repair_seg],next_side);
884 //--repair-- vm_vec_sub(&headfvec,&nextcenter,&goal_pos);
885 //--repair-- //mprintf( (0, "Next_side = %d, Head fvec = %d,%d,%d\n", next_side, headfvec.x, headfvec.y, headfvec.z ));
887 //--repair-- if (next_side == 5) //last side
888 //--repair-- headuvec = &repair_save_uvec;
890 //--repair-- headuvec = &Segments[repair_seg].sides[SideUpVector[next_side]].normals[0];
892 //--repair-- vm_vector_2_matrix(&goal_orient,&headfvec,headuvec,NULL);
893 //--repair-- vm_extract_angles_matrix(&goal_angles,&goal_orient);
894 //--repair-- delta_angles.p = my_delta_ang(start_angles.p,goal_angles.p);
895 //--repair-- delta_angles.b = my_delta_ang(start_angles.b,goal_angles.b);
896 //--repair-- delta_angles.h = my_delta_ang(start_angles.h,goal_angles.h);
897 //--repair-- current_time = 0;
898 //--repair-- Repairing = 0;
901 //--repair-- // ----------------------------------------------------------------------------------------------------------
902 //--repair-- //if repairing, cut it short
903 //--repair-- abort_repair_center()
905 //--repair-- if (!RepairObj || side_index==5)
908 //--repair-- current_time = 0;
909 //--repair-- side_index = 5;
910 //--repair-- next_side = sidelist[side_index];
911 //--repair-- refuel_calc_deltas(RepairObj, next_side, FuelStationSeg);
914 //--repair-- // ----------------------------------------------------------------------------------------------------------
915 //--repair-- void repair_ship_damage()
917 //--repair-- //mprintf((0,"Repairing ship damage\n"));
920 //--repair-- // ----------------------------------------------------------------------------------------------------------
921 //--repair-- int refuel_do_repair_effect( object * obj, int first_time, int repair_seg ) {
923 //--repair-- obj->mtype.phys_info.velocity.x = 0;
924 //--repair-- obj->mtype.phys_info.velocity.y = 0;
925 //--repair-- obj->mtype.phys_info.velocity.z = 0;
927 //--repair-- if (first_time) {
928 //--repair-- int entry_side;
929 //--repair-- current_time = 0;
931 //--repair-- digi_play_sample( SOUND_REPAIR_STATION_PLAYER_ENTERING, F1_0 );
933 //--repair-- entry_side = john_find_connect_side(repair_seg,obj->segnum );
934 //--repair-- Assert( entry_side > -1 );
936 //--repair-- switch( entry_side ) {
937 //--repair-- case WBACK: sidelist = SideOrderBack; break;
938 //--repair-- case WFRONT: sidelist = SideOrderFront; break;
939 //--repair-- case WLEFT: sidelist = SideOrderLeft; break;
940 //--repair-- case WRIGHT: sidelist = SideOrderRight; break;
941 //--repair-- case WTOP: sidelist = SideOrderTop; break;
942 //--repair-- case WBOTTOM: sidelist = SideOrderBottom; break;
944 //--repair-- side_index = 0;
945 //--repair-- next_side = sidelist[side_index];
947 //--repair-- refuel_calc_deltas(obj,next_side, repair_seg);
950 //--repair-- //update shields
951 //--repair-- if (Players[Player_num].shields < MAX_SHIELDS) { //if above max, don't mess with it
953 //--repair-- Players[Player_num].shields += fixmul(FrameTime,repair_rate);
955 //--repair-- if (Players[Player_num].shields > MAX_SHIELDS)
956 //--repair-- Players[Player_num].shields = MAX_SHIELDS;
959 //--repair-- current_time += FrameTime;
961 //--repair-- if (current_time >= delta_time ) {
962 //--repair-- vms_angvec av;
963 //--repair-- obj->pos = goal_pos;
964 //--repair-- av = goal_angles;
965 //--repair-- vm_angles_2_matrix(&obj->orient,&av);
967 //--repair-- if (side_index >= 5 )
968 //--repair-- return 1; // Done being repaired...
970 //--repair-- if (Repairing==0) {
971 //--repair-- //mprintf( (0, "<MACHINE EFFECT ON SIDE %d>\n", next_side ));
972 //--repair-- //digi_play_sample( SOUND_REPAIR_STATION_FIXING );
973 //--repair-- Repairing=1;
975 //--repair-- switch( next_side ) {
976 //--repair-- case 0: digi_play_sample( SOUND_REPAIR_STATION_FIXING_1,F1_0 ); break;
977 //--repair-- case 1: digi_play_sample( SOUND_REPAIR_STATION_FIXING_2,F1_0 ); break;
978 //--repair-- case 2: digi_play_sample( SOUND_REPAIR_STATION_FIXING_3,F1_0 ); break;
979 //--repair-- case 3: digi_play_sample( SOUND_REPAIR_STATION_FIXING_4,F1_0 ); break;
980 //--repair-- case 4: digi_play_sample( SOUND_REPAIR_STATION_FIXING_1,F1_0 ); break;
981 //--repair-- case 5: digi_play_sample( SOUND_REPAIR_STATION_FIXING_2,F1_0 ); break;
984 //--repair-- repair_ship_damage();
988 //--repair-- if (current_time >= (delta_time+(F1_0/2)) ) {
989 //--repair-- current_time = 0;
990 //--repair-- // Find next side...
991 //--repair-- side_index++;
992 //--repair-- if (side_index >= 6 ) return 1;
993 //--repair-- next_side = sidelist[side_index];
995 //--repair-- refuel_calc_deltas(obj, next_side, repair_seg);
998 //--repair-- } else {
999 //--repair-- fix factor, p,b,h;
1000 //--repair-- vms_angvec av;
1002 //--repair-- factor = fixdiv( current_time,delta_time );
1004 //--repair-- // Find object's current position
1005 //--repair-- obj->pos = delta_pos;
1006 //--repair-- vm_vec_scale( &obj->pos, factor );
1007 //--repair-- vm_vec_add2( &obj->pos, &start_pos );
1009 //--repair-- // Find object's current orientation
1010 //--repair-- p = fixmul(delta_angles.p,factor);
1011 //--repair-- b = fixmul(delta_angles.b,factor);
1012 //--repair-- h = fixmul(delta_angles.h,factor);
1013 //--repair-- av.p = (fixang)p + start_angles.p;
1014 //--repair-- av.b = (fixang)b + start_angles.b;
1015 //--repair-- av.h = (fixang)h + start_angles.h;
1016 //--repair-- vm_angles_2_matrix(&obj->orient,&av);
1020 //--repair-- update_object_seg(obj); //update segment
1022 //--repair-- return 0;
1025 //--repair-- // ----------------------------------------------------------------------------------------------------------
1026 //--repair-- //do the repair center for this frame
1027 //--repair-- void do_repair_sequence(object *obj)
1029 //--repair-- Assert(obj == RepairObj);
1031 //--repair-- if (refuel_do_repair_effect( obj, 0, FuelStationSeg )) {
1032 //--repair-- if (Players[Player_num].shields < MAX_SHIELDS)
1033 //--repair-- Players[Player_num].shields = MAX_SHIELDS;
1034 //--repair-- obj->control_type = save_control_type;
1035 //--repair-- obj->movement_type = save_movement_type;
1036 //--repair-- disable_repair_center=1;
1037 //--repair-- RepairObj = NULL;
1040 //--repair-- //the two lines below will spit the player out of the rapair center,
1041 //--repair-- //but what happen is that the ship just bangs into the door
1042 //--repair-- //if (obj->movement_type == MT_PHYSICS)
1043 //--repair-- // vm_vec_copy_scale(&obj->mtype.phys_info.velocity,&obj->orient.fvec,i2f(200));
1048 //--repair-- // ----------------------------------------------------------------------------------------------------------
1049 //--repair-- //see if we should start the repair center
1050 //--repair-- void check_start_repair_center(object *obj)
1052 //--repair-- if (RepairObj != NULL) return; //already in repair center
1054 //--repair-- if (Lsegments[obj->segnum].special_type & SS_REPAIR_CENTER) {
1056 //--repair-- if (!disable_repair_center) {
1057 //--repair-- //have just entered repair center
1059 //--repair-- RepairObj = obj;
1060 //--repair-- repair_save_uvec = obj->orient.uvec;
1062 //--repair-- repair_rate = fixmuldiv(FULL_REPAIR_RATE,(MAX_SHIELDS - Players[Player_num].shields),MAX_SHIELDS);
1064 //--repair-- save_control_type = obj->control_type;
1065 //--repair-- save_movement_type = obj->movement_type;
1067 //--repair-- obj->control_type = CT_REPAIRCEN;
1068 //--repair-- obj->movement_type = MT_NONE;
1070 //--repair-- FuelStationSeg = Lsegments[obj->segnum].special_segment;
1071 //--repair-- Assert(FuelStationSeg != -1);
1073 //--repair-- if (refuel_do_repair_effect( obj, 1, FuelStationSeg )) {
1074 //--repair-- Int3(); //can this happen?
1075 //--repair-- obj->control_type = CT_FLYING;
1076 //--repair-- obj->movement_type = MT_PHYSICS;
1081 //--repair-- disable_repair_center=0;
1085 // --------------------------------------------------------------------------------------------
1086 void disable_matcens(void)
1090 for (i=0; i<Num_robot_centers; i++) {
1091 Station[i].Enabled = 0;
1092 Station[i].Disable_time = 0;
1096 // --------------------------------------------------------------------------------------------
1097 // Initialize all materialization centers.
1098 // Give them all the right number of lives.
1099 void init_all_matcens(void)
1103 for (i=0; i<Num_fuelcenters; i++)
1104 if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
1105 Station[i].Lives = 3;
1106 Station[i].Enabled = 0;
1107 Station[i].Disable_time = 0;
1110 // Make sure this fuelcen is pointed at by a matcen.
1112 for (j=0; j<Num_robot_centers; j++) {
1113 if (RobotCenters[j].fuelcen_num == i)
1116 Assert(j != Num_robot_centers);
1123 // Make sure all matcens point at a fuelcen
1124 for (i=0; i<Num_robot_centers; i++) {
1125 int fuelcen_num = RobotCenters[i].fuelcen_num;
1127 Assert(fuelcen_num < Num_fuelcenters);
1128 Assert(Station[fuelcen_num].Type == SEGMENT_IS_ROBOTMAKER);
1135 extern void multi_send_capture_bonus (char);
1137 void fuelcen_check_for_goal(segment *segp)
1139 segment2 *seg2p = &Segment2s[segp-Segments];
1141 Assert( segp != NULL );
1142 Assert (Game_mode & GM_CAPTURE);
1144 if (seg2p->special==SEGMENT_IS_GOAL_BLUE ) {
1146 if ((get_team(Player_num)==TEAM_BLUE) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1148 mprintf ((0,"In goal segment BLUE\n"));
1150 multi_send_capture_bonus (Player_num);
1151 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1152 maybe_drop_net_powerup (POW_FLAG_RED);
1155 if ( seg2p->special==SEGMENT_IS_GOAL_RED) {
1157 if ((get_team(Player_num)==TEAM_RED) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1159 mprintf ((0,"In goal segment RED\n"));
1160 multi_send_capture_bonus (Player_num);
1161 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1162 maybe_drop_net_powerup (POW_FLAG_BLUE);
1167 void fuelcen_check_for_hoard_goal(segment *segp)
1169 segment2 *seg2p = &Segment2s[segp-Segments];
1171 Assert( segp != NULL );
1172 Assert (Game_mode & GM_HOARD);
1177 if (seg2p->special==SEGMENT_IS_GOAL_BLUE || seg2p->special==SEGMENT_IS_GOAL_RED )
1179 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX])
1181 mprintf ((0,"In orb goal!\n"));
1182 multi_send_orb_bonus (Player_num);
1183 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1184 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]=0;
1192 #ifndef FAST_FILE_IO
1194 * reads an old_matcen_info structure from a CFILE
1196 void old_matcen_info_read(old_matcen_info *mi, CFILE *fp)
1198 mi->robot_flags = cfile_read_int(fp);
1199 mi->hit_points = cfile_read_fix(fp);
1200 mi->interval = cfile_read_fix(fp);
1201 mi->segnum = cfile_read_short(fp);
1202 mi->fuelcen_num = cfile_read_short(fp);
1206 * reads a matcen_info structure from a CFILE
1208 void matcen_info_read(matcen_info *mi, CFILE *fp)
1210 mi->robot_flags[0] = cfile_read_int(fp);
1211 mi->robot_flags[1] = cfile_read_int(fp);
1212 mi->hit_points = cfile_read_fix(fp);
1213 mi->interval = cfile_read_fix(fp);
1214 mi->segnum = cfile_read_short(fp);
1215 mi->fuelcen_num = cfile_read_short(fp);