]> icculus.org git repositories - btb/d2x.git/blob - main/fuelcen.c
bigendian networking fixes
[btb/d2x.git] / main / fuelcen.c
1 /*
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.
12 */
13
14 #ifdef HAVE_CONFIG_H
15 #include <conf.h>
16 #endif
17
18 #ifdef RCS
19 static char rcsid[] = "$Id: fuelcen.c,v 1.6 2003-03-27 01:23:18 btb Exp $";
20 #endif
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <math.h>
25 #include <string.h>
26
27 #include "fuelcen.h"
28 #include "gameseg.h"
29 #include "game.h"               // For FrameTime
30 #include "error.h"
31 #include "mono.h"
32 #include "gauges.h"
33 #include "vclip.h"
34 #include "fireball.h"
35 #include "robot.h"
36 #include "powerup.h"
37
38 #include "wall.h"
39 #include "sounds.h"
40 #include "morph.h"
41 #include "3d.h"
42 #include "bm.h"
43 #include "polyobj.h"
44 #include "ai.h"
45 #include "gamemine.h"
46 #include "gamesave.h"
47 #include "player.h"
48 #include "collide.h"
49 #include "laser.h"
50 #ifdef NETWORK
51 #include "network.h"
52 #include "multi.h"
53 #endif
54 #include "multibot.h"
55 #include "escort.h"
56
57 // The max number of fuel stations per mine.
58
59 fix Fuelcen_refill_speed = i2f(1);
60 fix Fuelcen_give_amount = i2f(25);
61 fix Fuelcen_max_amount = i2f(100);
62
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);
66
67 #define MATCEN_HP_DEFAULT                       F1_0*500; // Hitpoints
68 #define MATCEN_INTERVAL_DEFAULT F1_0*5; //  5 seconds
69
70 matcen_info RobotCenters[MAX_ROBOT_CENTERS];
71 int Num_robot_centers;
72
73 FuelCenter Station[MAX_NUM_FUELCENS];
74 int Num_fuelcenters = 0;
75
76 segment * PlayerSegment= NULL;
77
78 #ifdef EDITOR
79 char    Special_names[MAX_CENTER_TYPES][11] = {
80         "NOTHING   ",
81         "FUELCEN   ",
82         "REPAIRCEN ",
83         "CONTROLCEN",
84         "ROBOTMAKER",
85         "GOAL_RED",
86         "GOAL_BLUE",
87 };
88 #endif
89
90 //------------------------------------------------------------
91 // Resets all fuel center info
92 void fuelcen_reset()
93 {
94         int i;
95
96         Num_fuelcenters = 0;
97         //mprintf( (0, "All fuel centers reset.\n"));
98
99         for(i=0; i<MAX_SEGMENTS; i++ )
100                 Segment2s[i].special = SEGMENT_IS_NOTHING;
101
102         Num_robot_centers = 0;
103
104 }
105
106 #ifndef NDEBUG          //this is sometimes called by people from the debugger
107 void reset_all_robot_centers() 
108 {
109         int i;
110
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;
116                 }
117 }
118 #endif
119
120 //------------------------------------------------------------
121 // Turns a segment into a fully charged up fuel center...
122 void fuelcen_create( segment *segp)
123 {
124         segment2        *seg2p = &Segment2s[segp-Segments];
125
126         int     station_type;
127
128         station_type = seg2p->special;
129
130         switch( station_type )  {
131         case SEGMENT_IS_NOTHING:
132         case SEGMENT_IS_GOAL_BLUE:
133         case SEGMENT_IS_GOAL_RED:
134                 return;
135         case SEGMENT_IS_FUELCEN:
136         case SEGMENT_IS_REPAIRCEN:
137         case SEGMENT_IS_CONTROLCEN:
138         case SEGMENT_IS_ROBOTMAKER:
139                 break;
140         default:
141                 Error( "Invalid station type %d in fuelcen.c\n", station_type );
142         }
143
144         Assert( (seg2p != NULL) );
145         if ( seg2p == NULL ) return;
146
147         Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
148         Assert( Num_fuelcenters > -1 );
149
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);
161
162 //      if (station_type == SEGMENT_IS_ROBOTMAKER)
163 //              Station[Num_fuelcenters].Capacity = i2f(Difficulty_level + 3);
164
165         //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
166         Num_fuelcenters++;
167 }
168
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)
173 {
174         segment2        *seg2p = &Segment2s[segp-Segments];
175
176         int     station_type = seg2p->special;
177
178         Assert( (seg2p != NULL) );
179         Assert(station_type == SEGMENT_IS_ROBOTMAKER);
180         if ( seg2p == NULL ) return;
181
182         Assert( Num_fuelcenters < MAX_NUM_FUELCENS );
183         Assert( Num_fuelcenters > -1 );
184
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;
189
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] );
197
198         seg2p->matcen_num = Num_robot_centers;
199         Num_robot_centers++;
200
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;
205
206         //mprintf( (0, "Segment %d is assigned to be fuel center %d.\n", Station[Num_fuelcenters].segnum, Num_fuelcenters ));
207         Num_fuelcenters++;
208 }
209
210 //------------------------------------------------------------
211 // Adds a segment that already is a special type into the Station array.
212 void fuelcen_activate( segment * segp, int station_type )
213 {
214         segment2        *seg2p = &Segment2s[segp-Segments];
215
216         seg2p->special = station_type;
217
218         if (seg2p->special == SEGMENT_IS_ROBOTMAKER)
219                 matcen_create( segp);
220         else
221                 fuelcen_create( segp);
222         
223 }
224
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))
229
230 //------------------------------------------------------------
231 //      Trigger (enable) the materialization center in segment segnum
232 void trigger_matcen(int segnum)
233 {
234         // -- segment           *segp = &Segments[segnum];
235         segment2                *seg2p = &Segment2s[segnum];
236         vms_vector      pos, delta;
237         FuelCenter      *robotcen;
238         int                     objnum;
239
240         mprintf((0, "Trigger matcen, segment %i\n", segnum));
241
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));
245
246         robotcen = &Station[RobotCenters[seg2p->matcen_num].fuelcen_num];
247
248         if (robotcen->Enabled == 1)
249                 return;
250
251         if (!robotcen->Lives)
252                 return;
253
254         //      MK: 11/18/95, At insane, matcens work forever!
255         if (Difficulty_level+1 < NDL)
256                 robotcen->Lives--;
257
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;
262
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 );
268         if (objnum != -1) {
269                 Objects[objnum].lifeleft = MATCEN_LIFE;
270                 Objects[objnum].ctype.light_info.intensity = i2f(8);    //      Light cast by a fuelcen.
271         } else {
272                 mprintf((1, "Can't create invisible flare for matcen.\n"));
273                 Int3();
274         }
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)));
276 }
277
278 #ifdef EDITOR
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 )
283 {
284         segment2        *seg2p = &Segment2s[segp-Segments];
285         int i, j;
286
287 Restart: ;
288
289         seg2p->special = 0;
290
291         for (i=0; i<Num_fuelcenters; i++ )      {
292                 if ( Station[i].segnum == segp-Segments )       {
293
294                         // If Robot maker is deleted, fix Segments and RobotCenters.
295                         if (Station[i].Type == SEGMENT_IS_ROBOTMAKER) {
296                                 Num_robot_centers--;
297                                 Assert(Num_robot_centers >= 0);
298
299                                 for (j=seg2p->matcen_num; j<Num_robot_centers; j++)
300                                         RobotCenters[j] = RobotCenters[j+1];
301
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--;
306                                 }
307                         }
308
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--;
313
314                         Num_fuelcenters--;
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;
319                         }
320                         goto Restart;
321                 }
322         }
323
324 }
325 #endif
326
327 #define ROBOT_GEN_TIME (i2f(5))
328
329 object * create_morph_robot( segment *segp, vms_vector *object_pos, int object_id)
330 {
331         short           objnum;
332         object  *obj;
333         int             default_behavior;
334
335         Players[Player_num].num_robots_level++;
336         Players[Player_num].num_robots_total++;
337
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);
341
342         if ( objnum < 0 ) {
343                 mprintf((1, "Can't create morph robot.  Aborting morph.\n"));
344                 Int3();
345                 return NULL;
346         }
347
348         obj = &Objects[objnum];
349
350         //Set polygon-object-specific data 
351
352         obj->rtype.pobj_info.model_num = Robot_info[obj->id].model_num;
353         obj->rtype.pobj_info.subobj_flags = 0;
354
355         //set Physics info
356
357         obj->mtype.phys_info.mass = Robot_info[obj->id].mass;
358         obj->mtype.phys_info.drag = Robot_info[obj->id].drag;
359
360         obj->mtype.phys_info.flags |= (PF_LEVELLING);
361
362         obj->shields = Robot_info[obj->id].strength;
363         
364         default_behavior = Robot_info[obj->id].behavior;
365
366         init_ai_object(obj-Objects, default_behavior, -1 );             //      Note, -1 = segment this robot goes to to hide, should probably be something useful
367
368         create_n_segment_path(obj, 6, -1);              //      Create a 6 segment path from creation point.
369
370         Ai_local_info[objnum].mode = ai_behavior_to_mode(default_behavior);
371
372         return obj;
373 }
374
375 int Num_extry_robots = 15;
376
377 #ifndef NDEBUG
378 int     FrameCount_last_msg = 0;
379 #endif
380
381 //      ----------------------------------------------------------------------------------------------------------
382 void robotmaker_proc( FuelCenter * robotcen )
383 {
384         fix             dist_to_player;
385         vms_vector      cur_object_loc; //, direction;
386         int             matcen_num, segnum, objnum;
387         object  *obj;
388         fix             top_time;
389         vms_vector      direction;
390
391         if (robotcen->Enabled == 0)
392                 return;
393
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;
399                 }
400         }
401
402         // mprintf((0, "Capacity of robot maker #%i is %i\n", robotcen - Station, robotcen->Capacity));
403
404         //      No robot making in multiplayer mode.
405 #ifdef NETWORK
406 #ifndef SHAREWARE
407         if ((Game_mode & GM_MULTI) && (!(Game_mode & GM_MULTI_ROBOTS) || !network_i_am_master()))
408                 return;
409 #else
410         if (Game_mode & GM_MULTI)
411                 return;
412 #endif
413 #endif
414
415         // Wait until transmorgafier has capacity to make a robot...
416         if ( robotcen->Capacity <= 0 ) {
417                 return;
418         }
419
420         matcen_num = Segment2s[robotcen->segnum].matcen_num;
421         //mprintf((0, "Robotmaker #%i flags = %8x\n", matcen_num, RobotCenters[matcen_num].robot_flags));
422
423         if ( matcen_num == -1 ) {
424                 mprintf((0, "Non-functional robotcen at %d\n", robotcen->segnum));
425                 return;
426         }
427
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));
430                 return;
431         }
432
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 ) ) {
436                 #ifndef NDEBUG
437                 if (FrameCount > FrameCount_last_msg + 20) {
438                         mprintf((0, "Cannot morph until you kill one!\n"));
439                         FrameCount_last_msg = FrameCount;
440                 }
441                 #endif
442                 return;
443         }
444
445         robotcen->Timer += FrameTime;
446
447         switch( robotcen->Flag )        {
448         case 0:         // Wait until next robot can generate
449                 if (Game_mode & GM_MULTI) 
450                 {
451                         top_time = ROBOT_GEN_TIME;      
452                 }
453                 else 
454                 {
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;
461                 }
462
463                 // mprintf( (0, "Time between morphs %d seconds, dist_to_player = %7.3f\n", f2i(top_time), f2fl(dist_to_player) ));
464
465                 if (robotcen->Timer > top_time )        {
466                         int     count=0;
467                         int     i, my_station_num = robotcen-Station;
468                         object *obj;
469
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)
474                                                 count++;
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;
478                                 return;
479                         }
480
481                         //      Whack on any robot or player in the matcen segment.
482                         count=0;
483                         segnum = robotcen->segnum;
484                         for (objnum=Segments[segnum].objects;objnum!=-1;objnum=Objects[objnum].next)    {
485                                 count++;
486                                 if ( count > MAX_OBJECTS )      {
487                                         mprintf((0, "Object list in segment %d is circular.", segnum ));
488                                         Int3();
489                                         return;
490                                 }
491                                 if (Objects[objnum].type==OBJ_ROBOT) {
492                                         collide_robot_and_materialization_center(&Objects[objnum]);
493                                         robotcen->Timer = top_time/2;
494                                         return;
495                                 } else if (Objects[objnum].type==OBJ_PLAYER ) {
496                                         collide_player_and_materialization_center(&Objects[objnum]);
497                                         robotcen->Timer = top_time/2;
498                                         return;
499                                 }
500                         }
501
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 );
505
506                         if (obj)
507                                 extract_orient_from_segment(&obj->orient,&Segments[robotcen->segnum]);
508
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 );
511                         }
512                         robotcen->Flag  = 1;
513                         robotcen->Timer = 0;
514
515                 }
516                 break;
517         case 1:                 // Wait until 1/2 second after VCLIP started.
518                 if (robotcen->Timer > (Vclip[VCLIP_MORPHING_ROBOT].play_time/2) )       {
519
520                         robotcen->Capacity -= EnergyToCreateOneRobot;
521                         robotcen->Flag = 0;
522
523                         robotcen->Timer = 0;
524                         compute_segment_center(&cur_object_loc, &Segments[robotcen->segnum]);
525
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) {
528                                 int     type;
529                                 uint    flags;
530                                 byte    legal_types[64];                //      64 bits, the width of robot_flags[].
531                                 int     num_types, robot_index, i;
532
533                                 num_types = 0;
534                                 for (i=0;i<2;i++) {
535                                         robot_index = i*32;
536                                         flags = RobotCenters[matcen_num].robot_flags[i];
537                                         while (flags) {
538                                                 if (flags & 1)
539                                                         legal_types[num_types++] = robot_index;
540                                                 flags >>= 1;
541                                                 robot_index++;
542                                         }
543                                 }
544
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"));
549
550                                 if (num_types == 1)
551                                         type = legal_types[0];
552                                 else
553                                         type = legal_types[(d_rand() * num_types) / 32768];
554
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 );
557                                 if (obj != NULL) {
558 #ifndef SHAREWARE
559 #ifdef NETWORK
560                                         if (Game_mode & GM_MULTI)
561                                                 multi_send_create_robot(robotcen-Station, obj-Objects, type);
562 #endif
563 #endif
564                                         obj->matcen_creator = (robotcen-Station) | 0x80;
565
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);
569         
570                                         morph_start( obj );
571                                         //robotcen->last_created_obj = obj;
572                                         //robotcen->last_created_sig = robotcen->last_created_obj->signature;
573                                 } else
574                                         mprintf((0, "Warning: create_morph_robot returned NULL (no objects left?)\n"));
575
576                         }
577   
578                 }
579                 break;
580         default:
581                 robotcen->Flag = 0;
582                 robotcen->Timer = 0;
583         }
584 }
585
586
587 //-------------------------------------------------------------
588 // Called once per frame, replenishes fuel supply.
589 void fuelcen_update_all()
590 {
591         int i;
592         fix AmountToreplenish;
593         
594         AmountToreplenish = fixmul(FrameTime,Fuelcen_refill_speed);
595
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] );
602         
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!    " );
610                                 }
611                         }
612                 }
613         }
614 }
615
616 //--unused-- //-------------------------------------------------------------
617 //--unused-- // replenishes all fuel supplies.
618 //--unused-- void fuelcen_replenish_all()
619 //--unused-- {
620 //--unused--    int i;
621 //--unused-- 
622 //--unused--    for (i=0; i<Num_fuelcenters; i++ )      {
623 //--unused--            Station[i].Capacity = Station[i].MaxCapacity;
624 //--unused--    }
625 //--unused--    //mprintf( (0, "All fuel centers are replenished\n" ));
626 //--unused-- 
627 //--unused-- }
628
629 #define FUELCEN_SOUND_DELAY (f1_0/4)            //play every half second
630
631 //-------------------------------------------------------------
632 fix fuelcen_give_fuel(segment *segp, fix MaxAmountCanTake )
633 {
634         segment2        *seg2p = &Segment2s[segp-Segments];
635
636         static fix last_play_time=0;
637
638         Assert( segp != NULL );
639
640         PlayerSegment = segp;
641
642         if ( (segp) && (seg2p->special==SEGMENT_IS_FUELCEN) )   {
643                 fix amount;
644
645                 detect_escort_goal_accomplished(-4);    //      UGLY! Hack! -4 means went through fuelcen.
646
647 //              if (Station[segp->value].MaxCapacity<=0)        {
648 //                      HUD_init_message( "Fuelcenter %d is destroyed.", segp->value );
649 //                      return 0;
650 //              }
651
652 //              if (Station[segp->value].Capacity<=0)   {
653 //                      HUD_init_message( "Fuelcenter %d is empty.", segp->value );
654 //                      return 0;
655 //              }
656
657                 if (MaxAmountCanTake <= 0 )     {
658 //                      //gauge_message( "Fueled up!");
659                         return 0;
660                 }
661
662                 amount = fixmul(FrameTime,Fuelcen_give_amount);
663
664                 if (amount > MaxAmountCanTake )
665                         amount = MaxAmountCanTake;
666
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;
671 //                      } else {
672 //                              Station[segp->value].Capacity -= amount;
673 //                      }
674
675                 if (last_play_time > GameTime)
676                         last_play_time = 0;
677
678                 if (GameTime > last_play_time+FUELCEN_SOUND_DELAY) {
679
680                         digi_play_sample( SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2 );
681 #ifdef NETWORK
682                         if (Game_mode & GM_MULTI)
683                                 multi_send_play_sound(SOUND_REFUEL_STATION_GIVING_FUEL, F1_0/2);
684 #endif
685
686                         last_play_time = GameTime;
687                 }
688
689
690                 //HUD_init_message( "Fuelcen %d has %d/%d fuel", segp->value,f2i(Station[segp->value].Capacity),f2i(Station[segp->value].MaxCapacity) );
691                 return amount;
692
693         } else {
694                 return 0;
695         }
696 }
697
698 //--unused-- //-----------------------------------------------------------
699 //--unused-- // Damages a fuel center
700 //--unused-- void fuelcen_damage(segment *segp, fix damage )
701 //--unused-- {
702 //--unused--    //int i;
703 //--unused--    // int  station_num = segp->value;
704 //--unused-- 
705 //--unused--    Assert( segp != NULL );
706 //--unused--    if ( segp == NULL ) return;
707 //--unused-- 
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:
711 //--unused--            return;
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;
720 //--unused-- //--                       }
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;
726 //--unused-- //--                       }
727 //--unused-- //--               }
728 //--unused-- //--               //mprintf( (0, "Materializatormografier has %x capacity left\n", Station[station_num].MaxCapacity ));
729 //--unused--            break;
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;
736 //--unused-- //--                       }
737 //--unused-- //--                       if (Station[station_num].MaxCapacity <= 0 )     {
738 //--unused-- //--                               Station[station_num].MaxCapacity = 0;
739 //--unused-- //--                               digi_play_sample( SOUND_REFUEL_STATION_DESTROYED );
740 //--unused-- //--                       }
741 //--unused-- //--               } else {
742 //--unused-- //--                       Station[station_num].MaxCapacity = 0;
743 //--unused-- //--               }
744 //--unused-- //--               HUD_init_message( "Fuelcenter %d damaged", station_num );
745 //--unused--            break;
746 //--unused--    case SEGMENT_IS_REPAIRCEN:
747 //--unused--            break;
748 //--unused--    case SEGMENT_IS_CONTROLCEN:
749 //--unused--            break;
750 //--unused--    default:
751 //--unused--            Error( "Invalid type in fuelcen.c" );
752 //--unused--    }
753 //--unused-- }
754
755 //--unused-- // ----------------------------------------------------------------------------------------------------------
756 //--unused-- fixang my_delta_ang(fixang a,fixang b)
757 //--unused-- {
758 //--unused--    fixang delta0,delta1;
759 //--unused-- 
760 //--unused--    return (abs(delta0 = a - b) < abs(delta1 = b - a)) ? delta0 : delta1;
761 //--unused-- 
762 //--unused-- }
763
764 //--unused-- // ----------------------------------------------------------------------------------------------------------
765 //--unused-- //return though which side of seg0 is seg1
766 //--unused-- int john_find_connect_side(int seg0,int seg1)
767 //--unused-- {
768 //--unused--    segment *Seg=&Segments[seg0];
769 //--unused--    int i;
770 //--unused-- 
771 //--unused--    for (i=MAX_SIDES_PER_SEGMENT;i--;) if (Seg->children[i]==seg1) return i;
772 //--unused-- 
773 //--unused--    return -1;
774 //--unused-- }
775
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;
783
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)
790
791 //--unused-- ubyte save_control_type,save_movement_type;
792
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 };
799
800 //--unused-- int SideUpVector[] = {WBOTTOM, WFRONT, WBOTTOM, WFRONT, WBOTTOM, WBOTTOM };
801
802 //--repair-- // ----------------------------------------------------------------------------------------------------------
803 //--repair-- void refuel_calc_deltas(object *obj, int next_side, int repair_seg)
804 //--repair-- {
805 //--repair--    vms_vector nextcenter, headfvec, *headuvec;
806 //--repair--    vms_matrix goal_orient;
807 //--repair-- 
808 //--repair--    // Find time for this movement
809 //--repair--    delta_time = F1_0;              // one second...
810 //--repair--            
811 //--repair--    // Find start and goal position
812 //--repair--    start_pos = obj->pos;
813 //--repair--    
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);
817 //--repair--    
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);
821 //--repair--    
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 ));
826 //--repair-- 
827 //--repair--    if (next_side == 5)                                             //last side
828 //--repair--            headuvec = &repair_save_uvec;
829 //--repair--    else
830 //--repair--            headuvec = &Segments[repair_seg].sides[SideUpVector[next_side]].normals[0];
831 //--repair-- 
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;
839 //--repair-- }
840 //--repair-- 
841 //--repair-- // ----------------------------------------------------------------------------------------------------------
842 //--repair-- //if repairing, cut it short
843 //--repair-- abort_repair_center()
844 //--repair-- {
845 //--repair--    if (!RepairObj || side_index==5)
846 //--repair--            return;
847 //--repair-- 
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);
852 //--repair-- }
853 //--repair-- 
854 //--repair-- // ----------------------------------------------------------------------------------------------------------
855 //--repair-- void repair_ship_damage()
856 //--repair-- {
857 //--repair--    //mprintf((0,"Repairing ship damage\n"));
858 //--repair-- }
859 //--repair-- 
860 //--repair-- // ----------------------------------------------------------------------------------------------------------
861 //--repair-- int refuel_do_repair_effect( object * obj, int first_time, int repair_seg )        {
862 //--repair-- 
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;                            
866 //--repair-- 
867 //--repair--    if (first_time) {
868 //--repair--            int entry_side;
869 //--repair--            current_time = 0;
870 //--repair-- 
871 //--repair--            digi_play_sample( SOUND_REPAIR_STATION_PLAYER_ENTERING, F1_0 );
872 //--repair-- 
873 //--repair--            entry_side = john_find_connect_side(repair_seg,obj->segnum );
874 //--repair--            Assert( entry_side > -1 );
875 //--repair-- 
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;
883 //--repair--            }
884 //--repair--            side_index = 0;
885 //--repair--            next_side = sidelist[side_index];
886 //--repair-- 
887 //--repair--            refuel_calc_deltas(obj,next_side, repair_seg);
888 //--repair--    } 
889 //--repair-- 
890 //--repair--    //update shields
891 //--repair--    if (Players[Player_num].shields < MAX_SHIELDS) {        //if above max, don't mess with it
892 //--repair-- 
893 //--repair--            Players[Player_num].shields += fixmul(FrameTime,repair_rate);
894 //--repair-- 
895 //--repair--            if (Players[Player_num].shields > MAX_SHIELDS)
896 //--repair--                    Players[Player_num].shields = MAX_SHIELDS;
897 //--repair--    }
898 //--repair-- 
899 //--repair--    current_time += FrameTime;
900 //--repair-- 
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);
906 //--repair-- 
907 //--repair--            if (side_index >= 5 )   
908 //--repair--                    return 1;               // Done being repaired...
909 //--repair-- 
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;
914 //--repair-- 
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;
922 //--repair--                    }
923 //--repair--            
924 //--repair--                    repair_ship_damage();
925 //--repair-- 
926 //--repair--            }
927 //--repair-- 
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];
934 //--repair--    
935 //--repair--                    refuel_calc_deltas(obj, next_side, repair_seg);
936 //--repair--            }
937 //--repair-- 
938 //--repair--    } else {
939 //--repair--            fix factor, p,b,h;      
940 //--repair--            vms_angvec av;
941 //--repair-- 
942 //--repair--            factor = fixdiv( current_time,delta_time );
943 //--repair-- 
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 );
948 //--repair--                    
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);
957 //--repair-- 
958 //--repair--    }
959 //--repair-- 
960 //--repair--    update_object_seg(obj);         //update segment
961 //--repair-- 
962 //--repair--    return 0;
963 //--repair-- }
964 //--repair-- 
965 //--repair-- // ----------------------------------------------------------------------------------------------------------
966 //--repair-- //do the repair center for this frame
967 //--repair-- void do_repair_sequence(object *obj)
968 //--repair-- {
969 //--repair--    Assert(obj == RepairObj);
970 //--repair-- 
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;
978 //--repair-- 
979 //--repair-- 
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));
984 //--repair--    }
985 //--repair-- 
986 //--repair-- }
987 //--repair-- 
988 //--repair-- // ----------------------------------------------------------------------------------------------------------
989 //--repair-- //see if we should start the repair center
990 //--repair-- void check_start_repair_center(object *obj)
991 //--repair-- {
992 //--repair--    if (RepairObj != NULL) return;          //already in repair center
993 //--repair-- 
994 //--repair--    if (Lsegments[obj->segnum].special_type & SS_REPAIR_CENTER) {
995 //--repair-- 
996 //--repair--            if (!disable_repair_center) {
997 //--repair--                    //have just entered repair center
998 //--repair-- 
999 //--repair--                    RepairObj = obj;
1000 //--repair--                    repair_save_uvec = obj->orient.uvec;
1001 //--repair-- 
1002 //--repair--                    repair_rate = fixmuldiv(FULL_REPAIR_RATE,(MAX_SHIELDS - Players[Player_num].shields),MAX_SHIELDS);
1003 //--repair-- 
1004 //--repair--                    save_control_type = obj->control_type;
1005 //--repair--                    save_movement_type = obj->movement_type;
1006 //--repair-- 
1007 //--repair--                    obj->control_type = CT_REPAIRCEN;
1008 //--repair--                    obj->movement_type = MT_NONE;
1009 //--repair-- 
1010 //--repair--                    FuelStationSeg  = Lsegments[obj->segnum].special_segment;
1011 //--repair--                    Assert(FuelStationSeg != -1);
1012 //--repair-- 
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;
1017 //--repair--                    }
1018 //--repair--            }
1019 //--repair--    }
1020 //--repair--    else
1021 //--repair--            disable_repair_center=0;
1022 //--repair-- 
1023 //--repair-- }
1024
1025 //      --------------------------------------------------------------------------------------------
1026 void disable_matcens(void)
1027 {
1028         int     i;
1029
1030         for (i=0; i<Num_robot_centers; i++) {
1031                 Station[i].Enabled = 0;
1032                 Station[i].Disable_time = 0;
1033         }
1034 }
1035
1036 //      --------------------------------------------------------------------------------------------
1037 //      Initialize all materialization centers.
1038 //      Give them all the right number of lives.
1039 void init_all_matcens(void)
1040 {
1041         int     i;
1042
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;
1048 #ifndef NDEBUG
1049 {
1050                         //      Make sure this fuelcen is pointed at by a matcen.
1051                         int     j;
1052                         for (j=0; j<Num_robot_centers; j++) {
1053                                 if (RobotCenters[j].fuelcen_num == i)
1054                                         break;
1055                         }
1056                         Assert(j != Num_robot_centers);
1057 }
1058 #endif
1059
1060                 }
1061
1062 #ifndef NDEBUG
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;
1066
1067                 Assert(fuelcen_num < Num_fuelcenters);
1068                 Assert(Station[fuelcen_num].Type == SEGMENT_IS_ROBOTMAKER);
1069         }
1070 #endif
1071
1072 }
1073
1074 #ifdef NETWORK
1075 extern void multi_send_capture_bonus (char);
1076
1077 void fuelcen_check_for_goal(segment *segp)
1078 {
1079         segment2        *seg2p = &Segment2s[segp-Segments];
1080
1081         Assert( segp != NULL );
1082         Assert (Game_mode & GM_CAPTURE);
1083
1084         if (seg2p->special==SEGMENT_IS_GOAL_BLUE )      {
1085
1086                         if ((get_team(Player_num)==TEAM_BLUE) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1087                          {
1088                                 mprintf ((0,"In goal segment BLUE\n"));
1089
1090                                 multi_send_capture_bonus (Player_num);
1091                                 Players[Player_num].flags &=(~(PLAYER_FLAGS_FLAG));
1092                                 maybe_drop_net_powerup (POW_FLAG_RED);
1093                          }
1094                  }
1095         if ( seg2p->special==SEGMENT_IS_GOAL_RED) {
1096
1097                         if ((get_team(Player_num)==TEAM_RED) && (Players[Player_num].flags & PLAYER_FLAGS_FLAG))
1098                          {              
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);
1103                          }
1104                  }
1105   } 
1106
1107 void fuelcen_check_for_hoard_goal(segment *segp)
1108 {
1109         segment2        *seg2p = &Segment2s[segp-Segments];
1110
1111         Assert( segp != NULL );
1112         Assert (Game_mode & GM_HOARD);
1113
1114    if (Player_is_dead)
1115                 return;
1116
1117         if (seg2p->special==SEGMENT_IS_GOAL_BLUE || seg2p->special==SEGMENT_IS_GOAL_RED  )      
1118         {
1119                 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX])
1120                 {
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;
1125       }
1126         }
1127
1128
1129
1130 #endif
1131
1132 #ifndef FAST_FILE_IO
1133 /*
1134  * reads an old_matcen_info structure from a CFILE
1135  */
1136 void old_matcen_info_read(old_matcen_info *mi, CFILE *fp)
1137 {
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);
1143 }
1144
1145 /*
1146  * reads a matcen_info structure from a CFILE
1147  */
1148 void matcen_info_read(matcen_info *mi, CFILE *fp)
1149 {
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);
1156 }
1157 #endif