ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.15 by root, Wed Aug 30 08:28:32 2006 UTC vs.
Revision 1.20 by root, Sun Sep 3 00:18:40 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.15 2006/08/30 08:28:32 root Exp $"; 3 * "$Id: map.C,v 1.20 2006/09/03 00:18:40 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
173 * Can not use strcat because we need to cycle through 173 * Can not use strcat because we need to cycle through
174 * all the names. 174 * all the names.
175 */ 175 */
176 endbuf = buf + strlen(buf); 176 endbuf = buf + strlen(buf);
177 177
178 for (i = 0; i < NROF_COMPRESS_METHODS; i++) {
179 if (uncomp[i][0])
180 strcpy(endbuf, uncomp[i][0]);
181 else
182 *endbuf = '\0';
183 if (!stat (buf, &statbuf)) 178 if (stat (buf, &statbuf))
184 break;
185 }
186 if (i == NROF_COMPRESS_METHODS)
187 return (-1); 179 return -1;
188 if (!S_ISREG (statbuf.st_mode)) 180 if (!S_ISREG (statbuf.st_mode))
189 return (-1); 181 return (-1);
190 182
191 if (((statbuf.st_mode & S_IRGRP) && getegid() == statbuf.st_gid) || 183 if (((statbuf.st_mode & S_IRGRP) && getegid() == statbuf.st_gid) ||
192 ((statbuf.st_mode & S_IRUSR) && geteuid() == statbuf.st_uid) || 184 ((statbuf.st_mode & S_IRUSR) && geteuid() == statbuf.st_uid) ||
490 op->x += tmp->x; 482 op->x += tmp->x;
491 op->y += tmp->y; 483 op->y += tmp->y;
492 op->head = tmp; 484 op->head = tmp;
493 op->map = m; 485 op->map = m;
494 last->more = op; 486 last->more = op;
495 if (tmp->name != op->name) {
496 if (op->name) free_string(op->name);
497 op->name = add_string(tmp->name); 487 op->name = tmp->name;
498 }
499 if (tmp->title != op->title) {
500 if (op->title) free_string(op->title);
501 op->title = add_string(tmp->title); 488 op->title = tmp->title;
502 }
503 /* we could link all the parts onto tmp, and then just 489 /* we could link all the parts onto tmp, and then just
504 * call insert_ob_in_map once, but the effect is the same, 490 * call insert_ob_in_map once, but the effect is the same,
505 * as insert_ob_in_map will call itself with each part, and 491 * as insert_ob_in_map will call itself with each part, and
506 * the coding is simpler to just to it here with each part. 492 * the coding is simpler to just to it here with each part.
507 */ 493 */
536 /* if the archetype for the object is null, means that we 522 /* if the archetype for the object is null, means that we
537 * got an invalid object. Don't do anything with it - the game 523 * got an invalid object. Don't do anything with it - the game
538 * or editor will not be able to do anything with it either. 524 * or editor will not be able to do anything with it either.
539 */ 525 */
540 if (op->arch==NULL) { 526 if (op->arch==NULL) {
541 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?op->name:"(null)"); 527 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?(const char *)op->name:"(null)");
542 continue; 528 continue;
543 } 529 }
544 530
545 531
546 switch(i) { 532 switch(i) {
626 * Modified to no longer take a path option which was not being 612 * Modified to no longer take a path option which was not being
627 * used anyways. MSW 2001-07-01 613 * used anyways. MSW 2001-07-01
628 */ 614 */
629 615
630mapstruct *get_linked_map(void) { 616mapstruct *get_linked_map(void) {
631 mapstruct *map=(mapstruct *) calloc(1,sizeof(mapstruct)); 617 mapstruct *map = new mapstruct;
632 mapstruct *mp; 618 mapstruct *mp;
633
634 if(map==NULL)
635 fatal(OUT_OF_MEMORY);
636 619
637 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next); 620 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next);
638 if(mp==NULL) 621 if(mp==NULL)
639 first_map=map; 622 first_map=map;
640 else 623 else
896 * what really should be used. 879 * what really should be used.
897 */ 880 */
898 else if (!strcmp(key,"oid")) { 881 else if (!strcmp(key,"oid")) {
899 fp.get (m, atoi(value)); 882 fp.get (m, atoi(value));
900 } else if (!strcmp(key, "attach")) { 883 } else if (!strcmp(key, "attach")) {
901 m->attach = add_string (value); 884 m->attach = value;
902 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { 885 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) {
903 m->enter_x = atoi(value); 886 m->enter_x = atoi(value);
904 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { 887 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) {
905 m->enter_y = atoi(value); 888 m->enter_y = atoi(value);
906 } else if (!strcmp(key,"x") || !strcmp(key, "width")) { 889 } else if (!strcmp(key,"x") || !strcmp(key, "width")) {
1233 } 1216 }
1234 else 1217 else
1235 { 1218 {
1236 if (!m->tmpname) 1219 if (!m->tmpname)
1237 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1220 m->tmpname = tempnam_local (settings.tmpdir, NULL);
1221
1238 strcpy (filename, m->tmpname); 1222 strcpy (filename, m->tmpname);
1239 } 1223 }
1240 1224
1241 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1225 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1242 m->in_memory = MAP_SAVING; 1226 m->in_memory = MAP_SAVING;
1243 1227
1244 object_freezer fp (filename); 1228 object_freezer freezer;
1245 1229
1246 /* legacy */ 1230 /* legacy */
1247 fprintf (fp, "arch map\n"); 1231 fprintf (freezer, "arch map\n");
1248 if (m->name) 1232 if (m->name)
1249 fprintf (fp, "name %s\n", m->name); 1233 fprintf (freezer, "name %s\n", m->name);
1250 if (!flag) 1234 if (!flag)
1251 fprintf (fp, "swap_time %d\n", m->swap_time); 1235 fprintf (freezer, "swap_time %d\n", m->swap_time);
1252 if (m->reset_timeout) 1236 if (m->reset_timeout)
1253 fprintf (fp, "reset_timeout %d\n", m->reset_timeout); 1237 fprintf (freezer, "reset_timeout %d\n", m->reset_timeout);
1254 if (m->fixed_resettime) 1238 if (m->fixed_resettime)
1255 fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); 1239 fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime);
1256 /* we unfortunately have no idea if this is a value the creator set 1240 /* we unfortunately have no idea if this is a value the creator set
1257 * or a difficulty value we generated when the map was first loaded 1241 * or a difficulty value we generated when the map was first loaded
1258 */ 1242 */
1259 if (m->difficulty) 1243 if (m->difficulty)
1260 fprintf (fp, "difficulty %d\n", m->difficulty); 1244 fprintf (freezer, "difficulty %d\n", m->difficulty);
1261 if (m->region) 1245 if (m->region)
1262 fprintf (fp, "region %s\n", m->region->name); 1246 fprintf (freezer, "region %s\n", m->region->name);
1263 if (m->shopitems) 1247 if (m->shopitems)
1264 { 1248 {
1265 print_shop_string (m, shop); 1249 print_shop_string (m, shop);
1266 fprintf (fp, "shopitems %s\n", shop); 1250 fprintf (freezer, "shopitems %s\n", shop);
1267 } 1251 }
1268 if (m->shopgreed) 1252 if (m->shopgreed)
1269 fprintf (fp, "shopgreed %f\n", m->shopgreed); 1253 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1270#ifndef WIN32 1254#ifndef WIN32
1271 if (m->shopmin) 1255 if (m->shopmin)
1272 fprintf (fp, "shopmin %llu\n", m->shopmin); 1256 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1273 if (m->shopmax) 1257 if (m->shopmax)
1274 fprintf (fp, "shopmax %llu\n", m->shopmax); 1258 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1275#else 1259#else
1276 if (m->shopmin) 1260 if (m->shopmin)
1277 fprintf (fp, "shopmin %I64u\n", m->shopmin); 1261 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1278 if (m->shopmax) 1262 if (m->shopmax)
1279 fprintf (fp, "shopmax %I64u\n", m->shopmax); 1263 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1280#endif 1264#endif
1281 if (m->shoprace) 1265 if (m->shoprace)
1282 fprintf (fp, "shoprace %s\n", m->shoprace); 1266 fprintf (freezer, "shoprace %s\n", m->shoprace);
1283 if (m->darkness) 1267 if (m->darkness)
1284 fprintf (fp, "darkness %d\n", m->darkness); 1268 fprintf (freezer, "darkness %d\n", m->darkness);
1285 if (m->width) 1269 if (m->width)
1286 fprintf (fp, "width %d\n", m->width); 1270 fprintf (freezer, "width %d\n", m->width);
1287 if (m->height) 1271 if (m->height)
1288 fprintf (fp, "height %d\n", m->height); 1272 fprintf (freezer, "height %d\n", m->height);
1289 if (m->enter_x) 1273 if (m->enter_x)
1290 fprintf (fp, "enter_x %d\n", m->enter_x); 1274 fprintf (freezer, "enter_x %d\n", m->enter_x);
1291 if (m->enter_y) 1275 if (m->enter_y)
1292 fprintf (fp, "enter_y %d\n", m->enter_y); 1276 fprintf (freezer, "enter_y %d\n", m->enter_y);
1293 if (m->msg) 1277 if (m->msg)
1294 fprintf (fp, "msg\n%sendmsg\n", m->msg); 1278 fprintf (freezer, "msg\n%sendmsg\n", m->msg);
1295 if (m->maplore) 1279 if (m->maplore)
1296 fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); 1280 fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore);
1297 if (m->unique) 1281 if (m->unique)
1298 fprintf (fp, "unique %d\n", m->unique); 1282 fprintf (freezer, "unique %d\n", m->unique);
1299 if (m->templatemap) 1283 if (m->templatemap)
1300 fprintf (fp, "template %d\n", m->templatemap); 1284 fprintf (freezer, "template %d\n", m->templatemap);
1301 if (m->outdoor) 1285 if (m->outdoor)
1302 fprintf (fp, "outdoor %d\n", m->outdoor); 1286 fprintf (freezer, "outdoor %d\n", m->outdoor);
1303 if (m->temp) 1287 if (m->temp)
1304 fprintf (fp, "temp %d\n", m->temp); 1288 fprintf (freezer, "temp %d\n", m->temp);
1305 if (m->pressure) 1289 if (m->pressure)
1306 fprintf (fp, "pressure %d\n", m->pressure); 1290 fprintf (freezer, "pressure %d\n", m->pressure);
1307 if (m->humid) 1291 if (m->humid)
1308 fprintf (fp, "humid %d\n", m->humid); 1292 fprintf (freezer, "humid %d\n", m->humid);
1309 if (m->windspeed) 1293 if (m->windspeed)
1310 fprintf (fp, "windspeed %d\n", m->windspeed); 1294 fprintf (freezer, "windspeed %d\n", m->windspeed);
1311 if (m->winddir) 1295 if (m->winddir)
1312 fprintf (fp, "winddir %d\n", m->winddir); 1296 fprintf (freezer, "winddir %d\n", m->winddir);
1313 if (m->sky) 1297 if (m->sky)
1314 fprintf (fp, "sky %d\n", m->sky); 1298 fprintf (freezer, "sky %d\n", m->sky);
1315 if (m->nosmooth) 1299 if (m->nosmooth)
1316 fprintf (fp, "nosmooth %d\n", m->nosmooth); 1300 fprintf (freezer, "nosmooth %d\n", m->nosmooth);
1317 1301
1318 /* Save any tiling information, except on overlays */ 1302 /* Save any tiling information, except on overlays */
1319 if (flag != 2) 1303 if (flag != 2)
1320 for (i = 0; i < 4; i++) 1304 for (i = 0; i < 4; i++)
1321 if (m->tile_path[i]) 1305 if (m->tile_path[i])
1322 fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); 1306 fprintf (freezer, "tile_path_%d %s\n", i + 1, m->tile_path[i]);
1323 1307
1324 fp.put (m); 1308 freezer.put (m);
1325 fprintf (fp, "end\n"); 1309 fprintf (freezer, "end\n");
1326 1310
1327 /* In the game save unique items in the different file, but 1311 /* In the game save unique items in the different file, but
1328 * in the editor save them to the normal map file. 1312 * in the editor save them to the normal map file.
1329 * If unique map, save files in the proper destination (set by 1313 * If unique map, save files in the proper destination (set by
1330 * player) 1314 * player)
1331 */ 1315 */
1332 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) 1316 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap)
1333 { 1317 {
1318 object_freezer unique;
1319
1320 if (flag == 2)
1321 save_objects (m, freezer, unique, 2);
1322 else
1323 save_objects (m, freezer, unique, 0);
1324
1334 sprintf (buf, "%s.v00", create_items_path (m->path)); 1325 sprintf (buf, "%s.v00", create_items_path (m->path));
1335 1326
1336 object_freezer fp2 (buf); 1327 unique.save (buf);
1337
1338 if (flag == 2)
1339 save_objects (m, fp, fp2, 2);
1340 else
1341 save_objects (m, fp, fp2, 0);
1342 } 1328 }
1343 else 1329 else
1344 { /* save same file when not playing, like in editor */ 1330 { /* save same file when not playing, like in editor */
1345 save_objects (m, fp, fp, 0); 1331 save_objects (m, freezer, freezer, 0);
1346 } 1332 }
1333
1334 freezer.save (filename);
1347 1335
1348 return 0; 1336 return 0;
1349} 1337}
1350 1338
1351 1339
1396 clean_object(op); 1384 clean_object(op);
1397 remove_ob(op); 1385 remove_ob(op);
1398 free_object(op); 1386 free_object(op);
1399 } 1387 }
1400 } 1388 }
1401#ifdef MANY_CORES
1402 /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1403 * an item on that map was not saved - look for that condition and die as appropriate -
1404 * this leaves more of the map data intact for better debugging.
1405 */
1406 for (op=objects; op!=NULL; op=op->next) {
1407 if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1408 LOG(llevDebug,"free_all_objects: object %s still on map after it should have been freed\n", op->name);
1409 abort();
1410 }
1411 }
1412#endif
1413} 1389}
1414 1390
1415/* 1391/*
1416 * Frees everything allocated by the given mapstructure. 1392 * Frees everything allocated by the given mapstructure.
1417 * don't free tmpname - our caller is left to do that 1393 * don't free tmpname - our caller is left to do that
1497 m->path); 1473 m->path);
1498 } 1474 }
1499 else 1475 else
1500 last->next = m->next; 1476 last->next = m->next;
1501 1477
1502 free (m); 1478 delete m;
1503} 1479}
1504 1480
1505 1481
1506 1482
1507/* 1483/*

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines