src/hcode/btech/p.map.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void debug_fixmap (dbref player, void *data, char *buffer)
void map_view (dbref player, void *data, char *buffer)
void map_addhex (dbref player, void *data, char *buffer)
void map_mapemit (dbref player, void *data, char *buffer)
int water_distance (MAP *map, int x, int y, int dir, int max)
int map_load (MAP *map, char *mapname)
void map_loadmap (dbref player, void *data, char *buffer)
void map_savemap (dbref player, void *data, char *buffer)
void map_setmapsize (dbref player, void *data, char *buffer)
void map_clearmechs (dbref player, void *data, char *buffer)
void map_update (dbref obj, void *data)
void initialize_map_empty (MAP *new, dbref key)
void newfreemap (dbref key, void **data, int selector)
int map_sizefun (void *data, int flag)
void map_listmechs (dbref player, void *data, char *buffer)
void clear_hex (MECH *mech, int x, int y, int meant)
void map_pathfind (dbref player, void *data, char *buffer)
void UpdateMechsTerrain (MAP *map, int x, int y, int t)


Function Documentation

void clear_hex ( MECH mech,
int  x,
int  y,
int  meant 
)

Definition at line 658 of file map.c.

References getMap(), GetTerrain, GRASSLAND, HEAVY_FOREST, LIGHT_FOREST, MECH::mapindex, mech_printf(), MECHALL, MechLOSBroadcast(), Number, ROUGH, SetTerrain, and tprintf().

Referenced by possibly_clear().

00659 {
00660         MAP *map;
00661 
00662         if(!(map = getMap(mech->mapindex)))
00663                 return;
00664         switch (GetTerrain(map, x, y)) {
00665         case HEAVY_FOREST:
00666                 SetTerrain(map, x, y, LIGHT_FOREST);
00667                 break;
00668         case LIGHT_FOREST:
00669                 if(Number(1, 2) == 1)
00670                         SetTerrain(map, x, y, ROUGH);
00671                 else
00672                         SetTerrain(map, x, y, GRASSLAND);
00673                 break;
00674         default:
00675                 return;
00676         }
00677         if(meant) {
00678                 MechLOSBroadcast(mech, tprintf("'s shot clears %d,%d!", x, y));
00679                 mech_printf(mech, MECHALL, "You clear %d,%d.", x, y);
00680         } else {
00681                 MechLOSBroadcast(mech, tprintf("'s stray shot clears %d,%d!", x, y));
00682                 mech_printf(mech, MECHALL, "You accidentally clear the %d,%d!", x, y);
00683         }
00684 }

void debug_fixmap ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 36 of file map.c.

References Contents, DOLIST, MAP::first_free, getMech(), GTYPE_MECH, Hardcode, IsMech, MECH::mapindex, MECH::mapnumber, MAP::mechsOnMap, MAP::mynum, notify_printf(), and WhichSpecial().

Referenced by load_update1().

