news_sup.c

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2005 Michael K. McCarty & Fritz Bronner
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 */
00018 // Interplay's BUZZ ALDRIN's RACE into SPACE
00019 //
00020 // Formerly -=> LiftOff : Race to the Moon :: IBM version MCGA
00021 // Copyright 1991 by Strategic Visions, Inc.
00022 // Designed by Fritz Bronner
00023 // Programmed by Michael K McCarty
00024 //
00025 // Support files for NEWS.C
00026 
00027 #include "Buzz_inc.h"
00028 #include "externs.h"
00029 
00030 /** ???
00031  * 
00032  * \param type 1:postive -1:negative search
00033  */
00034 int Steal(int p,int prog,int type) 
00035 {
00036  int i=0,j=0,k=0,save[28],lo=0,hi=28;
00037  if (prog)EMPTY_BODY;
00038  memset(save,0x00,sizeof save);
00039  for (i=0;i<7;i++)
00040   {
00041    if (Data->P[p].Probe[i].Num>=0 && Data->P[other(p)].Probe[i].Num>=0)
00042     {
00043      if (type==1) save[i]=Data->P[other(p)].Probe[i].Safety-Data->P[p].Probe[i].Safety;
00044       else save[i]=Data->P[p].Probe[i].Safety-Data->P[other(p)].Probe[i].Safety;
00045      if (type==-1 && save[i]<0 && ((Data->P[p].Probe[i].Safety+save[i])<Data->P[p].Probe[i].Base))
00046       save[i]=0;
00047     }
00048    if (Data->P[p].Rocket[i].Num>=0 && Data->P[other(p)].Rocket[i].Num>=0)
00049     {
00050      if (type==1) save[i+7]=Data->P[other(p)].Rocket[i].Safety-Data->P[p].Rocket[i].Safety;
00051       else save[i+7]=Data->P[p].Rocket[i].Safety-Data->P[other(p)].Rocket[i].Safety;
00052      if (type==-1 && save[i+7]<0 && ((Data->P[p].Rocket[i].Safety+save[i+7])<Data->P[p].Rocket[i].Base))
00053       save[i+7]=0;
00054     }
00055    if (Data->P[p].Manned[i].Num>=0 && Data->P[other(p)].Manned[i].Num>=0)
00056     {
00057      if (type==1) save[i+14]=Data->P[other(p)].Manned[i].Safety-Data->P[p].Manned[i].Safety;
00058       else save[i+14]=Data->P[p].Manned[i].Safety-Data->P[other(p)].Manned[i].Safety;
00059      if (type==-1 && save[i+14]<0 && ((Data->P[p].Manned[i].Safety+save[i+14])<Data->P[p].Manned[i].Base))
00060       save[i+7]=0;
00061     }
00062    if (Data->P[p].Misc[i].Num>=0 && Data->P[other(p)].Misc[i].Num>=0)
00063     {
00064      if (type==1) save[i+21]=Data->P[other(p)].Misc[i].Safety-Data->P[p].Misc[i].Safety;
00065       else save[i+21]=Data->P[p].Misc[i].Safety-Data->P[other(p)].Misc[i].Safety;
00066      if (type==-1 && save[i+21]<0 && ((Data->P[p].Misc[i].Safety+save[i+21])<Data->P[p].Misc[i].Base))
00067       save[i+21]=0;
00068     }
00069   };
00070   save[25]=save[26]=save[27]=save[12]=save[13]=save[3]=save[4]=save[5]=save[6]=0;  
00071   if (type==1)
00072    {
00073     for (i=lo;i<hi;i++)
00074       if (save[i]<=0) save[i]=0;  // Positive Only
00075     }
00076   else
00077    {
00078     for (i=lo;i<hi;i++)
00079      if (save[i]>=0) save[i]=0;  // Negatives Only
00080       else save[i]*=-1;
00081     }
00082   for (i=lo;i<hi;i++) if (save[i]>0) j++; // Check if event is good.
00083   if (j==0) return 0;
00084   j=random(hi-lo);
00085   while((k <100) && (save[j+lo] <= 0)) {   // finds candidate
00086     j=random(hi-lo)+lo;
00087     k++;
00088   };
00089   if (k==100) return 0;
00090   if (j>=0 && j<7) {
00091     lo=0;
00092     Data->P[p].Probe[j].Safety+=(save[j]*type);
00093     strcpy(&Name[0],&Data->P[p].Probe[j].Name[0]);
00094   };
00095   if (j>=7 && j<14) {
00096     lo=7;
00097     Data->P[p].Rocket[j-lo].Safety+=(save[j]*type);
00098     strcpy(&Name[0],&Data->P[p].Rocket[j-lo].Name[0]);
00099   };
00100   if (j>=14 && j<21) {
00101     lo=14;
00102     Data->P[p].Manned[j-lo].Safety+=(save[j]*type);
00103     strcpy(&Name[0],&Data->P[p].Manned[j-lo].Name[0]);
00104   };
00105   if (j>=21 && j<28) {
00106     lo=21;
00107     Data->P[p].Misc[j-lo].Safety+=(save[j]*type);
00108     strcpy(&Name[0],&Data->P[p].Misc[j-lo].Name[0]);
00109   };
00110  return save[j];
00111 }
00112 
00113 /** ???
00114  * 
00115  * \param type 1:postive -1:negative search
00116  * \param per Amount of modification in percent
00117  */
00118 int NMod(int p,int prog,int type,int per)
00119 {
00120   int i=0,j=0,save[28],lo=0,hi=28;
00121   Equipment *Eptr[28];
00122   
00123   lo=(prog>0) ? (prog-1)*7 : 0;   hi=(prog>0) ? lo+7 : 28;
00124   if (prog==1) hi=lo+3;
00125   /* drvee: this loop was going to 25, not 28 */
00126   for (i=0;i<(int)ARRAY_LENGTH(Eptr);i++)
00127    {
00128        /** \bug Mismatch between data.h(250) and this code here */
00129     Eptr[i]=(Equipment *) &Data->P[p].Probe[i];
00130     save[i]= ((Eptr[i]->Safety+per*type)<=(Eptr[i]->MaxSafety)&& Eptr[i]->Num>=0) ? Eptr[i]->Safety+per*type : 0;
00131     if (Eptr[i]->Num<0) save[i]=0;
00132    };
00133   for(i=0;i<(int)ARRAY_LENGTH(save);i++) if (save[i]<0) save[i]=0;
00134   save[11]=save[25]=save[26]=save[27]=save[12]=save[13]=save[3]=save[4]=save[5]=save[6]=0;  
00135   for (i=lo;i<hi;i++) if (save[i]>0) j++; // Check if event is good.
00136   if (j==0) return 0;           
00137   j=hi-1; while(save[j] == 0) j--;
00138   // Increment value and return program name
00139   Eptr[j]->Safety=save[j];
00140   strcpy(&Name[0],&Eptr[j]->Name[0]);
00141   if(Eptr[j]->Safety>Eptr[j]->MaxSafety) Eptr[j]->Safety=Eptr[j]->MaxSafety;
00142   return save[j];
00143 }
00144 
00145 
00146 int DamMod(int p,int prog,int dam,int cost)
00147 {
00148   int i=0,j=0,lo=0,hi=28;
00149   int save[28];
00150   Equipment *Eptr[28];
00151   
00152   memset(save,0x00,sizeof save);
00153   lo=(prog>0) ? (prog-1)*7 : 0;
00154   hi=(prog>0) ? lo+7 : 28;
00155   for (i=0;i<25;i++)
00156    {
00157     Eptr[i]=(Equipment *) &Data->P[p].Probe[i];
00158     save[i]= ((Eptr[i]->Safety > Eptr[i]->Base)&& Eptr[i]->Num>=0) ? Eptr[i]->Safety : 0;
00159    };
00160   for (i=0;i<25;i++) if ( save[i] <dam ) save[i]=0;
00161   save[25]=save[26]=save[27]=save[12]=save[13]=save[3]=save[4]=save[5]=save[6]=save[11]=0;
00162   save[19]=save[20]=0; //remove LM's
00163   for (i=lo;i<hi;i++) if (save[i]>0) j++; // Check if event is good.
00164   if (j==0) return 0;
00165   j=hi-1; while(save[j]==0) j--;
00166   strcpy(&Name[0],&Eptr[j]->Name[0]);
00167   Eptr[j]->Damage=dam;
00168   Eptr[j]->DCost=cost;
00169   return save[j];
00170 }
00171 
00172 
00173 int RDMods(int p,int prog,int type,int val)
00174 {
00175   int i=0,j=0,save[28],lo=0,hi=28;
00176   Equipment *Eptr[28];
00177   
00178   memset(save,0x00,sizeof save);
00179   lo=(prog>0) ? (prog-1)*7 : 0;
00180   hi=(prog>0) ? lo+7 : 28;
00181   for (i=0;i<25;i++)
00182    {
00183     Eptr[i]=(Equipment *) &Data->P[p].Probe[i];
00184     save[i]= ((Eptr[i]->Safety > Eptr[i]->Base)&& Eptr[i]->Num>=0) ? Eptr[i]->Safety : 0;
00185    };
00186   save[11]=save[25]=save[26]=save[27]=save[12]=save[13]=save[3]=save[4]=save[5]=save[6]=0;
00187   for(i=0;i<28;i++) if (save[i]<0) save[i]=0;
00188   for (i=lo;i<hi;i++) if (save[i]>0) j++; // Check if event is good.
00189   if (j==0) return 0;
00190   j=hi-1; while(save[j]==0) j--;
00191   strcpy(&Name[0],&Eptr[j]->Name[0]);
00192   Eptr[j]->RDCost+=type*val;
00193   return save[j];
00194 }
00195 
00196 
00197 int SaveMods(char p,char prog)
00198 {
00199   int i=0,j=0,save[28],lo=0,hi=28;
00200 
00201   for (i=0;i<28;i++) save[i]=0;
00202   switch (prog) {
00203     case 0: lo=0; hi=21;break;   // check ALL    programs
00204     case 1: lo=0; hi=7;break;    // check PROBE  programs
00205     case 2: lo=7; hi=14;break;   // check ROCKET programs
00206     case 3: lo=14; hi=18;break;  // check MANNED programs
00207     case 4: lo=18; hi=21;break;  // check LEM   programs
00208   };
00209   for (i=0;i<7;i++)
00210    {
00211     if (Data->P[p].Probe[i].Num>=0) save[i]=1;
00212     if (Data->P[p].Rocket[i].Num>=0) save[i+7]=1;
00213     if (Data->P[p].Manned[i].Num>=0) save[i+14]=1;
00214     if (Data->P[p].Misc[i].Num>=0) save[i+21]=1;
00215    };
00216   save[11]=save[25]=save[26]=save[27]=save[12]=save[13]=save[3]=save[4]=save[5]=save[6]=0;  
00217   for (i=lo;i<hi;i++) if (save[i]>0) j++; // Check if event is good.
00218   if (j==0) return 0;
00219   j=hi-1;while(save[j] == 0) j--;
00220   // Increment value and return program name
00221   if (j>=0 && j<7) {
00222     Data->P[p].Probe[j].SaveCard=1;
00223     strcpy(&Name[0],&Data->P[p].Probe[j].Name[0]);
00224   };
00225   if (j>=7 && j<14) {
00226     Data->P[p].Rocket[j-7].SaveCard=1;
00227     strcpy(&Name[0],&Data->P[p].Rocket[j-7].Name[0]);
00228   };
00229   if (j>=14 && j<21) {
00230     Data->P[p].Manned[j-14].SaveCard=1;
00231     strcpy(&Name[0],&Data->P[p].Manned[j-14].Name[0]);
00232   };
00233   return save[j];
00234 }
00235 
00236 // EOF

Generated on Fri Sep 28 00:35:45 2007 for raceintospace by  doxygen 1.5.3