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.6 2003-03-27 01:23:18 btb Exp $";
29 #include "game.h" // For FrameTime
57 // The max number of fuel stations per mine.
59 fix Fuelcen_refill_speed = i2f(1);
60 fix Fuelcen_give_amount = i2f(25);
61 fix Fuelcen_max_amount = i2f(100);
63 // Every time a robot is created in the morphing code, it decreases capacity of the morpher
64 // by this amount... when capacity gets to 0, no more morphers...
65 fix EnergyToCreateOneRobot = i2f(1);
67 #define MATCEN_HP_DEFAULT F1_0*500; // Hitpoints
68 #define MATCEN_INTERVAL_DEFAULT F1_0*5; // 5 seconds
70 matcen_info RobotCenters[MAX_ROBOT_CENTERS];
71 int Num_robot_centers;
73 FuelCenter Station[MAX_NUM_FUELCENS];
74 int Num_fuelcenters = 0;
76 segment * PlayerSegment= NULL;
79 char Special_names[MAX_CENTER_TYPES][11] = {
90 //------------------------------------------------------------
91 // Resets all fuel center info
97 //mprintf( (0, "All fuel centers reset.\n"));
99 for(i=0; i<MAX_SEGMENTS; i++ )
100 Segment2s[i].special = SEGMENT_IS_NOTHING;
102 Num_robot_centers = 0;
106 #ifndef NDEBUG //this is sometimes called by people from the debugger
107 void reset_all_robot_centers()
111 // Remove all materialization centers
112 for (i=0; i<Num_segments; i++)
113 if (Segment2s[i].special == SEGMENT_IS_ROBOTMAKER) {
114 Segment2s[i].special = SEGMENT_IS_NOTHING;
115 Segment2s[i].matcen_num = -1;
120 //------------------------------------------------------------
121 // Turns a segment into a fully charged up fuel center...
122 void fuelcen_create( segment *segp)
124 segment2 *seg2p = &Segment2s[segp-Segments];
128 station_type = seg2p->special;
130 switch( station_type ) {
131 case SEGMENT_IS_NOTHING:
132 case SEGMENT_IS_GOAL_BLUE:
133 case SEGMENT_IS_GOAL_RED:
135 case SEGMENT_IS_FUELCEN:
136 case SEGMENT_IS_REPAIRCEN:
137 case SEGMENT_IS_CONTROLCEN:
138 case SEGMENT_IS_ROBOTMAKER:
141 Error( "Invalid station type %d in fuelcen.c\n", station_type );
144 Assert( (seg2p != NULL) );
145 if ( seg2p == NULL ) return;
147 Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
148 Assert( Num_fuelcenters > -1 );
150 seg2p->value = Num_fuelcenters;
151 Station[Num_fuelcenters].Type = station_type;
152 Station[Num_fuelcenters].MaxCapacity = Fuelcen_max_amount;
153 Station[Num_fuelcenters].Capacity = Station[Num_fuelcenters].MaxCapacity;
154 Station[Num_fuelcenters].segnum = seg2p-Segment2s;
155 Station[Num_fuelcenters].Timer = -1;
156 Station[Num_fuelcenters].Flag = 0;
157 // Station[Num_fuelcenters].NextRobotType = -1;
158 // Station[Num_fuelcenters].last_created_obj=NULL;
159 // Station[Num_fuelcenters].last_created_sig = -1;
160 compute_segment_center(&Station[Num_fuelcenters].Center, segp);
162 // if (station_type == SEGMENT_IS_ROBOTMAKER)
163 // Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
165 //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
169 //------------------------------------------------------------
170 // Adds a matcen that already is a special type into the Station array.
171 // This function is separate from other fuelcens because we don't want values reset.
172 void matcen_create( segment *segp)
174 segment2 *seg2p = &Segment2s[segp-Segments];
176 int station_type = seg2p->special;
178 Assert( (seg2p != NULL) );
179 Assert(station_type == SEGMENT_IS_ROBOTMAKER);
180 if ( seg2p == NULL ) return;
182 Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
183 Assert( Num_fuelcenters > -1 );
185 seg2p->value = Num_fuelcenters;
186 Station[Num_fuelcenters].Type = station_type;
187 Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
188 Station[Num_fuelcenters].MaxCapacity = Station[Num_fuelcenters].Capacity;
190 Station[Num_fuelcenters].segnum = seg2p-Segment2s;
191 Station[Num_fuelcenters].Timer = -1;
192 Station[Num_fuelcenters].Flag = 0;
193 // Station[Num_fuelcenters].NextRobotType = -1;
194 // Station[Num_fuelcenters].last_created_obj=NULL;
195 // Station[Num_fuelcenters].last_created_sig = -1;
196 compute_segment_center(&Station[Num_fuelcenters].Center, &Segments[seg2p-Segment2s] );
198 seg2p->matcen_num = Num_robot_centers;
201 RobotCenters[seg2p->matcen_num].hit_points = MATCEN_HP_DEFAULT;
202 RobotCenters[seg2p->matcen_num].interval = MATCEN_INTERVAL_DEFAULT;
203 RobotCenters[seg2p->matcen_num].segnum = seg2p-Segment2s;
204 RobotCenters[seg2p->matcen_num].fuelcen_num = Num_fuelcenters;
206 //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
210 //------------------------------------------------------------
211 // Adds a segment that already is a special type into the Station array.
212 void fuelcen_activate( segment * segp, int station_type )
214 segment2 *seg2p = &Segment2s[segp-Segments];
216 seg2p->special = station_type;
218 if (seg2p->special == SEGMENT_IS_ROBOTMAKER)
219 matcen_create( segp);
221 fuelcen_create( segp);
225 // The lower this number is, the more quickly the center can be re-triggered.
226 // If it's too low, it can mean all the robots won't be put out, but for about 5
227 // robots, that's not real likely.
228 #define MATCEN_LIFE (i2f(30-2*Difficulty_level))
230 //------------------------------------------------------------
231 // Trigger (enable) the materialization center in segment segnum
232 void trigger_matcen(int segnum)
234 // -- segment *segp = &Segments[segnum];
235 segment2 *seg2p = &Segment2s[segnum];
236 vms_vector pos, delta;
237 FuelCenter *robotcen;
240 mprintf((0, "Trigger matcen, segment %i\n", segnum));
242 Assert(seg2p->special == SEGMENT_IS_ROBOTMAKER);
243 Assert(seg2p->matcen_num < Num_fuelcenters);
244 Assert((seg2p->matcen_num >= 0) && (seg2p->matcen_num <= Highest_segment_index));
246 robotcen = &Station[RobotCenters[seg2p->matcen_num].fuelcen_num];
248 if (robotcen->Enabled == 1)
251 if (!robotcen->Lives)
254 // MK: 11/18/95, At insane, matcens work forever!
255 if (Difficulty_level+1 < NDL)
258 robotcen->Timer = F1_0*1000; // Make sure the first robot gets emitted right away.
259 robotcen->Enabled = 1; // Say this center is enabled, it can create robots.
260 robotcen->Capacity = i2f(Difficulty_level + 3);
261 robotcen->Disable_time = MATCEN_LIFE;
263 // Create a bright object in the segment.
264 pos = robotcen->Center;
265 vm_vec_sub(&delta, &Vertices[Segments[segnum].verts[0]], &robotcen->Center);
266 vm_vec_scale_add2(&pos, &delta, F1_0/2);
267 objnum = obj_create( OBJ_LIGHT, 0, segnum, &pos, NULL, 0, CT_LIGHT, MT_NONE, RT_NONE );
269 Objects[objnum].lifeleft = MATCEN_LIFE;
270 Objects[objnum].ctype.light_info.intensity = i2f(8); // Light cast by a fuelcen.
272 mprintf((1, "Can't create invisible flare for matcen.\n"));
275 // 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)));
279 //------------------------------------------------------------
280 // Takes away a segment's fuel center properties.
281 // Deletes the segment point entry in the FuelCenter list.
282 void fuelcen_delete( segment * segp )
284 segment2 *seg2p = &Segment2s[segp-Segments];
291 for (i=0; i<Num_fuelcenters; i++ ) {
292 if ( Station[i].segnum == segp-Segments ) {
294 // If Robot maker is deleted, fix Segments and RobotCenters.
295 if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
297 Assert(Num_robot_centers >= 0);
299 for (j=seg2p->matcen_num; j<Num_robot_centers; j++)
300 RobotCenters[j] = RobotCenters[j+1];
302 for (j=0; j<Num_fuelcenters; j++) {
303 if ( Station[j].Type == SEGMENT_IS_ROBOTMAKER )
304 if ( Segment2s[Station[j].segnum].matcen_num > seg2p->matcen_num )
305 Segment2s[Station[j].segnum].matcen_num--;
309 //fix RobotCenters so they point to correct fuelcenter
310 for (j=0; j<Num_robot_centers; j++ )
311 if (RobotCenters[j].fuelcen_num > i) //this robotcenter's fuelcen is changing
312 RobotCenters[j].fuelcen_num--;
315 Assert(Num_fuelcenters >= 0);
316 for (j=i; j<Num_fuelcenters; j++ ) {
317 Station[j] = Station[j+1];
318 Segment2s[Station[j].segnum].value = j;
327 #define ROBOT_GEN_TIME (i2f(5))
329 object * create_morph_robot( segment *segp, vms_vector *object_pos, int object_id)
333 int default_behavior;
335 Players[Player_num].num_robots_level++;
336 Players[Player_num].num_robots_total++;
338 objnum = obj_create(OBJ_ROBOT, object_id, segp-Segments, object_pos,
339 &vmd_identity_matrix, Polygon_models[Robot_info[object_id].model_num].rad,
340 CT_AI, MT_PHYSICS, RT_POLYOBJ);
343 mprintf((1, "Can't create morph robot. Aborting morph.\n"));
348 obj = &Objects[objnum];
350 //Set polygon-object-specific data
352 obj->rtype.pobj_info.model_num = Robot_info[obj->id].model_num;
353 obj->rtype.pobj_info.subobj_flags = 0;
357 obj->mtype.phys_info.mass = Robot_info[obj->id].mass;
358 obj->mtype.phys_info.drag = Robot_info[obj->id].drag;
360 obj->mtype.phys_info.flags |= (PF_LEVELLING);
362 obj->shields = Robot_info[obj->id].strength;
364 default_behavior = Robot_info[obj->id].behavior;
366 init_ai_object(obj-Objects, default_behavior, -1 ); // Note, -1 = segment this robot goes to to hide, should probably be something useful
368 create_n_segment_path(obj, 6, -1); // Create a 6 segment path from creation point.
370 Ai_local_info[objnum].mode = ai_behavior_to_mode(default_behavior);
375 int Num_extry_robots = 15;
378 int FrameCount_last_msg = 0;
381 // ----------------------------------------------------------------------------------------------------------
382 void robotmaker_proc( FuelCenter * robotcen )
385 vms_vector cur_object_loc; //, direction;
386 int matcen_num, segnum, objnum;
389 vms_vector direction;
391 if (robotcen->Enabled == 0)
394 if (robotcen->Disable_time > 0) {
395 robotcen->Disable_time -= FrameTime;
396 if (robotcen->Disable_time <= 0) {
397 mprintf((0, "Robot center #%i gets disabled due to time running out.\n", robotcen-Station));
398 robotcen->Enabled = 0;
402 // mprintf((0, "Capacity of robot maker #%i is %i\n", robotcen - Station, robotcen->Capacity));
404 // No robot making in multiplayer mode.
407 if ((Game_mode & GM_MULTI) && (!(Game_mode & GM_MULTI_ROBOTS) || !network_i_am_master()))
410 if (Game_mode & GM_MULTI)
415 // Wait until transmorgafier has capacity to make a robot...
416 if ( robotcen->Capacity <= 0 ) {
420 matcen_num = Segment2s[robotcen->segnum].matcen_num;
421 //mprintf((0, "Robotmaker #%i flags = %8x\n", matcen_num, RobotCenters[matcen_num].robot_flags));
423 if ( matcen_num == -1 ) {
424 mprintf((0, "Non-functional robotcen at %d\n", robotcen->segnum));
428 if (RobotCenters[matcen_num].robot_flags[0]==0 && RobotCenters[matcen_num].robot_flags[1]==0) {
429 //mprintf((0, "robot_flags = 0 at robot maker #%i\n", RobotCenters[matcen_num].robot_flags));
433 // Wait until we have a free slot for this puppy...
434 // <<<<<<<<<<<<<<<< Num robots in mine >>>>>>>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<< Max robots in mine >>>>>>>>>>>>>>>
435 if ( (Players[Player_num].num_robots_level - Players[Player_num].num_kills_level) >= (Gamesave_num_org_robots + Num_extry_robots ) ) {
437 if (FrameCount > FrameCount_last_msg + 20) {
438 mprintf((0, "Cannot morph until you kill one!\n"));
439 FrameCount_last_msg = FrameCount;
445 robotcen->Timer += FrameTime;
447 switch( robotcen->Flag ) {
448 case 0: // Wait until next robot can generate
449 if (Game_mode & GM_MULTI)
451 top_time = ROBOT_GEN_TIME;
455 dist_to_player = vm_vec_dist_quick( &ConsoleObject->pos, &robotcen->Center );
456 top_time = dist_to_player/64 + d_rand() * 2 + F1_0*2;
457 if ( top_time > ROBOT_GEN_TIME )
458 top_time = ROBOT_GEN_TIME + d_rand();
459 if ( top_time < F1_0*2 )
460 top_time = F1_0*3/2 + d_rand()*2;
463 // mprintf( (0, "Time between morphs %d seconds, dist_to_player = %7.3f\n", f2i(top_time), f2fl(dist_to_player) ));
465 if (robotcen->Timer > top_time ) {
467 int i, my_station_num = robotcen-Station;
470 // Make sure this robotmaker hasn't put out its max without having any of them killed.
471 for (i=0; i<=Highest_object_index; i++)
472 if (Objects[i].type == OBJ_ROBOT)
473 if ((Objects[i].matcen_creator^0x80) == my_station_num)
475 if (count > Difficulty_level + 3) {
476 mprintf((0, "Cannot morph: center %i has already put out %i robots.\n", my_station_num, count));
477 robotcen->Timer /= 2;
481 // Whack on any robot or player in the matcen segment.
483 segnum = robotcen->segnum;
484 for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next) {
486 if ( count > MAX_OBJECTS ) {
487 mprintf((0, "Object list in segment %d is circular.", segnum ));
491 if (Objects[objnum].type==OBJ_ROBOT) {
492 collide_robot_and_materialization_center(&Objects[objnum]);
493 robotcen->Timer = top_time/2;
495 } else if (Objects[objnum].type==OBJ_PLAYER ) {
496 collide_player_and_materialization_center(&Objects[objnum]);
497 robotcen->Timer = top_time/2;
502 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
503 // HACK!!! The 10 under here should be something equal to the 1/2 the size of the segment.
504 obj = object_create_explosion(robotcen->segnum, &cur_object_loc, i2f(10), VCLIP_MORPHING_ROBOT );
507 extract_orient_from_segment(&obj->orient,&Segments[robotcen->segnum]);
509 if ( Vclip[VCLIP_MORPHING_ROBOT].sound_num > -1 ) {
510 digi_link_sound_to_pos( Vclip[VCLIP_MORPHING_ROBOT].sound_num, robotcen->segnum, 0, &cur_object_loc, 0, F1_0 );
517 case 1: // Wait until 1/2 second after VCLIP started.
518 if (robotcen->Timer > (Vclip[VCLIP_MORPHING_ROBOT].play_time/2) ) {
520 robotcen->Capacity -= EnergyToCreateOneRobot;
524 compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
526 // If this is the first materialization, set to valid robot.
527 if (RobotCenters[matcen_num].robot_flags[0] != 0 || RobotCenters[matcen_num].robot_flags[1] != 0) {
530 byte legal_types[64]; // 64 bits, the width of robot_flags[].
531 int num_types, robot_index, i;
536 flags = RobotCenters[matcen_num].robot_flags[i];
539 legal_types[num_types++] = robot_index;
545 //mprintf((0, "Flags = %08x, %2i legal types to morph: \n", RobotCenters[matcen_num].robot_flags, num_types));
546 //for (i=0; i<num_types; i++)
547 // mprintf((0, "%2i ", legal_types[i]));
548 //mprintf((0, "\n"));
551 type = legal_types[0];
553 type = legal_types[(d_rand() * num_types) / 32768];
555 mprintf((0, "Morph: (type = %i) (seg = %i) (capacity = %08x)\n", type, robotcen->segnum, robotcen->Capacity));
556 obj = create_morph_robot(&Segments[robotcen->segnum], &cur_object_loc, type );
560 if (Game_mode & GM_MULTI)
561 multi_send_create_robot(robotcen-Station, obj-Objects, type);
564 obj->matcen_creator = (robotcen-Station) | 0x80;
566 // Make object faces player...
567 vm_vec_sub( &direction, &ConsoleObject->pos,&obj->pos );
568 vm_vector_2_matrix( &obj->orient, &direction, &obj->orient.uvec, NULL);
571 //robotcen->last_created_obj = obj;
572 //robotcen->last_created_sig = robotcen->last_created_obj->signature;
574 mprintf((0, "Warning: create_morph_robot returned NULL (no objects left?)\n"));
587 //-------------------------------------------------------------
588 // Called once per frame, replenishes fuel supply.
589 void fuelcen_update_all()
592 fix AmountToreplenish;
594 AmountToreplenish = fixmul(FrameTime,Fuelcen_refill_speed);
596 for (i=0; i<Num_fuelcenters; i++ ) {
597 if ( Station[i].Type == SEGMENT_IS_ROBOTMAKER ) {
598 if (! (Game_suspended & SUSP_ROBOTS))
599 robotmaker_proc( &Station[i] );
600 } else if ( Station[i].Type == SEGMENT_IS_CONTROLCEN ) {
601 //controlcen_proc( &Station[i] );
603 } else if ( (Station[i].MaxCapacity > 0) && (PlayerSegment!=&Segments[Station[i].segnum]) ) {
604 if ( Station[i].Capacity < Station[i].MaxCapacity ) {
605 Station[i].Capacity += AmountToreplenish;
606 //mprintf( (0, "Fuel center %d replenished to %d.\n", i, f2i(Station[i].Capacity) ));
607 if ( Station[i].Capacity >= Station[i].MaxCapacity ) {
608 Station[i].Capacity = Station[i].MaxCapacity;
609 //gauge_message( "Fuel center is fully recharged! " );
616 //--unused-- //-------------------------------------------------------------
617 //--unused-- // replenishes all fuel supplies.
618 //--unused-- void fuelcen_replenish_all()
622 //--unused-- for (i=0; i<Num_fuelcenters; i++ ) {
623 //--unused-- Station[i].Capacity = Station[i].MaxCapacity;
625 //--unused-- //mprintf( (0, "All fuel centers are replenished\n" ));
629 #define FUELCEN_SOUND_DELAY (f1_0/4) //play every half second
631 //-------------------------------------------------------------
632 fix fuelcen_give_fuel(segment *segp, fix MaxAmountCanTake )
634 segment2 *seg2p = &Segment2s[segp-Segments];
636 static fix last_play_time=0;
638 Assert( segp != NULL );
640 PlayerSegment = segp;
642 if ( (segp) && (seg2p->special==SEGMENT_IS_FUELCEN) ) {
645 detect_escort_goal_accomplished(-4); // UGLY! Hack! -4 means went through fuelcen.
647 // if (Station[segp->value].MaxCapacity<=0) {
648 // HUD_init_message( "Fuelcenter %d is destroyed.", segp->value );
652 // if (Station[segp->value].Capacity<=0) {
653 // HUD_init_message( "Fuelcenter %d is empty.", segp->value );
657 if (MaxAmountCanTake <= 0 ) {
658 // //gauge_message( "Fueled up!");
662 amount = fixmul(FrameTime,Fuelcen_give_amount);
664 if (amount > MaxAmountCanTake )
665 amount = MaxAmountCanTake;
667 // if (!(Game_mode & GM_MULTI))
668 // if ( Station[segp->value].Capacity < amount ) {
669 // amount = Station[segp->value].Capacity;
670 // Station[segp->value].Capacity = 0;
672 // Station[segp->value].Capacity -= amount;
675 if (last_play_time > GameTime)
678 if (GameTime > last_play_time+FUELCEN_SOUND_DELAY) {
680 digi_play_sample( SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2 );
682 if (Game_mode & GM_MULTI)
683 multi_send_play_sound(SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2);
686 last_play_time = GameTime;
690 //HUD_init_message( "Fuelcen %d has %d/%d fuel", segp->value,f2i(Station[segp->value].Capacity),f2i(Station[segp->value].MaxCapacity) );
698 //--unused-- //-----------------------------------------------------------
699 //--unused-- // Damages a fuel center
700 //--unused-- void fuelcen_damage(segment *segp, fix damage )
702 //--unused-- //int i;
703 //--unused-- // int station_num = segp->value;
705 //--unused-- Assert( segp != NULL );
706 //--unused-- if ( segp == NULL ) return;
708 //--unused-- mprintf((0, "Obsolete function fuelcen_damage() called with seg=%i, damage=%7.3f\n", segp-Segments, f2fl(damage)));
709 //--unused-- switch( segp->special ) {
710 //--unused-- case SEGMENT_IS_NOTHING:
712 //--unused-- case SEGMENT_IS_ROBOTMAKER:
713 //--unused-- //-- // Robotmaker hit by laser
714 //--unused-- //-- if (Station[station_num].MaxCapacity<=0 ) {
715 //--unused-- //-- // Shooting a already destroyed materializer
716 //--unused-- //-- } else {
717 //--unused-- //-- Station[station_num].MaxCapacity -= damage;
718 //--unused-- //-- if (Station[station_num].Capacity > Station[station_num].MaxCapacity ) {
719 //--unused-- //-- Station[station_num].Capacity = Station[station_num].MaxCapacity;
721 //--unused-- //-- if (Station[station_num].MaxCapacity <= 0 ) {
722 //--unused-- //-- Station[station_num].MaxCapacity = 0;
723 //--unused-- //-- // Robotmaker dead
724 //--unused-- //-- for (i=0; i<6; i++ )
725 //--unused-- //-- segp->sides[i].tmap_num2 = 0;
728 //--unused-- //-- //mprintf( (0, "Materializatormografier has %x capacity left\n", Station[station_num].MaxCapacity ));
730 //--unused-- case SEGMENT_IS_FUELCEN:
731 //--unused-- //-- digi_play_sample( SOUND_REFUEL_STATION_HIT );
732 //--unused-- //-- if (Station[station_num].MaxCapacity>0 ) {
733 //--unused-- //-- Station[station_num].MaxCapacity -= damage;
734 //--unused-- //-- if (Station[station_num].Capacity > Station[station_num].MaxCapacity ) {
735 //--unused-- //-- Station[station_num].Capacity = Station[station_num].MaxCapacity;
737 //--unused-- //-- if (Station[station_num].MaxCapacity <= 0 ) {
738 //--unused-- //-- Station[station_num].MaxCapacity = 0;
739 //--unused-- //-- digi_play_sample( SOUND_REFUEL_STATION_DESTROYED );
741 //--unused-- //-- } else {
742 //--unused-- //-- Station[station_num].MaxCapacity = 0;
744 //--unused-- //-- HUD_init_message( "Fuelcenter %d damaged", station_num );
746 //--unused-- case SEGMENT_IS_REPAIRCEN:
748 //--unused-- case SEGMENT_IS_CONTROLCEN:
750 //--unused-- default:
751 //--unused-- Error( "Invalid type in fuelcen.c" );
755 //--unused-- // ----------------------------------------------------------------------------------------------------------
756 //--unused-- fixang my_delta_ang(fixang a,fixang b)
758 //--unused-- fixang delta0,delta1;
760 //--unused-- return (abs(delta0 = a - b) < abs(delta1 = b - a)) ? delta0 : delta1;
764 //--unused-- // ----------------------------------------------------------------------------------------------------------
765 //--unused-- //return though which side of seg0 is seg1
766 //--unused-- int john_find_connect_side(int seg0,int seg1)
768 //--unused-- segment *Seg=&Segments[seg0];
771 //--unused-- for (i=MAX_SIDES_PER_SEGMENT;i--;) if (Seg->children[i]==seg1) return i;
773 //--unused-- return -1;
776 // ----------------------------------------------------------------------------------------------------------
777 //--unused-- vms_angvec start_angles, delta_angles, goal_angles;
778 //--unused-- vms_vector start_pos, delta_pos, goal_pos;
779 //--unused-- int FuelStationSeg;
780 //--unused-- fix current_time,delta_time;
781 //--unused-- int next_side, side_index;
782 //--unused-- int * sidelist;
784 //--repair-- int Repairing;
785 //--repair-- vms_vector repair_save_uvec; //the player's upvec when enter repaircen
786 //--repair-- object *RepairObj=NULL; //which object getting repaired
787 //--repair-- int disable_repair_center=0;
788 //--repair-- fix repair_rate;
789 //--repair-- #define FULL_REPAIR_RATE i2f(10)
791 //--unused-- ubyte save_control_type,save_movement_type;
793 //--unused-- int SideOrderBack[] = {WFRONT, WRIGHT, WTOP, WLEFT, WBOTTOM, WBACK};
794 //--unused-- int SideOrderFront[] = {WBACK, WLEFT, WTOP, WRIGHT, WBOTTOM, WFRONT};
795 //--unused-- int SideOrderLeft[] = { WRIGHT, WBACK, WTOP, WFRONT, WBOTTOM, WLEFT };
796 //--unused-- int SideOrderRight[] = { WLEFT, WFRONT, WTOP, WBACK, WBOTTOM, WRIGHT };
797 //--unused-- int SideOrderTop[] = { WBOTTOM, WLEFT, WBACK, WRIGHT, WFRONT, WTOP };
798 //--unused-- int SideOrderBottom[] = { WTOP, WLEFT, WFRONT, WRIGHT, WBACK, WBOTTOM };
800 //--unused-- int SideUpVector[] = {WBOTTOM, WFRONT, WBOTTOM, WFRONT, WBOTTOM, WBOTTOM };
802 //--repair-- // ----------------------------------------------------------------------------------------------------------
803 //--repair-- void refuel_calc_deltas(object *obj, int next_side, int repair_seg)
805 //--repair-- vms_vector nextcenter, headfvec, *headuvec;
806 //--repair-- vms_matrix goal_orient;
808 //--repair-- // Find time for this movement
809 //--repair-- delta_time = F1_0; // one second...
811 //--repair-- // Find start and goal position
812 //--repair-- start_pos = obj->pos;
814 //--repair-- // Find delta position to get to goal position
815 //--repair-- compute_segment_center(&goal_pos,&Segments[repair_seg]);
816 //--repair-- vm_vec_sub( &delta_pos,&goal_pos,&start_pos);
818 //--repair-- // Find start angles
819 //--repair-- //angles_from_vector(&start_angles,&obj->orient.fvec);
820 //--repair-- vm_extract_angles_matrix(&start_angles,&obj->orient);
822 //--repair-- // Find delta angles to get to goal orientation
823 //--repair-- med_compute_center_point_on_side(&nextcenter,&Segments[repair_seg],next_side);
824 //--repair-- vm_vec_sub(&headfvec,&nextcenter,&goal_pos);
825 //--repair-- //mprintf( (0, "Next_side = %d, Head fvec = %d,%d,%d\n", next_side, headfvec.x, headfvec.y, headfvec.z ));
827 //--repair-- if (next_side == 5) //last side
828 //--repair-- headuvec = &repair_save_uvec;
830 //--repair-- headuvec = &Segments[repair_seg].sides[SideUpVector[next_side]].normals[0];
832 //--repair-- vm_vector_2_matrix(&goal_orient,&headfvec,headuvec,NULL);
833 //--repair-- vm_extract_angles_matrix(&goal_angles,&goal_orient);
834 //--repair-- delta_angles.p = my_delta_ang(start_angles.p,goal_angles.p);
835 //--repair-- delta_angles.b = my_delta_ang(start_angles.b,goal_angles.b);
836 //--repair-- delta_angles.h = my_delta_ang(start_angles.h,goal_angles.h);
837 //--repair-- current_time = 0;
838 //--repair-- Repairing = 0;
841 //--repair-- // ----------------------------------------------------------------------------------------------------------
842 //--repair-- //if repairing, cut it short
843 //--repair-- abort_repair_center()
845 //--repair-- if (!RepairObj || side_index==5)
848 //--repair-- current_time = 0;
849 //--repair-- side_index = 5;
850 //--repair-- next_side = sidelist[side_index];
851 //--repair-- refuel_calc_deltas(RepairObj, next_side, FuelStationSeg);
854 //--repair-- // ----------------------------------------------------------------------------------------------------------
855 //--repair-- void repair_ship_damage()
857 //--repair-- //mprintf((0,"Repairing ship damage\n"));
860 //--repair-- // ----------------------------------------------------------------------------------------------------------
861 //--repair-- int refuel_do_repair_effect( object * obj, int first_time, int repair_seg ) {
863 //--repair-- obj->mtype.phys_info.velocity.x = 0;
864 //--repair-- obj->mtype.phys_info.velocity.y = 0;
865 //--repair-- obj->mtype.phys_info.velocity.z = 0;
867 //--repair-- if (first_time) {
868 //--repair-- int entry_side;
869 //--repair-- current_time = 0;
871 //--repair-- digi_play_sample( SOUND_REPAIR_STATION_PLAYER_ENTERING, F1_0 );
873 //--repair-- entry_side = john_find_connect_side(repair_seg,obj->segnum );
874 //--repair-- Assert( entry_side > -1 );
876 //--repair-- switch( entry_side ) {
877 //--repair-- case WBACK: sidelist = SideOrderBack; break;
878 //--repair-- case WFRONT: sidelist = SideOrderFront; break;
879 //--repair-- case WLEFT: sidelist = SideOrderLeft; break;
880 //--repair-- case WRIGHT: sidelist = SideOrderRight; break;
881 //--repair-- case WTOP: sidelist = SideOrderTop; break;
882 //--repair-- case WBOTTOM: sidelist = SideOrderBottom; break;
884 //--repair-- side_index = 0;
885 //--repair-- next_side = sidelist[side_index];
887 //--repair-- refuel_calc_deltas(obj,next_side, repair_seg);
890 //--repair-- //update shields
891 //--repair-- if (Players[Player_num].shields < MAX_SHIELDS) { //if above max, don't mess with it
893 //--repair-- Players[Player_num].shields += fixmul(FrameTime,repair_rate);
895 //--repair-- if (Players[Player_num].shields > MAX_SHIELDS)
896 //--repair-- Players[Player_num].shields = MAX_SHIELDS;
899 //--repair-- current_time += FrameTime;
901 //--repair-- if (current_time >= delta_time ) {
902 //--repair-- vms_angvec av;
903 //--repair-- obj->pos = goal_pos;
904 //--repair-- av = goal_angles;
905 //--repair-- vm_angles_2_matrix(&obj->orient,&av);
907 //--repair-- if (side_index >= 5 )
908 //--repair-- return 1; // Done being repaired...
910 //--repair-- if (Repairing==0) {
911 //--repair-- //mprintf( (0, "<MACHINE EFFECT ON SIDE %d>\n", next_side ));
912 //--repair-- //digi_play_sample( SOUND_REPAIR_STATION_FIXING );
913 //--repair-- Repairing=1;
915 //--repair-- switch( next_side ) {
916 //--repair-- case 0: digi_play_sample( SOUND_REPAIR_STATION_FIXING_1,F1_0 ); break;
917 //--repair-- case 1: digi_play_sample( SOUND_REPAIR_STATION_FIXING_2,F1_0 ); break;
918 //--repair-- case 2: digi_play_sample( SOUND_REPAIR_STATION_FIXING_3,F1_0 ); break;
919 //--repair-- case 3: digi_play_sample( SOUND_REPAIR_STATION_FIXING_4,F1_0 ); break;
920 //--repair-- case 4: digi_play_sample( SOUND_REPAIR_STATION_FIXING_1,F1_0 ); break;
921 //--repair-- case 5: digi_play_sample( SOUND_REPAIR_STATION_FIXING_2,F1_0 ); break;
924 //--repair-- repair_ship_damage();
928 //--repair-- if (current_time >= (delta_time+(F1_0/2)) ) {
929 //--repair-- current_time = 0;
930 //--repair-- // Find next side...
931 //--repair-- side_index++;
932 //--repair-- if (side_index >= 6 ) return 1;
933 //--repair-- next_side = sidelist[side_index];
935 //--repair-- refuel_calc_deltas(obj, next_side, repair_seg);
938 //--repair-- } else {
939 //--repair-- fix factor, p,b,h;
940 //--repair-- vms_angvec av;
942 //--repair-- factor = fixdiv( current_time,delta_time );
944 //--repair-- // Find object's current position
945 //--repair-- obj->pos = delta_pos;
946 //--repair-- vm_vec_scale( &obj->pos, factor );
947 //--repair-- vm_vec_add2( &obj->pos, &start_pos );
949 //--repair-- // Find object's current orientation
950 //--repair-- p = fixmul(delta_angles.p,factor);
951 //--repair-- b = fixmul(delta_angles.b,factor);
952 //--repair-- h = fixmul(delta_angles.h,factor);
953 //--repair-- av.p = (fixang)p + start_angles.p;
954 //--repair-- av.b = (fixang)b + start_angles.b;
955 //--repair-- av.h = (fixang)h + start_angles.h;
956 //--repair-- vm_angles_2_matrix(&obj->orient,&av);
960 //--repair-- update_object_seg(obj); //update segment
962 //--repair-- return 0;
965 //--repair-- // ----------------------------------------------------------------------------------------------------------
966 //--repair-- //do the repair center for this frame
967 //--repair-- void do_repair_sequence(object *obj)
969 //--repair-- Assert(obj == RepairObj);
971 //--repair-- if (refuel_do_repair_effect( obj, 0, FuelStationSeg )) {
972 //--repair-- if (Players[Player_num].shields < MAX_SHIELDS)
973 //--repair-- Players[Player_num].shields = MAX_SHIELDS;
974 //--repair-- obj->control_type = save_control_type;
975 //--repair-- obj->movement_type = save_movement_type;
976 //--repair-- disable_repair_center=1;
977 //--repair-- RepairObj = NULL;
980 //--repair-- //the two lines below will spit the player out of the rapair center,
981 //--repair-- //but what happen is that the ship just bangs into the door
982 //--repair-- //if (obj->movement_type == MT_PHYSICS)
983 //--repair-- // vm_vec_copy_scale(&obj->mtype.phys_info.velocity,&obj->orient.fvec,i2f(200));
988 //--repair-- // ----------------------------------------------------------------------------------------------------------
989 //--repair-- //see if we should start the repair center
990 //--repair-- void check_start_repair_center(object *obj)
992 //--repair-- if (RepairObj != NULL) return; //already in repair center
994 //--repair-- if (Lsegments[obj->segnum].special_type & SS_REPAIR_CENTER) {
996 //--repair-- if (!disable_repair_center) {
997 //--repair-- //have just entered repair center
999 //--repair-- RepairObj = obj;
1000 //--repair-- repair_save_uvec = obj->orient.uvec;
1002 //--repair-- repair_rate = fixmuldiv(FULL_REPAIR_RATE,(MAX_SHIELDS - Players[Player_num].shields),MAX_SHIELDS);
1004 //--repair-- save_control_type = obj->control_type;
1005 //--repair-- save_movement_type = obj->movement_type;
1007 //--repair-- obj->control_type = CT_REPAIRCEN;
1008 //--repair-- obj->movement_type = MT_NONE;
1010 //--repair-- FuelStationSeg = Lsegments[obj->segnum].special_segment;
1011 //--repair-- Assert(FuelStationSeg != -1);
1013 //--repair-- if (refuel_do_repair_effect( obj, 1, FuelStationSeg )) {
1014 //--repair-- Int3(); //can this happen?
1015 //--repair-- obj->control_type = CT_FLYING;
1016 //--repair-- obj->movement_type = MT_PHYSICS;
1021 //--repair-- disable_repair_center=0;
1025 // --------------------------------------------------------------------------------------------
1026 void disable_matcens(void)
1030 for (i=0; i<Num_robot_centers; i++) {
1031 Station[i].Enabled = 0;
1032 Station[i].Disable_time = 0;
1036 // --------------------------------------------------------------------------------------------
1037 // Initialize all materialization centers.
1038 // Give them all the right number of lives.
1039 void init_all_matcens(void)
1043 for (i=0; i<Num_fuelcenters; i++)
1044 if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
1045 Station[i].Lives = 3;
1046 Station[i].Enabled = 0;
1047 Station[i].Disable_time = 0;
1050 // Make sure this fuelcen is pointed at by a matcen.
1052 for (j=0; j<Num_robot_centers; j++) {
1053 if (RobotCenters[j].fuelcen_num == i)
1056 Assert(j != Num_robot_centers);
1063 // Make sure all matcens point at a fuelcen
1064 for (i=0; i<Num_robot_centers; i++) {
1065 int fuelcen_num = RobotCenters[i].fuelcen_num;
1067 Assert(fuelcen_num < Num_fuelcenters);
1068 Assert(Station[fuelcen_num].Type == SEGMENT_IS_ROBOTMAKER);
1075 extern void multi_send_capture_bonus (char);
1077 void fuelcen_check_for_goal(segment *segp)
1079 segment2 *seg2p = &Segment2s[segp-Segments];
1081 Assert( segp != NULL );
1082 Assert (Game_mode & GM_CAPTURE);
1084 if (seg2p->special==SEGMENT_IS_GOAL_BLUE ) {
1086 if ((get_team(Player_num)==TEAM_BLUE) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1088 mprintf ((0,"In goal segment BLUE\n"));
1090 multi_send_capture_bonus (Player_num);
1091 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1092 maybe_drop_net_powerup (POW_FLAG_RED);
1095 if ( seg2p->special==SEGMENT_IS_GOAL_RED) {
1097 if ((get_team(Player_num)==TEAM_RED) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1099 mprintf ((0,"In goal segment RED\n"));
1100 multi_send_capture_bonus (Player_num);
1101 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1102 maybe_drop_net_powerup (POW_FLAG_BLUE);
1107 void fuelcen_check_for_hoard_goal(segment *segp)
1109 segment2 *seg2p = &Segment2s[segp-Segments];
1111 Assert( segp != NULL );
1112 Assert (Game_mode & GM_HOARD);
1117 if (seg2p->special==SEGMENT_IS_GOAL_BLUE || seg2p->special==SEGMENT_IS_GOAL_RED )
1119 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX])
1121 mprintf ((0,"In orb goal!\n"));
1122 multi_send_orb_bonus (Player_num);
1123 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1124 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]=0;
1132 #ifndef FAST_FILE_IO
1134 * reads an old_matcen_info structure from a CFILE
1136 void old_matcen_info_read(old_matcen_info *mi, CFILE *fp)
1138 mi->robot_flags = cfile_read_int(fp);
1139 mi->hit_points = cfile_read_fix(fp);
1140 mi->interval = cfile_read_fix(fp);
1141 mi->segnum = cfile_read_short(fp);
1142 mi->fuelcen_num = cfile_read_short(fp);
1146 * reads a matcen_info structure from a CFILE
1148 void matcen_info_read(matcen_info *mi, CFILE *fp)
1150 mi->robot_flags[0] = cfile_read_int(fp);
1151 mi->robot_flags[1] = cfile_read_int(fp);
1152 mi->hit_points = cfile_read_fix(fp);
1153 mi->interval = cfile_read_fix(fp);
1154 mi->segnum = cfile_read_short(fp);
1155 mi->fuelcen_num = cfile_read_short(fp);