00037 {
00038         MAP *m = (MAP *) data;
00039         int i, k;
00040         MECH *mek;
00041 
00042         if(!m)
00043                 return;
00044         notify_printf(player, "Checking %d entries..", m->first_free);
00045         DOLIST(k, Contents(m->mynum)) {
00046                 if(Hardcode(k)) {
00047                         if(WhichSpecial(k) == GTYPE_MECH) {
00048                                 MECH *mek;
00049 
00050                                 /* Check if it's on the map */
00051                                 for(i = 0; i < m->first_free; i++)
00052                                         if(m->mechsOnMap[i] == k)
00053                                                 break;
00054                                 if(i != m->first_free)
00055                                         continue;
00056                                 mek = getMech(k);
00057                                 mek->mapindex = -1;     /* Eep. */
00058                                 mek->mapnumber = 0;
00059                         }
00060                 }
00061         }
00062         for(i = 0; i < m->first_free; i++)
00063                 if((k = m->mechsOnMap[i]) >= 0) {
00064                         if(!IsMech(k)) {
00065                                 notify_printf(player,
00066                                                           "Error: #%d isn't mech yet is in mapindex. Fixing..",
00067                                                           k);
00068                                 m->mechsOnMap[i] = -1;
00069                         } else if(!(mek = getMech(k))) {
00070                                 notify_printf(player,
00071                                                           "Error: #%d has no mech data. Removing..", k);
00072                                 m->mechsOnMap[i] = -1;
00073                         } else if(mek->mapindex != m->mynum) {
00074                                 notify_printf(player,
00075                                                           "Error: #%d isn't really here! Removing..", k);
00076                                 m->mechsOnMap[i] = -1;
00077                         } else if(mek->mapnumber != i) {
00078                                 notify_printf(player,
00079                                                           "Error: #%d has invalid mapnumber (mn:%d <-> real:%d)..",
00080                                                           k, mek->mapnumber, i);
00081                         }
00082                 }
00083         notify(player, "Done.");
00084 }

void initialize_map_empty ( MAP new,
dbref  key 
)

Definition at line 549 of file map.c.

References Create, DEFAULT_MAP_HEIGHT, DEFAULT_MAP_WIDTH, MAP::map, MAP::map_height, MAP::map_width, and SetMap.

Referenced by load_update1(), and newfreemap().

00550 {
00551         int i, j;
00552 
00553         new->mynum = key;
00554         new->map_width = DEFAULT_MAP_WIDTH;
00555         new->map_height = DEFAULT_MAP_HEIGHT;
00556         Create(new->map, unsigned char *, new->map_height);
00557 
00558         for(i = 0; i < new->map_height; i++)
00559                 Create(new->map[i], unsigned char, new->map_width);
00560 
00561         for(i = 0; i < new->map_height; i++)
00562                 for(j = 0; j < new->map_width; j++)
00563                         SetMap(new, j, i, ' ', 0);
00564 }

void map_addhex ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 153 of file map.c.

References args, CheckData(), DOCHECK, MAX_ELEV, mech_parseattributes(), notify, SetElevation, SetTerrain, x, and y.

00154 {
00155         MAP *map;
00156         int x, y, argc;
00157         char *args[4], elev;
00158 
00159         map = (MAP *) data;
00160         if(!CheckData(player, map))
00161                 return;
00162         argc = mech_parseattributes(buffer, args, 4);
00163         DOCHECK(argc != 4, "Invalid number of arguments!");
00164         x = atoi(args[0]);
00165         y = atoi(args[1]);
00166         elev = abs(atoi(args[3]));
00167         DOCHECK(!((x >= 0) && (x < map->map_width) && (y >= 0) &&
00168                           (y < map->map_height)), "X,Y out of range!");
00169         if(args[2][0] == '.')
00170                 SetTerrain(map, x, y, ' ');
00171         else
00172                 SetTerrain(map, x, y, args[2][0]);
00173         SetElevation(map, x, y, (elev <= MAX_ELEV) ? elev : MAX_ELEV);
00174         notify(player, "Hex set!");
00175 }

void map_clearmechs ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 492 of file map.c.

References CheckData(), MAP::mynum, and ShutDownMap().

Referenced by fun_btloadmap(), and map_loadmap().

00493 {
00494         MAP *map;
00495 
00496         map = (MAP *) data;
00497         if(CheckData(player, map))
00498                 ShutDownMap(player, map->mynum);
00499 }

void map_listmechs ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 605 of file map.c.

References args, CheckData(), DOCHECK, MAP::first_free, getMech(), list_mapobjs(), listmatch(), MAX_MECHS_PER_MAP, mech_parseattributes(), MechIDS(), MAP::mechsOnMap, notify, and notify_printf().

