00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <math.h>
00017 #include <sys/file.h>
00018
00019 #include "mech.h"
00020 #include "weapons.h"
00021 #include "p.mech.partnames.h"
00022 #include "p.mech.utils.h"
00023
00024 const int num_def_weapons = NUM_DEF_WEAPONS;
00025
00026 int CheckData(dbref player, void *data)
00027 {
00028 int returnValue = 1;
00029
00030 if(data == NULL) {
00031 notify(player, "There is a problem with that item.");
00032 notify(player, "The data is not properly allocated.");
00033 notify(player, "Please notify a director of this.");
00034 returnValue = 0;
00035 }
00036 return (returnValue);
00037 }
00038
00039 void FillDefaultCriticals(MECH * mech, int index)
00040 {
00041 int loop;
00042
00043 for(loop = 0; loop < NUM_CRITICALS; loop++) {
00044 MechSections(mech)[index].criticals[loop].type = EMPTY;
00045 MechSections(mech)[index].criticals[loop].data = 0;
00046 MechSections(mech)[index].criticals[loop].firemode = 0;
00047 MechSections(mech)[index].criticals[loop].ammomode = 0;
00048 }
00049
00050 if(MechType(mech) == CLASS_AERO)
00051 switch (index) {
00052 case AERO_AFT:
00053 for(loop = 0; loop < 12; loop++)
00054 MechSections(mech)[index].criticals[loop].type =
00055 I2Special(HEAT_SINK);
00056 MechSections(mech)[index].criticals[2].type = I2Special(ENGINE);
00057 MechSections(mech)[index].criticals[10].type = I2Special(ENGINE);
00058 break;
00059 }
00060 if(MechType(mech) == CLASS_MECH)
00061 switch (index) {
00062 case HEAD:
00063 MechSections(mech)[index].criticals[0].type =
00064 I2Special(LIFE_SUPPORT);
00065 MechSections(mech)[index].criticals[1].type = I2Special(SENSORS);
00066 MechSections(mech)[index].criticals[2].type = I2Special(COCKPIT);
00067 MechSections(mech)[index].criticals[4].type = I2Special(SENSORS);
00068 MechSections(mech)[index].criticals[5].type =
00069 I2Special(LIFE_SUPPORT);
00070 break;
00071
00072 case CTORSO:
00073 MechSections(mech)[index].criticals[0].type = I2Special(ENGINE);
00074 MechSections(mech)[index].criticals[1].type = I2Special(ENGINE);
00075 MechSections(mech)[index].criticals[2].type = I2Special(ENGINE);
00076 MechSections(mech)[index].criticals[3].type = I2Special(GYRO);
00077 MechSections(mech)[index].criticals[4].type = I2Special(GYRO);
00078 MechSections(mech)[index].criticals[5].type = I2Special(GYRO);
00079 MechSections(mech)[index].criticals[6].type = I2Special(GYRO);
00080 MechSections(mech)[index].criticals[7].type = I2Special(ENGINE);
00081 MechSections(mech)[index].criticals[8].type = I2Special(ENGINE);
00082 MechSections(mech)[index].criticals[9].type = I2Special(ENGINE);
00083 break;
00084
00085 case RTORSO:
00086 case LTORSO:
00087 break;
00088
00089 case LARM:
00090 case RARM:
00091 case LLEG:
00092 case RLEG:
00093 MechSections(mech)[index].criticals[0].type =
00094 I2Special(SHOULDER_OR_HIP);
00095 MechSections(mech)[index].criticals[1].type =
00096 I2Special(UPPER_ACTUATOR);
00097 MechSections(mech)[index].criticals[2].type =
00098 I2Special(LOWER_ACTUATOR);
00099 MechSections(mech)[index].criticals[3].type =
00100 I2Special(HAND_OR_FOOT_ACTUATOR);
00101 break;
00102 }
00103 }
00104
00105 char *ShortArmorSectionString(char type, char mtype, int loc)
00106 {
00107 char **locs;
00108 static char buf[4];
00109 char *c = buf;
00110 int i;
00111
00112 locs = ProperSectionStringFromType(type, mtype);
00113 for(i = 0; locs[loc][i]; i++)
00114 if(isupper(locs[loc][i]) || isdigit(locs[loc][i]))
00115 *(c++) = locs[loc][i];
00116 *c = 0;
00117 return buf;
00118 }
00119
00120 int ArmorSectionFromString(char type, char mtype, char *string)
00121 {
00122 char **locs;
00123 int i, j;
00124 char *c, *d;
00125
00126 if(!string[0])
00127 return -1;
00128 locs = ProperSectionStringFromType(type, mtype);
00129 if(!locs)
00130 return -1;
00131
00132
00133 for(i = 0; locs[i]; i++)
00134 if(!strcasecmp(string, locs[i]))
00135 return i;
00136 for(i = 0; locs[i]; i++) {
00137 if(toupper(string[0]) != locs[i][0])
00138 continue;
00139 for(j = (i + 1); locs[j]; j++)
00140 if(toupper(string[0]) == locs[j][0])
00141 break;
00142 if(!locs[j])
00143 return i;
00144
00145 c = strstr(locs[i], " ");
00146 d = strstr(locs[j], " ");
00147 if(!c && !string[1] && d)
00148 return i;
00149 if(!c && !d)
00150 return -1;
00151 if(!string[1])
00152 continue;
00153 if(c && toupper(string[1]) == *(++c))
00154 return i;
00155 if(d && toupper(string[1]) == *(++d))
00156 return j;
00157 }
00158 return -1;
00159 }
00160
00161 int WeaponIndexFromString(char *string)
00162 {
00163 int id, brand;
00164
00165 if(find_matching_vlong_part(string, NULL, &id, &brand))
00166 if(IsWeapon(id))
00167 return Weapon2I(id);
00168 return -1;
00169 }
00170
00171 int FindSpecialItemCodeFromString(char *buffer)
00172 {
00173 int id, brand;
00174
00175 if(find_matching_vlong_part(buffer, NULL, &id, &brand))
00176 if(IsSpecial(id))
00177 return Special2I(id);
00178 return -1;
00179 }