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.
16 static char rcsid[] = "$Id: fuelcen.c,v 1.1.1.1 2001-01-19 03:29:59 bradleyb Exp $";
27 #include "game.h" // For FrameTime
52 // The max number of fuel stations per mine.
54 fix Fuelcen_refill_speed = i2f(1);
55 fix Fuelcen_give_amount = i2f(25);
56 fix Fuelcen_max_amount = i2f(100);
58 // Every time a robot is created in the morphing code, it decreases capacity of the morpher
59 // by this amount... when capacity gets to 0, no more morphers...
60 fix EnergyToCreateOneRobot = i2f(1);
62 #define MATCEN_HP_DEFAULT F1_0*500; // Hitpoints
63 #define MATCEN_INTERVAL_DEFAULT F1_0*5; // 5 seconds
65 matcen_info RobotCenters[MAX_ROBOT_CENTERS];
66 int Num_robot_centers;
68 FuelCenter Station[MAX_NUM_FUELCENS];
69 int Num_fuelcenters = 0;
71 segment * PlayerSegment= NULL;
74 char Special_names[MAX_CENTER_TYPES][11] = {
85 //------------------------------------------------------------
86 // Resets all fuel center info
92 //mprintf( (0, "All fuel centers reset.\n"));
94 for(i=0; i<MAX_SEGMENTS; i++ )
95 Segment2s[i].special = SEGMENT_IS_NOTHING;
97 Num_robot_centers = 0;
101 #ifndef NDEBUG //this is sometimes called by people from the debugger
102 void reset_all_robot_centers()
106 // Remove all materialization centers
107 for (i=0; i<Num_segments; i++)
108 if (Segment2s[i].special == SEGMENT_IS_ROBOTMAKER) {
109 Segment2s[i].special = SEGMENT_IS_NOTHING;
110 Segment2s[i].matcen_num = -1;
115 //------------------------------------------------------------
116 // Turns a segment into a fully charged up fuel center...
117 void fuelcen_create( segment *segp)
119 segment2 *seg2p = &Segment2s[segp-Segments];
123 station_type = seg2p->special;
125 switch( station_type ) {
126 case SEGMENT_IS_NOTHING:
127 case SEGMENT_IS_GOAL_BLUE:
128 case SEGMENT_IS_GOAL_RED:
130 case SEGMENT_IS_FUELCEN:
131 case SEGMENT_IS_REPAIRCEN:
132 case SEGMENT_IS_CONTROLCEN:
133 case SEGMENT_IS_ROBOTMAKER:
136 Error( "Invalid station type %d in fuelcen.c\n", station_type );
139 Assert( (seg2p != NULL) );
140 if ( seg2p == NULL ) return;
142 Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
143 Assert( Num_fuelcenters > -1 );
145 seg2p->value = Num_fuelcenters;
146 Station[Num_fuelcenters].Type = station_type;
147 Station[Num_fuelcenters].MaxCapacity = Fuelcen_max_amount;
148 Station[Num_fuelcenters].Capacity = Station[Num_fuelcenters].MaxCapacity;
149 Station[Num_fuelcenters].segnum = seg2p-Segment2s;
150 Station[Num_fuelcenters].Timer = -1;
151 Station[Num_fuelcenters].Flag = 0;
152 // Station[Num_fuelcenters].NextRobotType = -1;
153 // Station[Num_fuelcenters].last_created_obj=NULL;
154 // Station[Num_fuelcenters].last_created_sig = -1;
155 compute_segment_center(&Station[Num_fuelcenters].Center, segp);
157 // if (station_type == SEGMENT_IS_ROBOTMAKER)
158 // Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
160 //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
164 //------------------------------------------------------------
165 // Adds a matcen that already is a special type into the Station array.
166 // This function is separate from other fuelcens because we don't want values reset.
167 void matcen_create( segment *segp)
169 segment2 *seg2p = &Segment2s[segp-Segments];
171 int station_type = seg2p->special;
173 Assert( (seg2p != NULL) );
174 Assert(station_type == SEGMENT_IS_ROBOTMAKER);
175 if ( seg2p == NULL ) return;
177 Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
178 Assert( Num_fuelcenters > -1 );
180 seg2p->value = Num_fuelcenters;
181 Station[Num_fuelcenters].Type = station_type;
182 Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
183 Station[Num_fuelcenters].MaxCapacity = Station[Num_fuelcenters].Capacity;
185 Station[Num_fuelcenters].segnum = seg2p-Segment2s;
186 Station[Num_fuelcenters].Timer = -1;
187 Station[Num_fuelcenters].Flag = 0;
188 // Station[Num_fuelcenters].NextRobotType = -1;
189 // Station[Num_fuelcenters].last_created_obj=NULL;
190 // Station[Num_fuelcenters].last_created_sig = -1;
191 compute_segment_center(&Station[Num_fuelcenters].Center, &Segments[seg2p-Segment2s] );
193 seg2p->matcen_num = Num_robot_centers;
196 RobotCenters[seg2p->matcen_num].hit_points = MATCEN_HP_DEFAULT;
197 RobotCenters[seg2p->matcen_num].interval = MATCEN_INTERVAL_DEFAULT;
198 RobotCenters[seg2p->matcen_num].segnum = seg2p-Segment2s;
199 RobotCenters[seg2p->matcen_num].fuelcen_num = Num_fuelcenters;
201 //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
205 //------------------------------------------------------------
206 // Adds a segment that already is a special type into the Station array.
207 void fuelcen_activate( segment * segp, int station_type )
209 segment2 *seg2p = &Segment2s[segp-Segments];
211 seg2p->special = station_type;
213 if (seg2p->special == SEGMENT_IS_ROBOTMAKER)
214 matcen_create( segp);
216 fuelcen_create( segp);
220 // The lower this number is, the more quickly the center can be re-triggered.
221 // If it's too low, it can mean all the robots won't be put out, but for about 5
222 // robots, that's not real likely.
223 #define MATCEN_LIFE (i2f(30-2*Difficulty_level))
225 //------------------------------------------------------------
226 // Trigger (enable) the materialization center in segment segnum
227 void trigger_matcen(int segnum)
229 // -- segment *segp = &Segments[segnum];
230 segment2 *seg2p = &Segment2s[segnum];
231 vms_vector pos, delta;
232 FuelCenter *robotcen;
235 mprintf((0, "Trigger matcen, segment %i\n", segnum));
237 Assert(seg2p->special == SEGMENT_IS_ROBOTMAKER);
238 Assert(seg2p->matcen_num < Num_fuelcenters);
239 Assert((seg2p->matcen_num >= 0) && (seg2p->matcen_num <= Highest_segment_index));
241 robotcen = &Station[RobotCenters[seg2p->matcen_num].fuelcen_num];
243 if (robotcen->Enabled == 1)
246 if (!robotcen->Lives)
249 // MK: 11/18/95, At insane, matcens work forever!
250 if (Difficulty_level+1 < NDL)
253 robotcen->Timer = F1_0*1000; // Make sure the first robot gets emitted right away.
254 robotcen->Enabled = 1; // Say this center is enabled, it can create robots.
255 robotcen->Capacity = i2f(Difficulty_level + 3);
256 robotcen->Disable_time = MATCEN_LIFE;
258 // Create a bright object in the segment.
259 pos = robotcen->Center;
260 vm_vec_sub(&delta, &Vertices[Segments[segnum].verts[0]], &robotcen->Center);
261 vm_vec_scale_add2(&pos, &delta, F1_0/2);
262 objnum = obj_create( OBJ_LIGHT, 0, segnum, &pos, NULL, 0, CT_LIGHT, MT_NONE, RT_NONE );
264 Objects[objnum].lifeleft = MATCEN_LIFE;
265 Objects[objnum].ctype.light_info.intensity = i2f(8); // Light cast by a fuelcen.
267 mprintf((1, "Can't create invisible flare for matcen.\n"));
270 // 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)));
274 //------------------------------------------------------------
275 // Takes away a segment's fuel center properties.
276 // Deletes the segment point entry in the FuelCenter list.
277 void fuelcen_delete( segment * segp )
279 segment2 *seg2p = &Segment2s[segp-Segments];
286 for (i=0; i<Num_fuelcenters; i++ ) {
287 if ( Station[i].segnum == segp-Segments ) {
289 // If Robot maker is deleted, fix Segments and RobotCenters.
290 if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
292 Assert(Num_robot_centers >= 0);
294 for (j=seg2p->matcen_num; j<Num_robot_centers; j++)
295 RobotCenters[j] = RobotCenters[j+1];
297 for (j=0; j<Num_fuelcenters; j++) {
298 if ( Station[j].Type == SEGMENT_IS_ROBOTMAKER )
299 if ( Segment2s[Station[j].segnum].matcen_num > seg2p->matcen_num )
300 Segment2s[Station[j].segnum].matcen_num--;
304 //fix RobotCenters so they point to correct fuelcenter
305 for (j=0; j<Num_robot_centers; j++ )
306 if (RobotCenters[j].fuelcen_num > i) //this robotcenter's fuelcen is changing
307 RobotCenters[j].fuelcen_num--;
310 Assert(Num_fuelcenters >= 0);
311 for (j=i; j<Num_fuelcenters; j++ ) {
312 Station[j] = Station[j+1];
313 Segment2s[Station[j].segnum].value = j;
322 #define ROBOT_GEN_TIME (i2f(5))
324 object * create_morph_robot( segment *segp, vms_vector *object_pos, int object_id)
328 int default_behavior;
330 Players[Player_num].num_robots_level++;
331 Players[Player_num].num_robots_total++;
333 objnum = obj_create(OBJ_ROBOT, object_id, segp-Segments, object_pos,
334 &vmd_identity_matrix, Polygon_models[Robot_info[object_id].model_num].rad,
335 CT_AI, MT_PHYSICS, RT_POLYOBJ);
338 mprintf((1, "Can't create morph robot. Aborting morph.\n"));
343 obj = &Objects[objnum];
345 //Set polygon-object-specific data
347 obj->rtype.pobj_info.model_num = Robot_info[obj->id].model_num;
348 obj->rtype.pobj_info.subobj_flags = 0;
352 obj->mtype.phys_info.mass = Robot_info[obj->id].mass;
353 obj->mtype.phys_info.drag = Robot_info[obj->id].drag;
355 obj->mtype.phys_info.flags |= (PF_LEVELLING);
357 obj->shields = Robot_info[obj->id].strength;
359 default_behavior = Robot_info[obj->id].behavior;
361 init_ai_object(obj-Objects, default_behavior, -1 ); // Note, -1 = segment this robot goes to to hide, should probably be something useful
363 create_n_segment_path(obj, 6, -1); // Create a 6 segment path from creation point.
365 Ai_local_info[objnum].mode = ai_behavior_to_mode(default_behavior);
370 int Num_extry_robots = 15;
373 int FrameCount_last_msg = 0;
376 // ----------------------------------------------------------------------------------------------------------
377 void robotmaker_proc( FuelCenter * robotcen )
380 vms_vector cur_object_loc; //, direction;
381 int matcen_num, segnum, objnum;
384 vms_vector direction;
386 if (robotcen->Enabled == 0)
389 if (robotcen->Disable_time > 0) {
390 robotcen->Disable_time -= FrameTime;
391 if (robotcen->Disable_time <= 0) {
392 mprintf((0, "Robot center #%i gets disabled due to time running out.\n", robotcen-Station));
393 robotcen->Enabled = 0;
397 // mprintf((0, "Capacity of robot maker #%i is %i\n", robotcen - Station, robotcen->Capacity));
399 // No robot making in multiplayer mode.
402 if ((Game_mode & GM_MULTI) && (!(Game_mode & GM_MULTI_ROBOTS) || !network_i_am_master()))
405 if (Game_mode & GM_MULTI)
410 // Wait until transmorgafier has capacity to make a robot...
411 if ( robotcen->Capacity <= 0 ) {
415 matcen_num = Segment2s[robotcen->segnum].matcen_num;
416 //mprintf((0, "Robotmaker #%i flags = %8x\n", matcen_num, RobotCenters[matcen_num].robot_flags));
418 if ( matcen_num == -1 ) {
419 mprintf((0, "Non-functional robotcen at %d\n", robotcen->segnum));
423 if (RobotCenters[matcen_num].robot_flags[0]==0 && RobotCenters[matcen_num].robot_flags[1]==0) {
424 //mprintf((0, "robot_flags = 0 at robot maker #%i\n", RobotCenters[matcen_num].robot_flags));
428 // Wait until we have a free slot for this puppy...
429 // <<<<<<<<<<<<<<<< Num robots in mine >>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<< Max robots in mine >>>>>>>>>>>>>>>
430 if ( (Players[Player_num].num_robots_level - Players[Player_num].num_kills_level) >= (Gamesave_num_org_robots + Num_extry_robots ) ) {
432 if (FrameCount > FrameCount_last_msg + 20) {
433 mprintf((0, "Cannot morph until you kill one!\n"));
434 FrameCount_last_msg = FrameCount;
440 robotcen->Timer += FrameTime;
442 switch( robotcen->Flag ) {
443 case 0: // Wait until next robot can generate
444 if (Game_mode & GM_MULTI)
446 top_time = ROBOT_GEN_TIME;
450 dist_to_player = vm_vec_dist_quick( &ConsoleObject->pos, &robotcen->Center );
451 top_time = dist_to_player/64 + d_rand() * 2 + F1_0*2;
452 if ( top_time > ROBOT_GEN_TIME )
453 top_time = ROBOT_GEN_TIME + d_rand();
454 if ( top_time < F1_0*2 )
455 top_time = F1_0*3/2 + d_rand()*2;
458 // mprintf( (0, "Time between morphs %d seconds, dist_to_player = %7.3f\n", f2i(top_time), f2fl(dist_to_player) ));
460 if (robotcen->Timer > top_time ) {
462 int i, my_station_num = robotcen-Station;
465 // Make sure this robotmaker hasn't put out its max without having any of them killed.
466 for (i=0; i<=Highest_object_index; i++)
467 if (Objects[i].type == OBJ_ROBOT)
468 if ((Objects[i].matcen_creator^0x80) == my_station_num)
470 if (count > Difficulty_level + 3) {
471 mprintf((0, "Cannot morph: center %i has already put out %i robots.\n", my_station_num, count));
472 robotcen->Timer /= 2;
476 // Whack on any robot or player in the matcen segment.
478 segnum = robotcen->segnum;
479 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
481 if ( count > MAX_OBJECTS ) {
482 mprintf((0, "Object list in segment %d is circular.", segnum ));
486 if (Objects[objnum].type==OBJ_ROBOT) {
487 collide_robot_and_materialization_center(&Objects[objnum]);
488 robotcen->Timer = top_time/2;
490 } else if (Objects[objnum].type==OBJ_PLAYER ) {
491 collide_player_and_materialization_center(&Objects[objnum]);
492 robotcen->Timer = top_time/2;
497 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
498 // HACK!!! The 10 under here should be something equal to the 1/2 the size of the segment.
499 obj = object_create_explosion(robotcen->segnum, &cur_object_loc, i2f(10), VCLIP_MORPHING_ROBOT );
502 extract_orient_from_segment(&obj->orient,&Segments[robotcen->segnum]);
504 if ( Vclip[VCLIP_MORPHING_ROBOT].sound_num > -1 ) {
505 digi_link_sound_to_pos( Vclip[VCLIP_MORPHING_ROBOT].sound_num, robotcen->segnum, 0, &cur_object_loc, 0, F1_0 );
512 case 1: // Wait until 1/2 second after VCLIP started.
513 if (robotcen->Timer > (Vclip[VCLIP_MORPHING_ROBOT].play_time/2) ) {
515 robotcen->Capacity -= EnergyToCreateOneRobot;
519 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
521 // If this is the first materialization, set to valid robot.
522 if (RobotCenters[matcen_num].robot_flags[0] != 0 || RobotCenters[matcen_num].robot_flags[1] != 0) {
525 byte legal_types[64]; // 64 bits, the width of robot_flags[].
526 int num_types, robot_index, i;
531 flags = RobotCenters[matcen_num].robot_flags[i];
534 legal_types[num_types++] = robot_index;
540 //mprintf((0, "Flags = %08x, %2i legal types to morph: \n", RobotCenters[matcen_num].robot_flags, num_types));
541 //for (i=0; i<num_types; i++)
542 // mprintf((0, "%2i ", legal_types[i]));
543 //mprintf((0, "\n"));
546 type = legal_types[0];
548 type = legal_types[(d_rand() * num_types) / 32768];
550 mprintf((0, "Morph: (type = %i) (seg = %i) (capacity = %08x)\n", type, robotcen->segnum, robotcen->Capacity));
551 obj = create_morph_robot(&Segments[robotcen->segnum], &cur_object_loc, type );
555 if (Game_mode & GM_MULTI)
556 multi_send_create_robot(robotcen-Station, obj-Objects, type);
559 obj->matcen_creator = (robotcen-Station) | 0x80;
561 // Make object faces player...
562 vm_vec_sub( &direction, &ConsoleObject->pos,&obj->pos );
563 vm_vector_2_matrix( &obj->orient, &direction, &obj->orient.uvec, NULL);
566 //robotcen->last_created_obj = obj;
567 //robotcen->last_created_sig = robotcen->last_created_obj->signature;
569 mprintf((0, "Warning: create_morph_robot returned NULL (no objects left?)\n"));
582 //-------------------------------------------------------------
583 // Called once per frame, replenishes fuel supply.
584 void fuelcen_update_all()
587 fix AmountToreplenish;
589 AmountToreplenish = fixmul(FrameTime,Fuelcen_refill_speed);
591 for (i=0; i<Num_fuelcenters; i++ ) {
592 if ( Station[i].Type == SEGMENT_IS_ROBOTMAKER ) {
593 if (! (Game_suspended & SUSP_ROBOTS))
594 robotmaker_proc( &Station[i] );
595 } else if ( Station[i].Type == SEGMENT_IS_CONTROLCEN ) {
596 //controlcen_proc( &Station[i] );
598 } else if ( (Station[i].MaxCapacity > 0) && (PlayerSegment!=&Segments[Station[i].segnum]) ) {
599 if ( Station[i].Capacity < Station[i].MaxCapacity ) {
600 Station[i].Capacity += AmountToreplenish;
601 //mprintf( (0, "Fuel center %d replenished to %d.\n", i, f2i(Station[i].Capacity) ));
602 if ( Station[i].Capacity >= Station[i].MaxCapacity ) {
603 Station[i].Capacity = Station[i].MaxCapacity;
604 //gauge_message( "Fuel center is fully recharged! " );
611 //--unused-- //-------------------------------------------------------------
612 //--unused-- // replenishes all fuel supplies.
613 //--unused-- void fuelcen_replenish_all()
617 //--unused-- for (i=0; i<Num_fuelcenters; i++ ) {
618 //--unused-- Station[i].Capacity = Station[i].MaxCapacity;
620 //--unused-- //mprintf( (0, "All fuel centers are replenished\n" ));
624 #define FUELCEN_SOUND_DELAY (f1_0/4) //play every half second
626 //-------------------------------------------------------------
627 fix fuelcen_give_fuel(segment *segp, fix MaxAmountCanTake )
629 segment2 *seg2p = &Segment2s[segp-Segments];
631 static fix last_play_time=0;
633 Assert( segp != NULL );
635 PlayerSegment = segp;
637 if ( (segp) && (seg2p->special==SEGMENT_IS_FUELCEN) ) {
640 detect_escort_goal_accomplished(-4); // UGLY! Hack! -4 means went through fuelcen.
642 // if (Station[segp->value].MaxCapacity<=0) {
643 // HUD_init_message( "Fuelcenter %d is destroyed.", segp->value );
647 // if (Station[segp->value].Capacity<=0) {
648 // HUD_init_message( "Fuelcenter %d is empty.", segp->value );
652 if (MaxAmountCanTake <= 0 ) {
653 // //gauge_message( "Fueled up!");
657 amount = fixmul(FrameTime,Fuelcen_give_amount);
659 if (amount > MaxAmountCanTake )
660 amount = MaxAmountCanTake;
662 // if (!(Game_mode & GM_MULTI))
663 // if ( Station[segp->value].Capacity < amount ) {
664 // amount = Station[segp->value].Capacity;
665 // Station[segp->value].Capacity = 0;
667 // Station[segp->value].Capacity -= amount;
670 if (last_play_time > GameTime)
673 if (GameTime > last_play_time+FUELCEN_SOUND_DELAY) {
675 digi_play_sample( SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2 );
677 if (Game_mode & GM_MULTI)
678 multi_send_play_sound(SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2);
681 last_play_time = GameTime;
685 //HUD_init_message( "Fuelcen %d has %d/%d fuel", segp->value,f2i(Station[segp->value].Capacity),f2i(Station[segp->value].MaxCapacity) );
693 //--unused-- //-----------------------------------------------------------
694 //--unused-- // Damages a fuel center
695 //--unused-- void fuelcen_damage(segment *segp, fix damage )
697 //--unused-- //int i;
698 //--unused-- // int station_num = segp->value;
700 //--unused-- Assert( segp != NULL );
701 //--unused-- if ( segp == NULL ) return;
703 //--unused-- mprintf((0, "Obsolete function fuelcen_damage() called with seg=%i, damage=%7.3f\n", segp-Segments, f2fl(damage)));
704 //--unused-- switch( segp->special ) {
705 //--unused-- case SEGMENT_IS_NOTHING:
707 //--unused-- case SEGMENT_IS_ROBOTMAKER:
708 //--unused-- //-- // Robotmaker hit by laser
709 //--unused-- //-- if (Station[station_num].MaxCapacity<=0 ) {
710 //--unused-- //-- // Shooting a already destroyed materializer
711 //--unused-- //-- } else {
712 //--unused-- //-- Station[station_num].MaxCapacity -= damage;
713 //--unused-- //-- if (Station[station_num].Capacity > Station[station_num].MaxCapacity ) {
714 //--unused-- //-- Station[station_num].Capacity = Station[station_num].MaxCapacity;
716 //--unused-- //-- if (Station[station_num].MaxCapacity <= 0 ) {
717 //--unused-- //-- Station[station_num].MaxCapacity = 0;
718 //--unused-- //-- // Robotmaker dead
719 //--unused-- //-- for (i=0; i<6; i++ )
720 //--unused-- //-- segp->sides[i].tmap_num2 = 0;
723 //--unused-- //-- //mprintf( (0, "Materializatormografier has %x capacity left\n", Station[station_num].MaxCapacity ));
725 //--unused-- case SEGMENT_IS_FUELCEN:
726 //--unused-- //-- digi_play_sample( SOUND_REFUEL_STATION_HIT );
727 //--unused-- //-- if (Station[station_num].MaxCapacity>0 ) {
728 //--unused-- //-- Station[station_num].MaxCapacity -= damage;
729 //--unused-- //-- if (Station[station_num].Capacity > Station[station_num].MaxCapacity ) {
730 //--unused-- //-- Station[station_num].Capacity = Station[station_num].MaxCapacity;
732 //--unused-- //-- if (Station[station_num].MaxCapacity <= 0 ) {
733 //--unused-- //-- Station[station_num].MaxCapacity = 0;
734 //--unused-- //-- digi_play_sample( SOUND_REFUEL_STATION_DESTROYED );
736 //--unused-- //-- } else {
737 //--unused-- //-- Station[station_num].MaxCapacity = 0;
739 //--unused-- //-- HUD_init_message( "Fuelcenter %d damaged", station_num );
741 //--unused-- case SEGMENT_IS_REPAIRCEN:
743 //--unused-- case SEGMENT_IS_CONTROLCEN:
745 //--unused-- default:
746 //--unused-- Error( "Invalid type in fuelcen.c" );
750 //--unused-- // ----------------------------------------------------------------------------------------------------------
751 //--unused-- fixang my_delta_ang(fixang a,fixang b)
753 //--unused-- fixang delta0,delta1;
755 //--unused-- return (abs(delta0 = a - b) < abs(delta1 = b - a)) ? delta0 : delta1;
759 //--unused-- // ----------------------------------------------------------------------------------------------------------
760 //--unused-- //return though which side of seg0 is seg1
761 //--unused-- int john_find_connect_side(int seg0,int seg1)
763 //--unused-- segment *Seg=&Segments[seg0];
766 //--unused-- for (i=MAX_SIDES_PER_SEGMENT;i--;) if (Seg->children[i]==seg1) return i;
768 //--unused-- return -1;
771 // ----------------------------------------------------------------------------------------------------------
772 //--unused-- vms_angvec start_angles, delta_angles, goal_angles;
773 //--unused-- vms_vector start_pos, delta_pos, goal_pos;
774 //--unused-- int FuelStationSeg;
775 //--unused-- fix current_time,delta_time;
776 //--unused-- int next_side, side_index;
777 //--unused-- int * sidelist;
779 //--repair-- int Repairing;
780 //--repair-- vms_vector repair_save_uvec; //the player's upvec when enter repaircen
781 //--repair-- object *RepairObj=NULL; //which object getting repaired
782 //--repair-- int disable_repair_center=0;
783 //--repair-- fix repair_rate;
784 //--repair-- #define FULL_REPAIR_RATE i2f(10)
786 //--unused-- ubyte save_control_type,save_movement_type;
788 //--unused-- int SideOrderBack[] = {WFRONT, WRIGHT, WTOP, WLEFT, WBOTTOM, WBACK};
789 //--unused-- int SideOrderFront[] = {WBACK, WLEFT, WTOP, WRIGHT, WBOTTOM, WFRONT};
790 //--unused-- int SideOrderLeft[] = { WRIGHT, WBACK, WTOP, WFRONT, WBOTTOM, WLEFT };
791 //--unused-- int SideOrderRight[] = { WLEFT, WFRONT, WTOP, WBACK, WBOTTOM, WRIGHT };
792 //--unused-- int SideOrderTop[] = { WBOTTOM, WLEFT, WBACK, WRIGHT, WFRONT, WTOP };
793 //--unused-- int SideOrderBottom[] = { WTOP, WLEFT, WFRONT, WRIGHT, WBACK, WBOTTOM };
795 //--unused-- int SideUpVector[] = {WBOTTOM, WFRONT, WBOTTOM, WFRONT, WBOTTOM, WBOTTOM };
797 //--repair-- // ----------------------------------------------------------------------------------------------------------
798 //--repair-- void refuel_calc_deltas(object *obj, int next_side, int repair_seg)
800 //--repair-- vms_vector nextcenter, headfvec, *headuvec;
801 //--repair-- vms_matrix goal_orient;
803 //--repair-- // Find time for this movement
804 //--repair-- delta_time = F1_0; // one second...
806 //--repair-- // Find start and goal position
807 //--repair-- start_pos = obj->pos;
809 //--repair-- // Find delta position to get to goal position
810 //--repair-- compute_segment_center(&goal_pos,&Segments[repair_seg]);
811 //--repair-- vm_vec_sub( &delta_pos,&goal_pos,&start_pos);
813 //--repair-- // Find start angles
814 //--repair-- //angles_from_vector(&start_angles,&obj->orient.fvec);
815 //--repair-- vm_extract_angles_matrix(&start_angles,&obj->orient);
817 //--repair-- // Find delta angles to get to goal orientation
818 //--repair-- med_compute_center_point_on_side(&nextcenter,&Segments[repair_seg],next_side);
819 //--repair-- vm_vec_sub(&headfvec,&nextcenter,&goal_pos);
820 //--repair-- //mprintf( (0, "Next_side = %d, Head fvec = %d,%d,%d\n", next_side, headfvec.x, headfvec.y, headfvec.z ));
822 //--repair-- if (next_side == 5) //last side
823 //--repair-- headuvec = &repair_save_uvec;
825 //--repair-- headuvec = &Segments[repair_seg].sides[SideUpVector[next_side]].normals[0];
827 //--repair-- vm_vector_2_matrix(&goal_orient,&headfvec,headuvec,NULL);
828 //--repair-- vm_extract_angles_matrix(&goal_angles,&goal_orient);
829 //--repair-- delta_angles.p = my_delta_ang(start_angles.p,goal_angles.p);
830 //--repair-- delta_angles.b = my_delta_ang(start_angles.b,goal_angles.b);
831 //--repair-- delta_angles.h = my_delta_ang(start_angles.h,goal_angles.h);
832 //--repair-- current_time = 0;
833 //--repair-- Repairing = 0;
836 //--repair-- // ----------------------------------------------------------------------------------------------------------
837 //--repair-- //if repairing, cut it short
838 //--repair-- abort_repair_center()
840 //--repair-- if (!RepairObj || side_index==5)
843 //--repair-- current_time = 0;
844 //--repair-- side_index = 5;
845 //--repair-- next_side = sidelist[side_index];
846 //--repair-- refuel_calc_deltas(RepairObj, next_side, FuelStationSeg);
849 //--repair-- // ----------------------------------------------------------------------------------------------------------
850 //--repair-- void repair_ship_damage()
852 //--repair-- //mprintf((0,"Repairing ship damage\n"));
855 //--repair-- // ----------------------------------------------------------------------------------------------------------
856 //--repair-- int refuel_do_repair_effect( object * obj, int first_time, int repair_seg ) {
858 //--repair-- obj->mtype.phys_info.velocity.x = 0;
859 //--repair-- obj->mtype.phys_info.velocity.y = 0;
860 //--repair-- obj->mtype.phys_info.velocity.z = 0;
862 //--repair-- if (first_time) {
863 //--repair-- int entry_side;
864 //--repair-- current_time = 0;
866 //--repair-- digi_play_sample( SOUND_REPAIR_STATION_PLAYER_ENTERING, F1_0 );
868 //--repair-- entry_side = john_find_connect_side(repair_seg,obj->segnum );
869 //--repair-- Assert( entry_side > -1 );
871 //--repair-- switch( entry_side ) {
872 //--repair-- case WBACK: sidelist = SideOrderBack; break;
873 //--repair-- case WFRONT: sidelist = SideOrderFront; break;
874 //--repair-- case WLEFT: sidelist = SideOrderLeft; break;
875 //--repair-- case WRIGHT: sidelist = SideOrderRight; break;
876 //--repair-- case WTOP: sidelist = SideOrderTop; break;
877 //--repair-- case WBOTTOM: sidelist = SideOrderBottom; break;
879 //--repair-- side_index = 0;
880 //--repair-- next_side = sidelist[side_index];
882 //--repair-- refuel_calc_deltas(obj,next_side, repair_seg);
885 //--repair-- //update shields
886 //--repair-- if (Players[Player_num].shields < MAX_SHIELDS) { //if above max, don't mess with it
888 //--repair-- Players[Player_num].shields += fixmul(FrameTime,repair_rate);
890 //--repair-- if (Players[Player_num].shields > MAX_SHIELDS)
891 //--repair-- Players[Player_num].shields = MAX_SHIELDS;
894 //--repair-- current_time += FrameTime;
896 //--repair-- if (current_time >= delta_time ) {
897 //--repair-- vms_angvec av;
898 //--repair-- obj->pos = goal_pos;
899 //--repair-- av = goal_angles;
900 //--repair-- vm_angles_2_matrix(&obj->orient,&av);
902 //--repair-- if (side_index >= 5 )
903 //--repair-- return 1; // Done being repaired...
905 //--repair-- if (Repairing==0) {
906 //--repair-- //mprintf( (0, "<MACHINE EFFECT ON SIDE %d>\n", next_side ));
907 //--repair-- //digi_play_sample( SOUND_REPAIR_STATION_FIXING );
908 //--repair-- Repairing=1;
910 //--repair-- switch( next_side ) {
911 //--repair-- case 0: digi_play_sample( SOUND_REPAIR_STATION_FIXING_1,F1_0 ); break;
912 //--repair-- case 1: digi_play_sample( SOUND_REPAIR_STATION_FIXING_2,F1_0 ); break;
913 //--repair-- case 2: digi_play_sample( SOUND_REPAIR_STATION_FIXING_3,F1_0 ); break;
914 //--repair-- case 3: digi_play_sample( SOUND_REPAIR_STATION_FIXING_4,F1_0 ); break;
915 //--repair-- case 4: digi_play_sample( SOUND_REPAIR_STATION_FIXING_1,F1_0 ); break;
916 //--repair-- case 5: digi_play_sample( SOUND_REPAIR_STATION_FIXING_2,F1_0 ); break;
919 //--repair-- repair_ship_damage();
923 //--repair-- if (current_time >= (delta_time+(F1_0/2)) ) {
924 //--repair-- current_time = 0;
925 //--repair-- // Find next side...
926 //--repair-- side_index++;
927 //--repair-- if (side_index >= 6 ) return 1;
928 //--repair-- next_side = sidelist[side_index];
930 //--repair-- refuel_calc_deltas(obj, next_side, repair_seg);
933 //--repair-- } else {
934 //--repair-- fix factor, p,b,h;
935 //--repair-- vms_angvec av;
937 //--repair-- factor = fixdiv( current_time,delta_time );
939 //--repair-- // Find object's current position
940 //--repair-- obj->pos = delta_pos;
941 //--repair-- vm_vec_scale( &obj->pos, factor );
942 //--repair-- vm_vec_add2( &obj->pos, &start_pos );
944 //--repair-- // Find object's current orientation
945 //--repair-- p = fixmul(delta_angles.p,factor);
946 //--repair-- b = fixmul(delta_angles.b,factor);
947 //--repair-- h = fixmul(delta_angles.h,factor);
948 //--repair-- av.p = (fixang)p + start_angles.p;
949 //--repair-- av.b = (fixang)b + start_angles.b;
950 //--repair-- av.h = (fixang)h + start_angles.h;
951 //--repair-- vm_angles_2_matrix(&obj->orient,&av);
955 //--repair-- update_object_seg(obj); //update segment
957 //--repair-- return 0;
960 //--repair-- // ----------------------------------------------------------------------------------------------------------
961 //--repair-- //do the repair center for this frame
962 //--repair-- void do_repair_sequence(object *obj)
964 //--repair-- Assert(obj == RepairObj);
966 //--repair-- if (refuel_do_repair_effect( obj, 0, FuelStationSeg )) {
967 //--repair-- if (Players[Player_num].shields < MAX_SHIELDS)
968 //--repair-- Players[Player_num].shields = MAX_SHIELDS;
969 //--repair-- obj->control_type = save_control_type;
970 //--repair-- obj->movement_type = save_movement_type;
971 //--repair-- disable_repair_center=1;
972 //--repair-- RepairObj = NULL;
975 //--repair-- //the two lines below will spit the player out of the rapair center,
976 //--repair-- //but what happen is that the ship just bangs into the door
977 //--repair-- //if (obj->movement_type == MT_PHYSICS)
978 //--repair-- // vm_vec_copy_scale(&obj->mtype.phys_info.velocity,&obj->orient.fvec,i2f(200));
983 //--repair-- // ----------------------------------------------------------------------------------------------------------
984 //--repair-- //see if we should start the repair center
985 //--repair-- void check_start_repair_center(object *obj)
987 //--repair-- if (RepairObj != NULL) return; //already in repair center
989 //--repair-- if (Lsegments[obj->segnum].special_type & SS_REPAIR_CENTER) {
991 //--repair-- if (!disable_repair_center) {
992 //--repair-- //have just entered repair center
994 //--repair-- RepairObj = obj;
995 //--repair-- repair_save_uvec = obj->orient.uvec;
997 //--repair-- repair_rate = fixmuldiv(FULL_REPAIR_RATE,(MAX_SHIELDS - Players[Player_num].shields),MAX_SHIELDS);
999 //--repair-- save_control_type = obj->control_type;
1000 //--repair-- save_movement_type = obj->movement_type;
1002 //--repair-- obj->control_type = CT_REPAIRCEN;
1003 //--repair-- obj->movement_type = MT_NONE;
1005 //--repair-- FuelStationSeg = Lsegments[obj->segnum].special_segment;
1006 //--repair-- Assert(FuelStationSeg != -1);
1008 //--repair-- if (refuel_do_repair_effect( obj, 1, FuelStationSeg )) {
1009 //--repair-- Int3(); //can this happen?
1010 //--repair-- obj->control_type = CT_FLYING;
1011 //--repair-- obj->movement_type = MT_PHYSICS;
1016 //--repair-- disable_repair_center=0;
1020 // --------------------------------------------------------------------------------------------
1021 void disable_matcens(void)
1025 for (i=0; i<Num_robot_centers; i++) {
1026 Station[i].Enabled = 0;
1027 Station[i].Disable_time = 0;
1031 // --------------------------------------------------------------------------------------------
1032 // Initialize all materialization centers.
1033 // Give them all the right number of lives.
1034 void init_all_matcens(void)
1038 for (i=0; i<Num_fuelcenters; i++)
1039 if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
1040 Station[i].Lives = 3;
1041 Station[i].Enabled = 0;
1042 Station[i].Disable_time = 0;
1045 // Make sure this fuelcen is pointed at by a matcen.
1047 for (j=0; j<Num_robot_centers; j++) {
1048 if (RobotCenters[j].fuelcen_num == i)
1051 Assert(j != Num_robot_centers);
1058 // Make sure all matcens point at a fuelcen
1059 for (i=0; i<Num_robot_centers; i++) {
1060 int fuelcen_num = RobotCenters[i].fuelcen_num;
1062 Assert(fuelcen_num < Num_fuelcenters);
1063 Assert(Station[fuelcen_num].Type == SEGMENT_IS_ROBOTMAKER);
1070 extern void multi_send_capture_bonus (char);
1072 void fuelcen_check_for_goal(segment *segp)
1074 segment2 *seg2p = &Segment2s[segp-Segments];
1076 Assert( segp != NULL );
1077 Assert (Game_mode & GM_CAPTURE);
1079 if (seg2p->special==SEGMENT_IS_GOAL_BLUE ) {
1081 if ((get_team(Player_num)==TEAM_BLUE) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1083 mprintf ((0,"In goal segment BLUE\n"));
1085 multi_send_capture_bonus (Player_num);
1086 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1087 maybe_drop_net_powerup (POW_FLAG_RED);
1090 if ( seg2p->special==SEGMENT_IS_GOAL_RED) {
1092 if ((get_team(Player_num)==TEAM_RED) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1094 mprintf ((0,"In goal segment RED\n"));
1095 multi_send_capture_bonus (Player_num);
1096 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1097 maybe_drop_net_powerup (POW_FLAG_BLUE);
1102 void fuelcen_check_for_hoard_goal(segment *segp)
1104 segment2 *seg2p = &Segment2s[segp-Segments];
1106 Assert( segp != NULL );
1107 Assert (Game_mode & GM_HOARD);
1112 if (seg2p->special==SEGMENT_IS_GOAL_BLUE || seg2p->special==SEGMENT_IS_GOAL_RED )
1114 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX])
1116 mprintf ((0,"In orb goal!\n"));
1117 multi_send_orb_bonus (Player_num);
1118 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1119 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]=0;