00606 {
00607         MAP *map;
00608         MECH *tempMech;
00609         int i;
00610         int count = 0;
00611         char valid[50];
00612         char *ID;
00613         char *args[2];
00614         char *cmds[] = { "MECHS", "OBJS", NULL };
00615         enum {
00616                 MECHS, OBJS
00617         };
00618 
00619         map = (MAP *) data;
00620 
00621         if(!CheckData(player, map))
00622                 return;
00623         DOCHECK(mech_parseattributes(buffer, args, 1) == 0,
00624                         "Supply target type too!");
00625         switch (listmatch(cmds, args[0])) {
00626         case MECHS:
00627                 notify(player, "--- Mechs on Map ---");
00628                 for(i = 0; i < map->first_free; i++) {
00629                         if(map->mechsOnMap[i] != -1) {
00630                                 tempMech = getMech(map->mechsOnMap[i]);
00631                                 ID = MechIDS(tempMech, 0);
00632                                 if(tempMech)
00633                                         strcpy(valid, "Valid Data");
00634                                 else
00635                                         strcpy(valid, "Invalid Object Data!  Remove this Mech!");
00636                                 notify_printf(player, "Mech DB Number: %d : [%s]\t%s",
00637                                                           map->mechsOnMap[i], ID, valid);
00638                                 count++;
00639                         }
00640                 }
00641                 notify_printf(player, "%d Mechs On Map", count);
00642                 notify_printf(player, "%d positions open", MAX_MECHS_PER_MAP - count);
00643                 if(count != map->first_free)
00644                         notify_printf(player,
00645                                                   "%d is first free slot, according to db.",
00646                                                   map->first_free);
00647                 return;
00648                 break;
00649         case OBJS:
00650                 list_mapobjs(player, map);
00651                 return;
00652                 break;
00653         }
00654         notify_printf(player, "Invalid argument (%s)!", args[0]);
00655         return;
00656 }

int map_load ( MAP map,
char *  mapname 
)

Definition at line 244 of file map.c.

References Create, DEFAULT_MAP_HEIGHT, DEFAULT_MAP_WIDTH, del_mapobjs(), FIRE, MAP::flags, GetTerrainName_base(), GRASSLAND, LIGHT_FOREST, MAP::map, MAP::map_height, MAP_NAME_SIZE, MAP_PATH, MAPFLAG_FIRES, MAPX, MAPY, my_open_file(), MAP::mynum, SendError, SetMap, SMOKE, TFIRE, and tprintf().

Referenced by fun_btloadmap(), and map_loadmap().

