00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <math.h>
00013 #include <sys/file.h>
00014
00015 #include "mech.h"
00016 #include "mech.events.h"
00017 #include "create.h"
00018 #include "autopilot.h"
00019 #include "p.mech.build.h"
00020 #include "p.mech.utils.h"
00021 #include "p.mechrep.h"
00022 #include "p.mech.c3.h"
00023 #include "p.mech.c3i.h"
00024
00025
00026 #define SPECIAL_FREE 0
00027 #define SPECIAL_ALLOC 1
00028
00029 void clear_mech_from_LOS(MECH * mech)
00030 {
00031 MAP *map;
00032 int i;
00033 MECH *mek;
00034
00035
00036
00037
00038 if(!(map = FindObjectsData(mech->mapindex)))
00039 return;
00040 #ifdef SENSOR_DEBUG
00041 SendSensor(tprintf("LOS info for #%d cleared.", mech->mynum));
00042 #endif
00043 for(i = 0; i < map->first_free; i++) {
00044 map->LOSinfo[mech->mapnumber][i] = 0;
00045 map->LOSinfo[i][mech->mapnumber] = 0;
00046
00047 if(map->mechsOnMap[i] >= 0 && i != mech->mapnumber) {
00048 if(!(mek = getMech(map->mechsOnMap[i])))
00049 continue;
00050 if((MechStatus(mek) & LOCK_TARGET) &&
00051 MechTarget(mek) == mech->mynum) {
00052 mech_notify(mek, MECHALL,
00053 "Weapon system reports the lock has been lost.");
00054 LoseLock(mek);
00055 }
00056 if((map->LOSinfo[i][mech->mapnumber] & MECHLOSFLAG_SEEN) &&
00057 MechTeam(mek) != MechTeam(mech))
00058 MechNumSeen(mek) = MAX(0, MechNumSeen(mek) - 1);
00059 }
00060 }
00061 if(MechStatus(mech) & LOCK_MODES) {
00062 mech_notify(mech, MECHALL,
00063 "Weapon system reports the lock has been lost.");
00064 LoseLock(mech);
00065 }
00066 }
00067
00068 void mech_Rsetxy(dbref player, void *data, char *buffer)
00069 {
00070 MECH *mech = (MECH *) data;
00071 MAP *mech_map = getMap(mech->mapindex);
00072 char *args[3];
00073 int x, y, z, argc;
00074
00075 if(!CheckData(player, mech))
00076 return;
00077 cch(MECH_MAP);
00078 argc = mech_parseattributes(buffer, args, 3);
00079 DOCHECK(argc != 2 && argc != 3, "Invalid number of arguments to SETXY!");
00080 x = atoi(args[0]);
00081 y = atoi(args[1]);
00082 DOCHECK(x >= mech_map->map_width || y >= mech_map->map_height || x < 0
00083 || y < 0, "Invalid coordinates!");
00084 MechX(mech) = x;
00085 MechLastX(mech) = x;
00086 MechY(mech) = y;
00087 MechLastY(mech) = y;
00088 MapCoordToRealCoord(MechX(mech), MechY(mech), &MechFX(mech),
00089 &MechFY(mech));
00090 MechTerrain(mech) = GetTerrain(mech_map, MechX(mech), MechY(mech));
00091 MarkForLOSUpdate(mech);
00092 if(argc == 2) {
00093 MechElev(mech) = GetElev(mech_map, MechX(mech), MechY(mech));
00094 MechZ(mech) = MechElev(mech) - 1;
00095 MechFZ(mech) = ZSCALE * MechZ(mech);
00096 DropSetElevation(mech, 0);
00097 z = MechZ(mech);
00098 if(!Landed(mech) && FlyingT(mech))
00099 MechStatus(mech) |= LANDED;
00100 } else {
00101 z = atoi(args[2]);
00102 MechZ(mech) = z;
00103 MechFZ(mech) = ZSCALE * MechZ(mech);
00104 MechElev(mech) = GetElev(mech_map, MechX(mech), MechY(mech));
00105 }
00106 clear_mech_from_LOS(mech);
00107 notify_printf(player, "Pos changed to %d,%d,%d", x, y, z);
00108 SendLoc(tprintf("#%d set #%d's pos to %d,%d,%d.", player, mech->mynum,
00109 x, y, z));
00110 }
00111
00112
00113 void mech_Rsetmapindex(dbref player, void *data, char *buffer)
00114 {
00115 MECH *mech = (MECH *) data;
00116 char *args[2], *tempstr;
00117 int newindex, nargs, notdone = 0;
00118 int loop;
00119 MAP *newmap = NULL;
00120 MAP *oldmap;
00121 MECH *tempMech;
00122 char targ[2];
00123
00124 if(!CheckData(player, mech))
00125 return;
00126 nargs = mech_parseattributes(buffer, args, 2);
00127 DOCHECK(nargs < 1, "Invalid number of arguments to SETMAPINDX!");
00128 newindex = atoi(args[0]);
00129 DOCHECK(newindex < -1, "Invalid map index!");
00130 if(newindex != -1) {
00131 if(!(newmap = ValidMap(player, newindex)))
00132 return;
00133 }
00134
00135 if(mech->mapindex != -1) {
00136 if(!(oldmap = ValidMap(player, mech->mapindex)))
00137 return;
00138 TAGTarget(mech) = -1;
00139 clearC3iNetwork(mech, 1);
00140 clearC3Network(mech, 1);
00141 remove_mech_from_map(oldmap, mech);
00142 }
00143
00144 if(newindex == -1) {
00145 notify(player, "Mech removed from map.");
00146 SendLoc(tprintf("#%d removed #%d from map #%d.", player,
00147 mech->mynum, oldmap->mynum));
00148 return;
00149 }
00150
00151
00152
00153 if(nargs > 1 && strlen(args[1]) > 1) {
00154 targ[0] = args[1][0];
00155 targ[1] = args[1][1];
00156 } else if((tempstr = silly_atr_get(mech->mynum, A_MECHPREFID))
00157 && strlen(tempstr) > 1) {
00158 targ[0] = tempstr[0];
00159 targ[1] = tempstr[1];
00160 } else {
00161 targ[0] = 65 + Number(0, 25);
00162 targ[1] = 65 + Number(0, 25);
00163 }
00164 targ[0] = BOUNDED('A', toupper(targ[0]), 'Z');
00165 targ[1] = BOUNDED('A', toupper(targ[1]), 'Z');
00166 for(loop = 0; (loop < newmap->first_free && !notdone); loop++) {
00167 if((tempMech = (MECH *)
00168 FindObjectsData(newmap->mechsOnMap[loop])))
00169 if(MechID(tempMech)[0] == targ[0] &&
00170 MechID(tempMech)[1] == targ[1])
00171 notdone = 1;
00172 }
00173 while (notdone) {
00174 targ[0] = 65 + Number(0, 25);
00175 targ[1] = 65 + Number(0, 25);
00176 notdone = 0;
00177 for(loop = 0; (loop < newmap->first_free && !notdone); loop++) {
00178 if((tempMech = (MECH *)
00179 FindObjectsData(newmap->mechsOnMap[loop])))
00180 if(MechID(tempMech)[0] == targ[0] &&
00181 MechID(tempMech)[1] == targ[1])
00182 notdone = 1;
00183 }
00184 }
00185 DOCHECK(loop == MAX_MECHS_PER_MAP,
00186 "There are too many mechs on that map!");
00187 add_mech_to_map(newmap, mech);
00188 MechID(mech)[0] = targ[0];
00189 MechID(mech)[1] = targ[1];
00190 if(MechX(mech) > (newmap->map_width - 1) ||
00191 MechY(mech) > (newmap->map_height - 1)) {
00192 MechX(mech) = 0;
00193 MechLastX(mech) = 0;
00194 MechY(mech) = 0;
00195 MechLastY(mech) = 0;
00196 MapCoordToRealCoord(MechX(mech), MechY(mech), &MechFX(mech),
00197 &MechFY(mech));
00198 MechTerrain(mech) = GetTerrain(newmap, MechX(mech), MechY(mech));
00199 MechElev(mech) = GetElev(newmap, MechX(mech), MechY(mech));
00200 notify(player,
00201 "You're current position is out of bounds, Pos changed to 0,0");
00202 }
00203 notify_printf(player, "MapIndex changed to %d", newindex);
00204 notify_printf(player, "Your ID: %c%c", MechID(mech)[0], MechID(mech)[1]);
00205 SendLoc(tprintf("#%d set #%d's mapindex to #%d.", player, mech->mynum,
00206 newindex));
00207 UnZombifyMech(mech);
00208 }
00209
00210 void mech_Rsetteam(dbref player, void *data, char *buffer)
00211 {
00212 MECH *mech = (MECH *) data;
00213 char *args[1];
00214 int team;
00215 MAP *newmap;
00216
00217 if(!CheckData(player, mech))
00218 return;
00219 DOCHECK(mech->mapindex == -1, "Mech is not on a map: Can't set team");
00220 newmap = ValidMap(player, mech->mapindex);
00221 if(!newmap) {
00222 notify(player, "Map index reset!");
00223 mech->mapindex = -1;
00224 return;
00225 }
00226 DOCHECK(mech_parseattributes(buffer, args, 1) != 1,
00227 "Invalid number of arguments!");
00228 team = atoi(args[0]);
00229 if(team < 0)
00230 team = 0;
00231 MechTeam(mech) = team;
00232 notify_printf(player, "Team set to %d", team);
00233 }
00234
00235 #define SPECIAL_FREE 0
00236 #define SPECIAL_ALLOC 1
00237
00238 extern void auto_stop_pilot(AUTO * autopilot);
00239
00240 void newfreemech(dbref key, void **data, int selector)
00241 {
00242 MECH *new = *data;
00243 MAP *map;
00244 AUTO *a;
00245 int i;
00246 command_node *temp;
00247
00248 switch (selector) {
00249 case SPECIAL_ALLOC:
00250 new->mynum = key;
00251 new->mapnumber = 1;
00252 new->mapindex = -1;
00253 MechID(new)[0] = ' ';
00254 MechID(new)[1] = ' ';
00255 clear_mech(new, 1);
00256 for(i = 0; i < NUM_SECTIONS; i++)
00257 FillDefaultCriticals(new, i);
00258 break;
00259 case SPECIAL_FREE:
00260 if(new->mapindex != -1 && (map = getMap(new->mapindex)))
00261 remove_mech_from_map(map, new);
00262 if(MechAuto(new) > 0 ) {
00263 AUTO *a = (AUTO *) FindObjectsData(MechAuto(new));
00264 if (a) {
00265 auto_stop_pilot(a);
00266
00267 while (dllist_size(a->commands)) {
00268
00269
00270
00271 temp = (command_node *) dllist_remove(a->commands,
00272 dllist_head(a->
00273 commands));
00274
00275
00276 auto_destroy_command_node(temp);
00277
00278 }
00279
00280
00281 dllist_destroy_list(a->commands);
00282 a->commands = NULL;
00283
00284
00285 auto_destroy_astar_path(a);
00286
00287
00288 for(i = 0; i < AUTO_PROFILE_MAX_SIZE; i++) {
00289 if(a->profile[i]) {
00290 rb_destroy(a->profile[i]);
00291 }
00292 a->profile[i] = NULL;
00293 }
00294
00295
00296 auto_destroy_weaplist(a);
00297
00298 a->mymechnum = -1;
00299 }
00300 MechAuto(new) = -1;
00301 }
00302
00303
00304 }
00305 }