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.2 2001-01-31 15:17:50 bradleyb Exp $";
29 #include "game.h" // For FrameTime
54 // The max number of fuel stations per mine.
56 fix Fuelcen_refill_speed = i2f(1);
57 fix Fuelcen_give_amount = i2f(25);
58 fix Fuelcen_max_amount = i2f(100);
60 // Every time a robot is created in the morphing code, it decreases capacity of the morpher
61 // by this amount... when capacity gets to 0, no more morphers...
62 fix EnergyToCreateOneRobot = i2f(1);
64 #define MATCEN_HP_DEFAULT F1_0*500; // Hitpoints
65 #define MATCEN_INTERVAL_DEFAULT F1_0*5; // 5 seconds
67 matcen_info RobotCenters[MAX_ROBOT_CENTERS];
68 int Num_robot_centers;
70 FuelCenter Station[MAX_NUM_FUELCENS];
71 int Num_fuelcenters = 0;
73 segment * PlayerSegment= NULL;
76 char Special_names[MAX_CENTER_TYPES][11] = {
87 //------------------------------------------------------------
88 // Resets all fuel center info
94 //mprintf( (0, "All fuel centers reset.\n"));
96 for(i=0; i<MAX_SEGMENTS; i++ )
97 Segment2s[i].special = SEGMENT_IS_NOTHING;
99 Num_robot_centers = 0;
103 #ifndef NDEBUG //this is sometimes called by people from the debugger
104 void reset_all_robot_centers()
108 // Remove all materialization centers
109 for (i=0; i<Num_segments; i++)
110 if (Segment2s[i].special == SEGMENT_IS_ROBOTMAKER) {
111 Segment2s[i].special = SEGMENT_IS_NOTHING;
112 Segment2s[i].matcen_num = -1;
117 //------------------------------------------------------------
118 // Turns a segment into a fully charged up fuel center...
119 void fuelcen_create( segment *segp)
121 segment2 *seg2p = &Segment2s[segp-Segments];
125 station_type = seg2p->special;
127 switch( station_type ) {
128 case SEGMENT_IS_NOTHING:
129 case SEGMENT_IS_GOAL_BLUE:
130 case SEGMENT_IS_GOAL_RED:
132 case SEGMENT_IS_FUELCEN:
133 case SEGMENT_IS_REPAIRCEN:
134 case SEGMENT_IS_CONTROLCEN:
135 case SEGMENT_IS_ROBOTMAKER:
138 Error( "Invalid station type %d in fuelcen.c\n", station_type );
141 Assert( (seg2p != NULL) );
142 if ( seg2p == NULL ) return;
144 Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
145 Assert( Num_fuelcenters > -1 );
147 seg2p->value = Num_fuelcenters;
148 Station[Num_fuelcenters].Type = station_type;
149 Station[Num_fuelcenters].MaxCapacity = Fuelcen_max_amount;
150 Station[Num_fuelcenters].Capacity = Station[Num_fuelcenters].MaxCapacity;
151 Station[Num_fuelcenters].segnum = seg2p-Segment2s;
152 Station[Num_fuelcenters].Timer = -1;
153 Station[Num_fuelcenters].Flag = 0;
154 // Station[Num_fuelcenters].NextRobotType = -1;
155 // Station[Num_fuelcenters].last_created_obj=NULL;
156 // Station[Num_fuelcenters].last_created_sig = -1;
157 compute_segment_center(&Station[Num_fuelcenters].Center, segp);
159 // if (station_type == SEGMENT_IS_ROBOTMAKER)
160 // Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
162 //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
166 //------------------------------------------------------------
167 // Adds a matcen that already is a special type into the Station array.
168 // This function is separate from other fuelcens because we don't want values reset.
169 void matcen_create( segment *segp)
171 segment2 *seg2p = &Segment2s[segp-Segments];
173 int station_type = seg2p->special;
175 Assert( (seg2p != NULL) );
176 Assert(station_type == SEGMENT_IS_ROBOTMAKER);
177 if ( seg2p == NULL ) return;
179 Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
180 Assert( Num_fuelcenters > -1 );
182 seg2p->value = Num_fuelcenters;
183 Station[Num_fuelcenters].Type = station_type;
184 Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
185 Station[Num_fuelcenters].MaxCapacity = Station[Num_fuelcenters].Capacity;
187 Station[Num_fuelcenters].segnum = seg2p-Segment2s;
188 Station[Num_fuelcenters].Timer = -1;
189 Station[Num_fuelcenters].Flag = 0;
190 // Station[Num_fuelcenters].NextRobotType = -1;
191 // Station[Num_fuelcenters].last_created_obj=NULL;
192 // Station[Num_fuelcenters].last_created_sig = -1;
193 compute_segment_center(&Station[Num_fuelcenters].Center, &Segments[seg2p-Segment2s] );
195 seg2p->matcen_num = Num_robot_centers;
198 RobotCenters[seg2p->matcen_num].hit_points = MATCEN_HP_DEFAULT;
199 RobotCenters[seg2p->matcen_num].interval = MATCEN_INTERVAL_DEFAULT;
200 RobotCenters[seg2p->matcen_num].segnum = seg2p-Segment2s;
201 RobotCenters[seg2p->matcen_num].fuelcen_num = Num_fuelcenters;
203 //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
207 //------------------------------------------------------------
208 // Adds a segment that already is a special type into the Station array.
209 void fuelcen_activate( segment * segp, int station_type )
211 segment2 *seg2p = &Segment2s[segp-Segments];
213 seg2p->special = station_type;
215 if (seg2p->special == SEGMENT_IS_ROBOTMAKER)
216 matcen_create( segp);
218 fuelcen_create( segp);
222 // The lower this number is, the more quickly the center can be re-triggered.
223 // If it's too low, it can mean all the robots won't be put out, but for about 5
224 // robots, that's not real likely.
225 #define MATCEN_LIFE (i2f(30-2*Difficulty_level))
227 //------------------------------------------------------------
228 // Trigger (enable) the materialization center in segment segnum
229 void trigger_matcen(int segnum)
231 // -- segment *segp = &Segments[segnum];
232 segment2 *seg2p = &Segment2s[segnum];
233 vms_vector pos, delta;
234 FuelCenter *robotcen;
237 mprintf((0, "Trigger matcen, segment %i\n", segnum));
239 Assert(seg2p->special == SEGMENT_IS_ROBOTMAKER);
240 Assert(seg2p->matcen_num < Num_fuelcenters);
241 Assert((seg2p->matcen_num >= 0) && (seg2p->matcen_num <= Highest_segment_index));
243 robotcen = &Station[RobotCenters[seg2p->matcen_num].fuelcen_num];
245 if (robotcen->Enabled == 1)
248 if (!robotcen->Lives)
251 // MK: 11/18/95, At insane, matcens work forever!
252 if (Difficulty_level+1 < NDL)
255 robotcen->Timer = F1_0*1000; // Make sure the first robot gets emitted right away.
256 robotcen->Enabled = 1; // Say this center is enabled, it can create robots.
257 robotcen->Capacity = i2f(Difficulty_level + 3);
258 robotcen->Disable_time = MATCEN_LIFE;
260 // Create a bright object in the segment.
261 pos = robotcen->Center;
262 vm_vec_sub(&delta, &Vertices[Segments[segnum].verts[0]], &robotcen->Center);
263 vm_vec_scale_add2(&pos, &delta, F1_0/2);
264 objnum = obj_create( OBJ_LIGHT, 0, segnum, &pos, NULL, 0, CT_LIGHT, MT_NONE, RT_NONE );
266 Objects[objnum].lifeleft = MATCEN_LIFE;
267 Objects[objnum].ctype.light_info.intensity = i2f(8); // Light cast by a fuelcen.
269 mprintf((1, "Can't create invisible flare for matcen.\n"));
272 // 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)));
276 //------------------------------------------------------------
277 // Takes away a segment's fuel center properties.
278 // Deletes the segment point entry in the FuelCenter list.
279 void fuelcen_delete( segment * segp )
281 segment2 *seg2p = &Segment2s[segp-Segments];
288 for (i=0; i<Num_fuelcenters; i++ ) {
289 if ( Station[i].segnum == segp-Segments ) {
291 // If Robot maker is deleted, fix Segments and RobotCenters.
292 if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
294 Assert(Num_robot_centers >= 0);
296 for (j=seg2p->matcen_num; j<Num_robot_centers; j++)
297 RobotCenters[j] = RobotCenters[j+1];
299 for (j=0; j<Num_fuelcenters; j++) {
300 if ( Station[j].Type == SEGMENT_IS_ROBOTMAKER )
301 if ( Segment2s[Station[j].segnum].matcen_num > seg2p->matcen_num )
302 Segment2s[Station[j].segnum].matcen_num--;
306 //fix RobotCenters so they point to correct fuelcenter
307 for (j=0; j<Num_robot_centers; j++ )
308 if (RobotCenters[j].fuelcen_num > i) //this robotcenter's fuelcen is changing
309 RobotCenters[j].fuelcen_num--;
312 Assert(Num_fuelcenters >= 0);
313 for (j=i; j<Num_fuelcenters; j++ ) {
314 Station[j] = Station[j+1];
315 Segment2s[Station[j].segnum].value = j;
324 #define ROBOT_GEN_TIME (i2f(5))
326 object * create_morph_robot( segment *segp, vms_vector *object_pos, int object_id)
330 int default_behavior;
332 Players[Player_num].num_robots_level++;
333 Players[Player_num].num_robots_total++;
335 objnum = obj_create(OBJ_ROBOT, object_id, segp-Segments, object_pos,
336 &vmd_identity_matrix, Polygon_models[Robot_info[object_id].model_num].rad,
337 CT_AI, MT_PHYSICS, RT_POLYOBJ);
340 mprintf((1, "Can't create morph robot. Aborting morph.\n"));
345 obj = &Objects[objnum];
347 //Set polygon-object-specific data
349 obj->rtype.pobj_info.model_num = Robot_info[obj->id].model_num;
350 obj->rtype.pobj_info.subobj_flags = 0;
354 obj->mtype.phys_info.mass = Robot_info[obj->id].mass;
355 obj->mtype.phys_info.drag = Robot_info[obj->id].drag;
357 obj->mtype.phys_info.flags |= (PF_LEVELLING);
359 obj->shields = Robot_info[obj->id].strength;
361 default_behavior = Robot_info[obj->id].behavior;
363 init_ai_object(obj-Objects, default_behavior, -1 ); // Note, -1 = segment this robot goes to to hide, should probably be something useful
365 create_n_segment_path(obj, 6, -1); // Create a 6 segment path from creation point.
367 Ai_local_info[objnum].mode = ai_behavior_to_mode(default_behavior);
372 int Num_extry_robots = 15;
375 int FrameCount_last_msg = 0;
378 // ----------------------------------------------------------------------------------------------------------
379 void robotmaker_proc( FuelCenter * robotcen )
382 vms_vector cur_object_loc; //, direction;
383 int matcen_num, segnum, objnum;
386 vms_vector direction;
388 if (robotcen->Enabled == 0)
391 if (robotcen->Disable_time > 0) {
392 robotcen->Disable_time -= FrameTime;
393 if (robotcen->Disable_time <= 0) {
394 mprintf((0, "Robot center #%i gets disabled due to time running out.\n", robotcen-Station));
395 robotcen->Enabled = 0;
399 // mprintf((0, "Capacity of robot maker #%i is %i\n", robotcen - Station, robotcen->Capacity));
401 // No robot making in multiplayer mode.
404 if ((Game_mode & GM_MULTI) && (!(Game_mode & GM_MULTI_ROBOTS) || !network_i_am_master()))
407 if (Game_mode & GM_MULTI)
412 // Wait until transmorgafier has capacity to make a robot...
413 if ( robotcen->Capacity <= 0 ) {
417 matcen_num = Segment2s[robotcen->segnum].matcen_num;
418 //mprintf((0, "Robotmaker #%i flags = %8x\n", matcen_num, RobotCenters[matcen_num].robot_flags));
420 if ( matcen_num == -1 ) {
421 mprintf((0, "Non-functional robotcen at %d\n", robotcen->segnum));
425 if (RobotCenters[matcen_num].robot_flags[0]==0 && RobotCenters[matcen_num].robot_flags[1]==0) {
426 //mprintf((0, "robot_flags = 0 at robot maker #%i\n", RobotCenters[matcen_num].robot_flags));
430 // Wait until we have a free slot for this puppy...
431 // <<<<<<<<<<<<<<<< Num robots in mine >>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<< Max robots in mine >>>>>>>>>>>>>>>
432 if ( (Players[Player_num].num_robots_level - Players[Player_num].num_kills_level) >= (Gamesave_num_org_robots + Num_extry_robots ) ) {
434 if (FrameCount > FrameCount_last_msg + 20) {
435 mprintf((0, "Cannot morph until you kill one!\n"));
436 FrameCount_last_msg = FrameCount;
442 robotcen->Timer += FrameTime;
444 switch( robotcen->Flag ) {
445 case 0: // Wait until next robot can generate
446 if (Game_mode & GM_MULTI)
448 top_time = ROBOT_GEN_TIME;
452 dist_to_player = vm_vec_dist_quick( &ConsoleObject->pos, &robotcen->Center );
453 top_time = dist_to_player/64 + d_rand() * 2 + F1_0*2;
454 if ( top_time > ROBOT_GEN_TIME )
455 top_time = ROBOT_GEN_TIME + d_rand();
456 if ( top_time < F1_0*2 )
457 top_time = F1_0*3/2 + d_rand()*2;
460 // mprintf( (0, "Time between morphs %d seconds, dist_to_player = %7.3f\n", f2i(top_time), f2fl(dist_to_player) ));
462 if (robotcen->Timer > top_time ) {
464 int i, my_station_num = robotcen-Station;
467 // Make sure this robotmaker hasn't put out its max without having any of them killed.
468 for (i=0; i<=Highest_object_index; i++)
469 if (Objects[i].type == OBJ_ROBOT)
470 if ((Objects[i].matcen_creator^0x80) == my_station_num)
472 if (count > Difficulty_level + 3) {
473 mprintf((0, "Cannot morph: center %i has already put out %i robots.\n", my_station_num, count));
474 robotcen->Timer /= 2;
478 // Whack on any robot or player in the matcen segment.
480 segnum = robotcen->segnum;
481 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
483 if ( count > MAX_OBJECTS ) {
484 mprintf((0, "Object list in segment %d is circular.", segnum ));
488 if (Objects[objnum].type==OBJ_ROBOT) {
489 collide_robot_and_materialization_center(&Objects[objnum]);
490 robotcen->Timer = top_time/2;
492 } else if (Objects[objnum].type==OBJ_PLAYER ) {
493 collide_player_and_materialization_center(&Objects[objnum]);
494 robotcen->Timer = top_time/2;
499 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
500 // HACK!!! The 10 under here should be something equal to the 1/2 the size of the segment.
501 obj = object_create_explosion(robotcen->segnum, &cur_object_loc, i2f(10), VCLIP_MORPHING_ROBOT );
504 extract_orient_from_segment(&obj->orient,&Segments[robotcen->segnum]);
506 if ( Vclip[VCLIP_MORPHING_ROBOT].sound_num > -1 ) {
507 digi_link_sound_to_pos( Vclip[VCLIP_MORPHING_ROBOT].sound_num, robotcen->segnum, 0, &cur_object_loc, 0, F1_0 );
514 case 1: // Wait until 1/2 second after VCLIP started.
515 if (robotcen->Timer > (Vclip[VCLIP_MORPHING_ROBOT].play_time/2) ) {
517 robotcen->Capacity -= EnergyToCreateOneRobot;
521 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
523 // If this is the first materialization, set to valid robot.
524 if (RobotCenters[matcen_num].robot_flags[0] != 0 || RobotCenters[matcen_num].robot_flags[1] != 0) {
527 byte legal_types[64]; // 64 bits, the width of robot_flags[].
528 int num_types, robot_index, i;
533 flags = RobotCenters[matcen_num].robot_flags[i];
536 legal_types[num_types++] = robot_index;
542 //mprintf((0, "Flags = %08x, %2i legal types to morph: \n", RobotCenters[matcen_num].robot_flags, num_types));
543 //for (i=0; i<num_types; i++)
544 // mprintf((0, "%2i ", legal_types[i]));
545 //mprintf((0, "\n"));
548 type = legal_types[0];
550 type = legal_types[(d_rand() * num_types) / 32768];
552 mprintf((0, "Morph: (type = %i) (seg = %i) (capacity = %08x)\n", type, robotcen->segnum, robotcen->Capacity));
553 obj = create_morph_robot(&Segments[robotcen->segnum], &cur_object_loc, type );
557 if (Game_mode & GM_MULTI)
558 multi_send_create_robot(robotcen-Station, obj-Objects, type);
561 obj->matcen_creator = (robotcen-Station) | 0x80;
563 // Make object faces player...
564 vm_vec_sub( &direction, &ConsoleObject->pos,&obj->pos );
565 vm_vector_2_matrix( &obj->orient, &direction, &obj->orient.uvec, NULL);
568 //robotcen->last_created_obj = obj;
569 //robotcen->last_created_sig = robotcen->last_created_obj->signature;
571 mprintf((0, "Warning: create_morph_robot returned NULL (no objects left?)\n"));
584 //-------------------------------------------------------------
585 // Called once per frame, replenishes fuel supply.
586 void fuelcen_update_all()
589 fix AmountToreplenish;
591 AmountToreplenish = fixmul(FrameTime,Fuelcen_refill_speed);
593 for (i=0; i<Num_fuelcenters; i++ ) {
594 if ( Station[i].Type == SEGMENT_IS_ROBOTMAKER ) {
595 if (! (Game_suspended & SUSP_ROBOTS))
596 robotmaker_proc( &Station[i] );
597 } else if ( Station[i].Type == SEGMENT_IS_CONTROLCEN ) {
598 //controlcen_proc( &Station[i] );
600 } else if ( (Station[i].MaxCapacity > 0) && (PlayerSegment!=&Segments[Station[i].segnum]) ) {
601 if ( Station[i].Capacity < Station[i].MaxCapacity ) {
602 Station[i].Capacity += AmountToreplenish;
603 //mprintf( (0, "Fuel center %d replenished to %d.\n", i, f2i(Station[i].Capacity) ));
604 if ( Station[i].Capacity >= Station[i].MaxCapacity ) {
605 Station[i].Capacity = Station[i].MaxCapacity;
606 //gauge_message( "Fuel center is fully recharged! " );
613 //--unused-- //-------------------------------------------------------------
614 //--unused-- // replenishes all fuel supplies.
615 //--unused-- void fuelcen_replenish_all()
619 //--unused-- for (i=0; i<Num_fuelcenters; i++ ) {
620 //--unused-- Station[i].Capacity = Station[i].MaxCapacity;
622 //--unused-- //mprintf( (0, "All fuel centers are replenished\n" ));
626 #define FUELCEN_SOUND_DELAY (f1_0/4) //play every half second
628 //-------------------------------------------------------------
629 fix fuelcen_give_fuel(segment *segp, fix MaxAmountCanTake )
631 segment2 *seg2p = &Segment2s[segp-Segments];
633 static fix last_play_time=0;
635 Assert( segp != NULL );
637 PlayerSegment = segp;
639 if ( (segp) && (seg2p->special==SEGMENT_IS_FUELCEN) ) {
642 detect_escort_goal_accomplished(-4); // UGLY! Hack! -4 means went through fuelcen.
644 // if (Station[segp->value].MaxCapacity<=0) {
645 // HUD_init_message( "Fuelcenter %d is destroyed.", segp->value );
649 // if (Station[segp->value].Capacity<=0) {
650 // HUD_init_message( "Fuelcenter %d is empty.", segp->value );
654 if (MaxAmountCanTake <= 0 ) {
655 // //gauge_message( "Fueled up!");
659 amount = fixmul(FrameTime,Fuelcen_give_amount);
661 if (amount > MaxAmountCanTake )
662 amount = MaxAmountCanTake;
664 // if (!(Game_mode & GM_MULTI))
665 // if ( Station[segp->value].Capacity < amount ) {
666 // amount = Station[segp->value].Capacity;
667 // Station[segp->value].Capacity = 0;
669 // Station[segp->value].Capacity -= amount;
672 if (last_play_time > GameTime)
675 if (GameTime > last_play_time+FUELCEN_SOUND_DELAY) {
677 digi_play_sample( SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2 );
679 if (Game_mode & GM_MULTI)
680 multi_send_play_sound(SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2);
683 last_play_time = GameTime;
687 //HUD_init_message( "Fuelcen %d has %d/%d fuel", segp->value,f2i(Station[segp->value].Capacity),f2i(Station[segp->value].MaxCapacity) );
695 //--unused-- //-----------------------------------------------------------
696 //--unused-- // Damages a fuel center
697 //--unused-- void fuelcen_damage(segment *segp, fix damage )
699 //--unused-- //int i;
700 //--unused-- // int station_num = segp->value;
702 //--unused-- Assert( segp != NULL );
703 //--unused-- if ( segp == NULL ) return;
705 //--unused-- mprintf((0, "Obsolete function fuelcen_damage() called with seg=%i, damage=%7.3f\n", segp-Segments, f2fl(damage)));
706 //--unused-- switch( segp->special ) {
707 //--unused-- case SEGMENT_IS_NOTHING:
709 //--unused-- case SEGMENT_IS_ROBOTMAKER:
710 //--unused-- //-- // Robotmaker hit by laser
711 //--unused-- //-- if (Station[station_num].MaxCapacity<=0 ) {
712 //--unused-- //-- // Shooting a already destroyed materializer
713 //--unused-- //-- } else {
714 //--unused-- //-- Station[station_num].MaxCapacity -= damage;
715 //--unused-- //-- if (Station[station_num].Capacity > Station[station_num].MaxCapacity ) {
716 //--unused-- //-- Station[station_num].Capacity = Station[station_num].MaxCapacity;
718 //--unused-- //-- if (Station[station_num].MaxCapacity <= 0 ) {
719 //--unused-- //-- Station[station_num].MaxCapacity = 0;
720 //--unused-- //-- // Robotmaker dead
721 //--unused-- //-- for (i=0; i<6; i++ )
722 //--unused-- //-- segp->sides[i].tmap_num2 = 0;
725 //--unused-- //-- //mprintf( (0, "Materializatormografier has %x capacity left\n", Station[station_num].MaxCapacity ));
727 //--unused-- case SEGMENT_IS_FUELCEN:
728 //--unused-- //-- digi_play_sample( SOUND_REFUEL_STATION_HIT );
729 //--unused-- //-- if (Station[station_num].MaxCapacity>0 ) {
730 //--unused-- //-- Station[station_num].MaxCapacity -= damage;
731 //--unused-- //-- if (Station[station_num].Capacity > Station[station_num].MaxCapacity ) {
732 //--unused-- //-- Station[station_num].Capacity = Station[station_num].MaxCapacity;
734 //--unused-- //-- if (Station[station_num].MaxCapacity <= 0 ) {
735 //--unused-- //-- Station[station_num].MaxCapacity = 0;
736 //--unused-- //-- digi_play_sample( SOUND_REFUEL_STATION_DESTROYED );
738 //--unused-- //-- } else {
739 //--unused-- //-- Station[station_num].MaxCapacity = 0;
741 //--unused-- //-- HUD_init_message( "Fuelcenter %d damaged", station_num );
743 //--unused-- case SEGMENT_IS_REPAIRCEN:
745 //--unused-- case SEGMENT_IS_CONTROLCEN:
747 //--unused-- default:
748 //--unused-- Error( "Invalid type in fuelcen.c" );
752 //--unused-- // ----------------------------------------------------------------------------------------------------------
753 //--unused-- fixang my_delta_ang(fixang a,fixang b)
755 //--unused-- fixang delta0,delta1;
757 //--unused-- return (abs(delta0 = a - b) < abs(delta1 = b - a)) ? delta0 : delta1;
761 //--unused-- // ----------------------------------------------------------------------------------------------------------
762 //--unused-- //return though which side of seg0 is seg1
763 //--unused-- int john_find_connect_side(int seg0,int seg1)
765 //--unused-- segment *Seg=&Segments[seg0];
768 //--unused-- for (i=MAX_SIDES_PER_SEGMENT;i--;) if (Seg->children[i]==seg1) return i;
770 //--unused-- return -1;
773 // ----------------------------------------------------------------------------------------------------------
774 //--unused-- vms_angvec start_angles, delta_angles, goal_angles;
775 //--unused-- vms_vector start_pos, delta_pos, goal_pos;
776 //--unused-- int FuelStationSeg;
777 //--unused-- fix current_time,delta_time;
778 //--unused-- int next_side, side_index;
779 //--unused-- int * sidelist;
781 //--repair-- int Repairing;
782 //--repair-- vms_vector repair_save_uvec; //the player's upvec when enter repaircen
783 //--repair-- object *RepairObj=NULL; //which object getting repaired
784 //--repair-- int disable_repair_center=0;
785 //--repair-- fix repair_rate;
786 //--repair-- #define FULL_REPAIR_RATE i2f(10)
788 //--unused-- ubyte save_control_type,save_movement_type;
790 //--unused-- int SideOrderBack[] = {WFRONT, WRIGHT, WTOP, WLEFT, WBOTTOM, WBACK};
791 //--unused-- int SideOrderFront[] = {WBACK, WLEFT, WTOP, WRIGHT, WBOTTOM, WFRONT};
792 //--unused-- int SideOrderLeft[] = { WRIGHT, WBACK, WTOP, WFRONT, WBOTTOM, WLEFT };
793 //--unused-- int SideOrderRight[] = { WLEFT, WFRONT, WTOP, WBACK, WBOTTOM, WRIGHT };
794 //--unused-- int SideOrderTop[] = { WBOTTOM, WLEFT, WBACK, WRIGHT, WFRONT, WTOP };
795 //--unused-- int SideOrderBottom[] = { WTOP, WLEFT, WFRONT, WRIGHT, WBACK, WBOTTOM };
797 //--unused-- int SideUpVector[] = {WBOTTOM, WFRONT, WBOTTOM, WFRONT, WBOTTOM, WBOTTOM };
799 //--repair-- // ----------------------------------------------------------------------------------------------------------
800 //--repair-- void refuel_calc_deltas(object *obj, int next_side, int repair_seg)
802 //--repair-- vms_vector nextcenter, headfvec, *headuvec;
803 //--repair-- vms_matrix goal_orient;
805 //--repair-- // Find time for this movement
806 //--repair-- delta_time = F1_0; // one second...
808 //--repair-- // Find start and goal position
809 //--repair-- start_pos = obj->pos;
811 //--repair-- // Find delta position to get to goal position
812 //--repair-- compute_segment_center(&goal_pos,&Segments[repair_seg]);
813 //--repair-- vm_vec_sub( &delta_pos,&goal_pos,&start_pos);
815 //--repair-- // Find start angles
816 //--repair-- //angles_from_vector(&start_angles,&obj->orient.fvec);
817 //--repair-- vm_extract_angles_matrix(&start_angles,&obj->orient);
819 //--repair-- // Find delta angles to get to goal orientation
820 //--repair-- med_compute_center_point_on_side(&nextcenter,&Segments[repair_seg],next_side);
821 //--repair-- vm_vec_sub(&headfvec,&nextcenter,&goal_pos);
822 //--repair-- //mprintf( (0, "Next_side = %d, Head fvec = %d,%d,%d\n", next_side, headfvec.x, headfvec.y, headfvec.z ));
824 //--repair-- if (next_side == 5) //last side
825 //--repair-- headuvec = &repair_save_uvec;
827 //--repair-- headuvec = &Segments[repair_seg].sides[SideUpVector[next_side]].normals[0];
829 //--repair-- vm_vector_2_matrix(&goal_orient,&headfvec,headuvec,NULL);
830 //--repair-- vm_extract_angles_matrix(&goal_angles,&goal_orient);
831 //--repair-- delta_angles.p = my_delta_ang(start_angles.p,goal_angles.p);
832 //--repair-- delta_angles.b = my_delta_ang(start_angles.b,goal_angles.b);
833 //--repair-- delta_angles.h = my_delta_ang(start_angles.h,goal_angles.h);
834 //--repair-- current_time = 0;
835 //--repair-- Repairing = 0;
838 //--repair-- // ----------------------------------------------------------------------------------------------------------
839 //--repair-- //if repairing, cut it short
840 //--repair-- abort_repair_center()
842 //--repair-- if (!RepairObj || side_index==5)
845 //--repair-- current_time = 0;
846 //--repair-- side_index = 5;
847 //--repair-- next_side = sidelist[side_index];
848 //--repair-- refuel_calc_deltas(RepairObj, next_side, FuelStationSeg);
851 //--repair-- // ----------------------------------------------------------------------------------------------------------
852 //--repair-- void repair_ship_damage()
854 //--repair-- //mprintf((0,"Repairing ship damage\n"));
857 //--repair-- // ----------------------------------------------------------------------------------------------------------
858 //--repair-- int refuel_do_repair_effect( object * obj, int first_time, int repair_seg ) {
860 //--repair-- obj->mtype.phys_info.velocity.x = 0;
861 //--repair-- obj->mtype.phys_info.velocity.y = 0;
862 //--repair-- obj->mtype.phys_info.velocity.z = 0;
864 //--repair-- if (first_time) {
865 //--repair-- int entry_side;
866 //--repair-- current_time = 0;
868 //--repair-- digi_play_sample( SOUND_REPAIR_STATION_PLAYER_ENTERING, F1_0 );
870 //--repair-- entry_side = john_find_connect_side(repair_seg,obj->segnum );
871 //--repair-- Assert( entry_side > -1 );
873 //--repair-- switch( entry_side ) {
874 //--repair-- case WBACK: sidelist = SideOrderBack; break;
875 //--repair-- case WFRONT: sidelist = SideOrderFront; break;
876 //--repair-- case WLEFT: sidelist = SideOrderLeft; break;
877 //--repair-- case WRIGHT: sidelist = SideOrderRight; break;
878 //--repair-- case WTOP: sidelist = SideOrderTop; break;
879 //--repair-- case WBOTTOM: sidelist = SideOrderBottom; break;
881 //--repair-- side_index = 0;
882 //--repair-- next_side = sidelist[side_index];
884 //--repair-- refuel_calc_deltas(obj,next_side, repair_seg);
887 //--repair-- //update shields
888 //--repair-- if (Players[Player_num].shields < MAX_SHIELDS) { //if above max, don't mess with it
890 //--repair-- Players[Player_num].shields += fixmul(FrameTime,repair_rate);
892 //--repair-- if (Players[Player_num].shields > MAX_SHIELDS)
893 //--repair-- Players[Player_num].shields = MAX_SHIELDS;
896 //--repair-- current_time += FrameTime;
898 //--repair-- if (current_time >= delta_time ) {
899 //--repair-- vms_angvec av;
900 //--repair-- obj->pos = goal_pos;
901 //--repair-- av = goal_angles;
902 //--repair-- vm_angles_2_matrix(&obj->orient,&av);
904 //--repair-- if (side_index >= 5 )
905 //--repair-- return 1; // Done being repaired...
907 //--repair-- if (Repairing==0) {
908 //--repair-- //mprintf( (0, "<MACHINE EFFECT ON SIDE %d>\n", next_side ));
909 //--repair-- //digi_play_sample( SOUND_REPAIR_STATION_FIXING );
910 //--repair-- Repairing=1;
912 //--repair-- switch( next_side ) {
913 //--repair-- case 0: digi_play_sample( SOUND_REPAIR_STATION_FIXING_1,F1_0 ); break;
914 //--repair-- case 1: digi_play_sample( SOUND_REPAIR_STATION_FIXING_2,F1_0 ); break;
915 //--repair-- case 2: digi_play_sample( SOUND_REPAIR_STATION_FIXING_3,F1_0 ); break;
916 //--repair-- case 3: digi_play_sample( SOUND_REPAIR_STATION_FIXING_4,F1_0 ); break;
917 //--repair-- case 4: digi_play_sample( SOUND_REPAIR_STATION_FIXING_1,F1_0 ); break;
918 //--repair-- case 5: digi_play_sample( SOUND_REPAIR_STATION_FIXING_2,F1_0 ); break;
921 //--repair-- repair_ship_damage();
925 //--repair-- if (current_time >= (delta_time+(F1_0/2)) ) {
926 //--repair-- current_time = 0;
927 //--repair-- // Find next side...
928 //--repair-- side_index++;
929 //--repair-- if (side_index >= 6 ) return 1;
930 //--repair-- next_side = sidelist[side_index];
932 //--repair-- refuel_calc_deltas(obj, next_side, repair_seg);
935 //--repair-- } else {
936 //--repair-- fix factor, p,b,h;
937 //--repair-- vms_angvec av;
939 //--repair-- factor = fixdiv( current_time,delta_time );
941 //--repair-- // Find object's current position
942 //--repair-- obj->pos = delta_pos;
943 //--repair-- vm_vec_scale( &obj->pos, factor );
944 //--repair-- vm_vec_add2( &obj->pos, &start_pos );
946 //--repair-- // Find object's current orientation
947 //--repair-- p = fixmul(delta_angles.p,factor);
948 //--repair-- b = fixmul(delta_angles.b,factor);
949 //--repair-- h = fixmul(delta_angles.h,factor);
950 //--repair-- av.p = (fixang)p + start_angles.p;
951 //--repair-- av.b = (fixang)b + start_angles.b;
952 //--repair-- av.h = (fixang)h + start_angles.h;
953 //--repair-- vm_angles_2_matrix(&obj->orient,&av);
957 //--repair-- update_object_seg(obj); //update segment
959 //--repair-- return 0;
962 //--repair-- // ----------------------------------------------------------------------------------------------------------
963 //--repair-- //do the repair center for this frame
964 //--repair-- void do_repair_sequence(object *obj)
966 //--repair-- Assert(obj == RepairObj);
968 //--repair-- if (refuel_do_repair_effect( obj, 0, FuelStationSeg )) {
969 //--repair-- if (Players[Player_num].shields < MAX_SHIELDS)
970 //--repair-- Players[Player_num].shields = MAX_SHIELDS;
971 //--repair-- obj->control_type = save_control_type;
972 //--repair-- obj->movement_type = save_movement_type;
973 //--repair-- disable_repair_center=1;
974 //--repair-- RepairObj = NULL;
977 //--repair-- //the two lines below will spit the player out of the rapair center,
978 //--repair-- //but what happen is that the ship just bangs into the door
979 //--repair-- //if (obj->movement_type == MT_PHYSICS)
980 //--repair-- // vm_vec_copy_scale(&obj->mtype.phys_info.velocity,&obj->orient.fvec,i2f(200));
985 //--repair-- // ----------------------------------------------------------------------------------------------------------
986 //--repair-- //see if we should start the repair center
987 //--repair-- void check_start_repair_center(object *obj)
989 //--repair-- if (RepairObj != NULL) return; //already in repair center
991 //--repair-- if (Lsegments[obj->segnum].special_type & SS_REPAIR_CENTER) {
993 //--repair-- if (!disable_repair_center) {
994 //--repair-- //have just entered repair center
996 //--repair-- RepairObj = obj;
997 //--repair-- repair_save_uvec = obj->orient.uvec;
999 //--repair-- repair_rate = fixmuldiv(FULL_REPAIR_RATE,(MAX_SHIELDS - Players[Player_num].shields),MAX_SHIELDS);
1001 //--repair-- save_control_type = obj->control_type;
1002 //--repair-- save_movement_type = obj->movement_type;
1004 //--repair-- obj->control_type = CT_REPAIRCEN;
1005 //--repair-- obj->movement_type = MT_NONE;
1007 //--repair-- FuelStationSeg = Lsegments[obj->segnum].special_segment;
1008 //--repair-- Assert(FuelStationSeg != -1);
1010 //--repair-- if (refuel_do_repair_effect( obj, 1, FuelStationSeg )) {
1011 //--repair-- Int3(); //can this happen?
1012 //--repair-- obj->control_type = CT_FLYING;
1013 //--repair-- obj->movement_type = MT_PHYSICS;
1018 //--repair-- disable_repair_center=0;
1022 // --------------------------------------------------------------------------------------------
1023 void disable_matcens(void)
1027 for (i=0; i<Num_robot_centers; i++) {
1028 Station[i].Enabled = 0;
1029 Station[i].Disable_time = 0;
1033 // --------------------------------------------------------------------------------------------
1034 // Initialize all materialization centers.
1035 // Give them all the right number of lives.
1036 void init_all_matcens(void)
1040 for (i=0; i<Num_fuelcenters; i++)
1041 if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
1042 Station[i].Lives = 3;
1043 Station[i].Enabled = 0;
1044 Station[i].Disable_time = 0;
1047 // Make sure this fuelcen is pointed at by a matcen.
1049 for (j=0; j<Num_robot_centers; j++) {
1050 if (RobotCenters[j].fuelcen_num == i)
1053 Assert(j != Num_robot_centers);
1060 // Make sure all matcens point at a fuelcen
1061 for (i=0; i<Num_robot_centers; i++) {
1062 int fuelcen_num = RobotCenters[i].fuelcen_num;
1064 Assert(fuelcen_num < Num_fuelcenters);
1065 Assert(Station[fuelcen_num].Type == SEGMENT_IS_ROBOTMAKER);
1072 extern void multi_send_capture_bonus (char);
1074 void fuelcen_check_for_goal(segment *segp)
1076 segment2 *seg2p = &Segment2s[segp-Segments];
1078 Assert( segp != NULL );
1079 Assert (Game_mode & GM_CAPTURE);
1081 if (seg2p->special==SEGMENT_IS_GOAL_BLUE ) {
1083 if ((get_team(Player_num)==TEAM_BLUE) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1085 mprintf ((0,"In goal segment BLUE\n"));
1087 multi_send_capture_bonus (Player_num);
1088 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1089 maybe_drop_net_powerup (POW_FLAG_RED);
1092 if ( seg2p->special==SEGMENT_IS_GOAL_RED) {
1094 if ((get_team(Player_num)==TEAM_RED) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1096 mprintf ((0,"In goal segment RED\n"));
1097 multi_send_capture_bonus (Player_num);
1098 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1099 maybe_drop_net_powerup (POW_FLAG_BLUE);
1104 void fuelcen_check_for_hoard_goal(segment *segp)
1106 segment2 *seg2p = &Segment2s[segp-Segments];
1108 Assert( segp != NULL );
1109 Assert (Game_mode & GM_HOARD);
1114 if (seg2p->special==SEGMENT_IS_GOAL_BLUE || seg2p->special==SEGMENT_IS_GOAL_RED )
1116 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX])
1118 mprintf ((0,"In orb goal!\n"));
1119 multi_send_orb_bonus (Player_num);
1120 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1121 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]=0;