00245 {
00246         char openfile[50];
00247         char terr, elev;
00248         int i1, i2, i3;
00249         FILE *fp;
00250         char row[MAPX * 2 + 3];
00251         int i, j = 0, height, width, filemode;
00252 
00253         if(strlen(mapname) >= MAP_NAME_SIZE)
00254                 mapname[MAP_NAME_SIZE] = 0;
00255         sprintf(openfile, "%s/%s", MAP_PATH, mapname);
00256         fp = my_open_file(openfile, "r", &filemode);
00257         if(!fp) {
00258                 return -1;
00259         }
00260         del_mapobjs(map);                       /* Just in case */
00261         if(map->map) {
00262                 for(i = 0; i < map->map_height; i++)
00263                         free((char *) (map->map[i]));
00264                 free((char *) (map->map));
00265         }
00266         if(fscanf(fp, "%d %d\n", &height, &width) != 2 || height < 1 ||
00267            height > MAPY || width < 1 || width > MAPX) {
00268                 SendError(tprintf("Map #%d: Invalid height and/or width",
00269                                                   map->mynum));
00270                 width = DEFAULT_MAP_WIDTH;
00271                 height = DEFAULT_MAP_HEIGHT;
00272         }
00273         Create(map->map, unsigned char *, height);
00274 
00275         for(i = 0; i < height; i++)
00276                 Create(map->map[i], unsigned char, width);
00277 
00278         for(i = 0; i < height; i++) {
00279                 if(feof(fp)
00280                    || fgets(row, 2 * MAPX + 2, fp) == NULL ||
00281                    strlen(row) < (2 * width)) {
00282                         break;
00283                 }
00284                 for(j = 0; j < width; j++) {
00285                         terr = row[2 * j];
00286                         elev = row[2 * j + 1] - '0';
00287                         switch (terr) {
00288                         case FIRE:
00289                                 map->flags |= MAPFLAG_FIRES;
00290                                 break;
00291                         case TFIRE:
00292                         case SMOKE:
00293                         case '.':
00294                                 terr = GRASSLAND;
00295                                 break;
00296                         case '\'':
00297                                 terr = LIGHT_FOREST;
00298                                 break;
00299                         }
00300                         if(!strcmp(GetTerrainName_base(terr), "Unknown")) {
00301                                 SendError(tprintf
00302                                                   ("Map #%d: Invalid terrain at %d,%d: '%c'",
00303                                                    map->mynum, j, i, terr));
00304                                 terr = GRASSLAND;
00305                         }
00306                         SetMap(map, j, i, terr, elev);
00307                 }
00308         }
00309         if(i != height) {
00310                 SendError(tprintf("Error: EOF reached prematurely. "
00311                                                   "(x%d != %d || y%d != %d)", j, width, i, height));
00312                 my_close_file(fp, &filemode);
00313                 return -2;
00314         }
00315         map->grav = 100;
00316         map->temp = 20;
00317         if(!feof(fp)) {
00318                 if(fscanf(fp, "%d: %d %d\n", &i1, &i2, &i3) == 3) {
00319                         map->flags = i1;
00320                         map->grav = i2;
00321                         map->temp = i3;
00322                 }
00323         }
00324         map->map_height = height;
00325         map->map_width = width;
00326         if(!MapNoBridgify(map))
00327                 make_bridges(map);
00328         sprintf(map->mapname, mapname);
00329         my_close_file(fp, &filemode);
00330         return 0;
00331 }

void map_loadmap ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 333 of file map.c.

References args, CheckData(), DOCHECK, map_clearmechs(), map_load(), mech_parseattributes(), notify, and notify_printf().

Referenced by load_update1().

00334 {
00335         MAP *map;
00336         char *args[1];
00337 
00338         map = (MAP *) data;
00339 
00340         if(!CheckData(player, map))
00341                 return;
00342 
00343         DOCHECK(mech_parseattributes(buffer, args, 1) != 1,
00344                         "Invalid number of arguments!");
00345         notify_printf(player, "Loading %s", args[0]);
00346         switch (map_load(map, args[0])) {
00347         case -1:
00348                 notify(player, "Map not found.");
00349                 return;
00350         case -2:
00351                 notify(player, "Map invalid.");
00352                 return;
00353         case 0:
00354                 notify(player, "Map loaded.");
00355                 break;
00356         default:
00357                 notify(player, "Unknown error while loading map!");
00358                 return;
00359         }
00360 
00361         if(player != 1) {
00362                 notify(player, "Clearing Mechs off Newly Loaded Map");
00363                 map_clearmechs(player, data, "");
00364         }
00365 }

void map_mapemit ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 177 of file map.c.

References CheckData(), DOCHECK, MapBroadcast(), and notify.

00178 {
00179         MAP *map;
00180 
00181         map = (MAP *) data;
00182         if(!CheckData(player, map))
00183                 return;
00184         while (*buffer == ' ')
00185                 buffer++;
00186         DOCHECK(!buffer || !*buffer, "What do you want to @mapemit?");
00187         MapBroadcast(map, buffer);
00188         notify(player, "Message sent!");
00189 }

void map_pathfind ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 690 of file map.c.

References args, BOUNDED(), DOCHECK, mech_parseattributes(), readval, spath_map, and time().

00691 {
00692         MAP *map = (MAP *) data;
00693         char *args[6];
00694         int argc;
00695         int x1, y1, x2, y2;
00696         time_t start_t;
00697         int errper = -1;
00698 
00699         if(!map)
00700                 return;
00701         argc = mech_parseattributes(buffer, args, 6);
00702         DOCHECK((argc < 4 || argc > 5), "Invalid arguments!");
00703         readval(x1, args[0]);
00704         readval(y1, args[1]);
00705         readval(x2, args[2]);
00706         readval(y2, args[3]);
00707         if(argc > 4) {
00708                 readval(errper, args[4]);
00709                 errper = BOUNDED(0, errper, 1000);
00710         }
00711         spath_map = map;
00712         start_t = time(NULL);
00713 }

void map_savemap ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 369 of file map.c.

References args, CheckData(), DOCHECK, find_mapobj(), FIRE, MAP::flags, GetElevation, GetRTerrain, GetTerrain, MAP::map_height, MAP_NAME_SIZE, MAP_PATH, MAP::map_width, MAPFLAG_FIRES, MAPX, mech_parseattributes(), my_open_file(), notify_printf(), SendEvent, SetTerrain, SMOKE, TFIRE, tprintf(), and TYPE_FIRE.

00370 {
00371         MAP *map;
00372         char *args[1];
00373         FILE *fp;
00374         char openfile[50];
00375         int i, j;
00376         char row[MAPX * 2 + 1];
00377         char terrain;
00378         int filemode;
00379 
00380         map = (MAP *) data;
00381 
00382         if(!CheckData(player, map))
00383                 return;
00384 
00385         DOCHECK(mech_parseattributes(buffer, args, 1) != 1,
00386                         "Invalid number of arguments!");
00387         if(strlen(args[0]) >= MAP_NAME_SIZE)
00388                 args[MAP_NAME_SIZE] = 0;
00389         notify_printf(player, "Saving %s", args[0]);
00390         sprintf(openfile, "%s/", MAP_PATH);
00391         strcat(openfile, args[0]);
00392         DOCHECK(!(fp =
00393                           my_open_file(openfile, "w", &filemode)),
00394                         "Unable to open the map file!");
00395         fprintf(fp, "%d %d\n", map->map_height, map->map_width);
00396         for(i = 0; i < map->map_height; i++) {
00397                 mapobj *mo;
00398 
00399                 row[0] = 0;
00400                 for(j = 0; j < map->map_width; j++) {
00401                         terrain = GetTerrain(map, j, i);
00402                         switch (terrain) {
00403                         case ' ':
00404                                 terrain = '.';
00405                                 break;
00406                         case FIRE:
00407                                 /* check if we're burnin', if so, alter terrain type */
00408                                 if((mo = find_mapobj(map, j, i, TYPE_FIRE)))
00409                                         terrain = TFIRE;
00410                                 else if(!(map->flags & MAPFLAG_FIRES)) {
00411                                         SetTerrain(map, j, i, ' ');
00412                                         SendEvent(tprintf
00413                                                           ("[lost?] fire event noticed on map #%d (%s) at %d,%d",
00414                                                            map->mynum, map->mapname, j, i));
00415                                         terrain = '.';
00416                                 }
00417                                 break;
00418                         case SMOKE:
00419                                 terrain = GetRTerrain(map, j, i);
00420                                 if(terrain == ' ')
00421                                         terrain = '.';
00422                                 if(terrain == SMOKE) {
00423                                         SetTerrain(map, j, i, ' ');
00424                                         SendEvent(tprintf
00425                                                           ("[lost?] smoke event noticed on map #%d (%s) at %d,%d",
00426                                                            map->mynum, map->mapname, j, i));
00427                                         terrain = '.';
00428                                 }
00429                                 break;
00430                         }
00431                         row[j * 2] = terrain;
00432                         row[j * 2 + 1] = GetElevation(map, j, i) + '0';
00433                 }
00434                 row[j * 2] = 0;
00435                 fprintf(fp, "%s\n", row);
00436         }
00437         if((i = (map->flags & ~(MAPFLAG_MAPO))))
00438                 fprintf(fp, "%d: %d %d\n", i, map->grav, map->temp);
00439         notify(player, "Saving complete!");
00440         my_close_file(fp, &filemode);
00441 }

void map_setmapsize ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 443 of file map.c.

References args, CheckData(), Create, del_mapobjs(), DOCHECK, GetElevation, GetTerrain, MAP::map, MAP::map_height, MAP::map_width, MAP::mapobj, MAPX, MAPY, mech_parseattributes(), notify, SendError, SetMapB, TYPE_BITS, x, and y.

00444 {
00445         MAP *oldmap;
00446         unsigned char **map;
00447         int x, y, i, j, failed = 0, argc, x1, y1;
00448         char *args[4];
00449 
00450         oldmap = (MAP *) data;
00451         if(!CheckData(player, oldmap))
00452                 return;
00453         DOCHECK(oldmap->mapobj[TYPE_BITS], "Invalid map for size change, sorry.");
00454         DOCHECK((argc =
00455                          mech_parseattributes(buffer, args, 4)) != 2,
00456                         "Invalid number of arguments (X/Y expected)");
00457         x = atoi(args[0]);
00458         y = atoi(args[1]);
00459         DOCHECK(!((x >= 0) && (x <= MAPX) && (y >= 0) &&
00460                           (y <= MAPY)), "X,Y out of range!");
00461         /* allocate new map space */
00462         Create(map, unsigned char *, y);
00463         for(i = 0; i < y; i++)
00464                 Create(map[i], unsigned char, x);
00465 
00466         if(failed)
00467                 SendError("Memory allocation failed in setmapsize!");
00468         else {
00469                 /* Initialize the hexes in the new map to blank */
00470                 for(i = 0; i < y; i++)
00471                         for(j = 0; j < x; j++)
00472                                 SetMapB(map, j, i, ' ', 0);
00473                 /* Copy old map into new map */
00474                 x1 = (oldmap->map_width < x) ? oldmap->map_width : x;
00475                 y1 = (oldmap->map_height < y) ? oldmap->map_height : y;
00476                 for(i = 0; i < y1; i++)
00477                         for(j = 0; j < x1; j++)
00478                                 SetMapB(map, j, i, GetTerrain(oldmap, j, i),
00479                                                 GetElevation(oldmap, j, i));
00480                 /* Now free the old map */
00481                 for(i = oldmap->map_height - 1; i >= 0; i--)
00482                         free((char *) (oldmap->map[i]));
00483                 del_mapobjs(oldmap);
00484                 /* set new map size and pointer to new map space */
00485                 oldmap->map_height = y;
00486                 oldmap->map_width = x;
00487                 oldmap->map = map;
00488                 notify(player, "Size set.");
00489         }
00490 }

int map_sizefun ( void *  data,
int  flag 
)

Definition at line 592 of file map.c.

References MAP::map.

00593 {
00594         MAP *map = (MAP *) data;
00595         int size = 0;
00596 
00597         if(!map)
00598                 return 0;
00599         size = sizeof(*map);
00600         if(map->map)
00601                 size += sizeof(*map->map);
00602         return size;
00603 }

void map_update ( dbref  obj,
void *  data 
)

Definition at line 503 of file map.c.

References A_MAPVIS, BOUNDED(), MAP::cloudbase, MAP::first_free, getMech(), LBUF_SIZE, MAP::maplight, MAP::mapvis, MAP::maxvis, mech_notify(), MECHALL, MAP::mechsOnMap, muxevent_tick, sensor_light_availability_check(), silly_atr_get(), update_LOSinfo(), MAP::winddir, and MAP::windspeed.

00504 {
00505         MAP *map = ((MAP *) data);
00506         MECH *mech;
00507         char *tmps, changemsg[LBUF_SIZE] = "";
00508         int ma, ml, wind, wspeed, cloudbase = 200;
00509         int oldl, oldv, i, j;
00510         AUTO *au;
00511 
00512         /* Changed from % 25 to % 60. %60 never hit when muxevent_tick came here and was odd.
00513            % 25 should hit when its odd or even (25 75 125... when odd 50 100 150... when even */
00514 
00515         if(!(muxevent_tick % 25)) {
00516                 oldl = map->maplight;
00517                 oldv = map->mapvis;
00518                 if(!(tmps = silly_atr_get(obj, A_MAPVIS)) ||
00519                    sscanf(tmps, "%d %d %d %d %d %[^\n]", &ma, &ml, &wind,
00520                                   &wspeed, &cloudbase, changemsg) < 4) {
00521                         ma = 30;
00522                         ml = 2;
00523                         wind = 0;
00524                         wspeed = 0;
00525                         cloudbase = 200;
00526                 }
00527                 map->winddir = wind;
00528                 map->windspeed = wspeed;
00529                 map->mapvis = BOUNDED(0, ma, 60);
00530                 map->maxvis = BOUNDED(24, ma * 3, 60);
00531                 map->maplight = BOUNDED(0, ml, 2);
00532                 map->cloudbase = cloudbase;
00533                 if(ml != oldl || ma != oldv)
00534                         for(i = 0; i < map->first_free; i++) {
00535                                 if((j = map->mechsOnMap[i]) < 0)
00536                                         continue;
00537                                 if(!(mech = getMech(j)))
00538                                         continue;
00539                                 if(ml != oldl)
00540                                         sensor_light_availability_check(mech);
00541                                 if(strlen(changemsg) > 5)
00542                                         mech_notify(mech, MECHALL, changemsg);
00543                         }
00544         }
00545         update_LOSinfo(obj, map);
00546         /* Fire/Smoke are event-driven -> nothing related to them done here */
00547 }

void map_view ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 92 of file map.c.

References A_TACSIZE, args, BOUNDED(), MakeMapText(), MAP_DISPLAY_HEIGHT, MAP_DISPLAY_WIDTH, MAP::map_height, MAP::map_width, mech_parseattributes(), notify, silly_atr_get(), x, and y.

00093 {
00094         MAP *mech_map = (MAP *) data;
00095         int argc, i;
00096         int x, y;
00097         char *args[2];
00098         int displayHeight = MAP_DISPLAY_HEIGHT, displayWidth = MAP_DISPLAY_WIDTH;
00099         char *str;
00100         char **maptext;
00101 
00102         /* Check if its a valid map */
00103         if(!mech_map)
00104                 return;
00105 
00106         /* Make sure the proper number of arguments '<X> <Y>' were passed */
00107         argc = mech_parseattributes(buffer, args, 2);
00108         switch (argc) {
00109         case 2:
00110                 x = BOUNDED(0, atoi(args[0]), mech_map->map_width - 1);
00111                 y = BOUNDED(0, atoi(args[1]), mech_map->map_height - 1);
00112                 break;
00113         default:
00114                 notify(player, "Invalid number of parameters!");
00115                 return;
00116         }
00117 
00118         /* Get the Tacsize attribute from
00119          * the player, if doesn't exist set the height and width to
00120          * default params. If it does exist, check the values and
00121          * make sure they are legit. */
00122         str = silly_atr_get(player, A_TACSIZE);
00123         if(!*str) {
00124                 displayHeight = MAP_DISPLAY_HEIGHT;
00125                 displayWidth = MAP_DISPLAY_WIDTH;
00126         } else if(sscanf(str, "%d %d", &displayHeight, &displayWidth) != 2 ||
00127                           displayHeight > 24 || displayHeight < 5 || displayWidth < 5 ||
00128                           displayWidth > 40) {
00129 
00130                 notify(player,
00131                            "Illegal Tacsize attribute. Must be in format "
00132                            "'Height Width' . Height : 5-24 Width : 5-40");
00133                 displayHeight = MAP_DISPLAY_HEIGHT;
00134                 displayWidth = MAP_DISPLAY_WIDTH;
00135 
00136         }
00137 
00138         /* Everything worked but lets check the map size */
00139         displayHeight = (displayHeight <= mech_map->map_height)
00140                 ? displayHeight : mech_map->map_height;
00141         displayWidth = (displayWidth <= mech_map->map_width)
00142                 ? displayWidth : mech_map->map_width;
00143 
00144         /* Get the map data */
00145         maptext = MakeMapText(player, NULL, mech_map, x, y, displayWidth,
00146                                                   displayHeight, 3, 0);
00147 
00148         /* Display the map to the player */
00149         for(i = 0; maptext[i]; i++)
00150                 notify(player, maptext[i]);
00151 }

void newfreemap ( dbref  key,
void **  data,
int  selector 
)

Definition at line 567 of file map.c.

References del_mapobjs(), initialize_map_empty(), NUM_MAPOBJTYPES, SPECIAL_ALLOC, and SPECIAL_FREE.

00568 {
00569         MAP *new = *data;
00570         int i;
00571 
00572         switch (selector) {
00573         case SPECIAL_ALLOC:
00574                 initialize_map_empty(new, key);
00575                 /* allocate default map space */
00576                 for(i = 0; i < NUM_MAPOBJTYPES; i++)
00577                         new->mapobj[i] = NULL;
00578                 sprintf(new->mapname, "%s", "Default Map");
00579                 break;
00580         case SPECIAL_FREE:
00581                 del_mapobjs(new);
00582                 if(new->map) {
00583                         for(i = new->map_height - 1; i >= 0; i--)
00584                                 if(new->map[i])
00585                                         free((char *) (new->map[i]));
00586                         free((char *) (new->map));
00587                 }
00588                 break;
00589         }
00590 }

void UpdateMechsTerrain ( MAP map,
int  x,
int  y,
int  t 
)

Definition at line 717 of file map.c.

References FindObjectsData(), MAP::first_free, MarkForLOSUpdate(), MAP::mechsOnMap, MechTerrain, MechX, and MechY.

00718 {
00719         MECH *mech;
00720         int i;
00721 
00722         for(i = 0; i < map->first_free; i++) {
00723                 if(!(mech = FindObjectsData(map->mechsOnMap[i])))
00724                         continue;
00725                 if(MechX(mech) != x || MechY(mech) != y)
00726                         continue;
00727                 if(MechTerrain(mech) != t) {
00728                         MechTerrain(mech) = t;
00729                         MarkForLOSUpdate(mech);
00730                 }
00731         }
00732 }

int water_distance ( MAP map,
int  x,
int  y,
int  dir,
int  max 
)

Definition at line 195 of file map.c.

References BOUNDED(), BRIDGE, dirs, GetTerrain, ICE, MAP::map_height, MAP::map_width, ROAD, and WATER.

Referenced by eligible_bridge_hex().

00196 {
00197         int i;
00198         int x2, y2;
00199 
00200         for(i = 1; i < max; i++) {
00201                 x = x + dirs[dir][0];
00202                 y = y + dirs[dir][1];
00203                 if(!x && dirs[dir][0])
00204                         y--;
00205                 x2 = BOUNDED(0, x, map->map_width - 1);
00206                 y2 = BOUNDED(0, y, map->map_height - 1);
00207                 if(x != x2 || y != y2)
00208                         return max;
00209                 if(GetTerrain(map, x, y) == WATER || GetTerrain(map, x, y) == ICE)
00210                         return i;
00211                 if(GetTerrain(map, x, y) != BRIDGE && GetTerrain(map, x, y) != ROAD)
00212                         return max;
00213         }
00214         return max;
00215 }


Generated on Mon May 28 04:25:40 2007 for BattletechMUX by  doxygen 1.4.7