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.1 by elmex, Sun Aug 13 17:16:00 2006 UTC vs.
Revision 1.7 by elmex, Mon Aug 21 02:58:22 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; 3 * "$Id: map.C,v 1.7 2006/08/21 02:58:22 elmex 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
268 retval |= P_NEW_MAP; 268 retval |= P_NEW_MAP;
269 if (newmap) *newmap = mp; 269 if (newmap) *newmap = mp;
270 if (nx) *nx = newx; 270 if (nx) *nx = newx;
271 if (ny) *ny = newy; 271 if (ny) *ny = newy;
272 retval |= mp->spaces[newx + mp->width * newy].flags; 272 retval |= mp->spaces[newx + mp->width * newy].flags;
273
274 if (retval & P_SAFE)
275 retval |= P_NO_MAGIC | P_NO_CLERIC; // P_SAFE does imply these
276
273 return retval; 277 return retval;
274} 278}
275 279
276 280
277/* 281/*
945 m->winddir = atoi(value); 949 m->winddir = atoi(value);
946 } else if (!strcmp(key, "sky")) { 950 } else if (!strcmp(key, "sky")) {
947 m->sky = atoi(value); 951 m->sky = atoi(value);
948 } else if (!strcmp(key, "nosmooth")) { 952 } else if (!strcmp(key, "nosmooth")) {
949 m->nosmooth = atoi(value); 953 m->nosmooth = atoi(value);
954 } else if (!strcmp(key, "safe_map")) {
955 m->safe_map = atoi(value);
950 } 956 }
951 else if (!strncmp(key,"tile_path_", 10)) { 957 else if (!strncmp(key,"tile_path_", 10)) {
952 int tile=atoi(key+10); 958 int tile=atoi(key+10);
953 959
954 if (tile<1 || tile>4) { 960 if (tile<1 || tile>4) {
1214 * (this should have been updated when first loaded) 1220 * (this should have been updated when first loaded)
1215 */ 1221 */
1216 1222
1217int new_save_map(mapstruct *m, int flag) { 1223int new_save_map(mapstruct *m, int flag) {
1218 FILE *fp, *fp2; 1224 FILE *fp, *fp2;
1219 char filename[MAX_BUF],buf[MAX_BUF], shop[MAX_BUF]; 1225 char filename[MAX_BUF],buf[MAX_BUF], buf_s[MAX_BUF],
1226 shop[MAX_BUF], filename_s[MAX_BUF];
1220 int i; 1227 int i;
1221 1228
1222 if (flag && !*m->path) { 1229 if (flag && !*m->path) {
1223 LOG(llevError,"Tried to save map without path.\n"); 1230 LOG(llevError,"Tried to save map without path.\n");
1224 return -1; 1231 return -1;
1245 } else { 1252 } else {
1246 if (!m->tmpname) 1253 if (!m->tmpname)
1247 m->tmpname = tempnam_local(settings.tmpdir,NULL); 1254 m->tmpname = tempnam_local(settings.tmpdir,NULL);
1248 strcpy(filename, m->tmpname); 1255 strcpy(filename, m->tmpname);
1249 } 1256 }
1250 LOG(llevDebug,"Saving map %s\n",m->path); 1257 LOG(llevDebug,"Saving map %s to %s\n", m->path, filename);
1251 m->in_memory = MAP_SAVING; 1258 m->in_memory = MAP_SAVING;
1252 1259
1253 unlink (filename); // do not overwrite backups if done via hardlinks 1260 sprintf (filename_s, "%s~", filename);
1254 1261
1255 /* Compress if it isn't a temporary save. Do compress if unique */ 1262 /* Compress if it isn't a temporary save. Do compress if unique */
1256 if (m->compressed && (m->unique || m->templatemap || flag)) { 1263 if (m->compressed && (m->unique || m->templatemap || flag)) {
1257 char buf[MAX_BUF]; 1264 char buf[MAX_BUF];
1258 strcpy(buf, uncomp[m->compressed][2]); 1265 strcpy(buf, uncomp[m->compressed][2]);
1259 strcat(buf, " > "); 1266 strcat(buf, " > ");
1260 strcat(buf, filename); 1267 strcat(buf, filename_s);
1261 fp = popen(buf, "w"); 1268 fp = popen(buf, "w");
1262 } else 1269 } else
1263 fp = fopen(filename, "w"); 1270 fp = fopen(filename_s, "w");
1264 1271
1265 if(fp == NULL) { 1272 if(fp == NULL) {
1266 LOG(llevError, "Cannot write %s: %s\n", filename, strerror_local(errno)); 1273 LOG(llevError, "Cannot write %s: %s\n", filename_s, strerror_local(errno));
1267 return -1; 1274 return -1;
1268 } 1275 }
1269 1276
1270 /* legacy */ 1277 /* legacy */
1271 fprintf(fp,"arch map\n"); 1278 fprintf(fp,"arch map\n");
1306 if (m->humid) fprintf(fp, "humid %d\n", m->humid); 1313 if (m->humid) fprintf(fp, "humid %d\n", m->humid);
1307 if (m->windspeed) fprintf(fp, "windspeed %d\n", m->windspeed); 1314 if (m->windspeed) fprintf(fp, "windspeed %d\n", m->windspeed);
1308 if (m->winddir) fprintf(fp, "winddir %d\n", m->winddir); 1315 if (m->winddir) fprintf(fp, "winddir %d\n", m->winddir);
1309 if (m->sky) fprintf(fp, "sky %d\n", m->sky); 1316 if (m->sky) fprintf(fp, "sky %d\n", m->sky);
1310 if (m->nosmooth) fprintf(fp, "nosmooth %d\n", m->nosmooth); 1317 if (m->nosmooth) fprintf(fp, "nosmooth %d\n", m->nosmooth);
1318 if (m->safe_map) fprintf(fp, "safe_map %d\n", m->safe_map);
1311 1319
1312 /* Save any tiling information, except on overlays */ 1320 /* Save any tiling information, except on overlays */
1313 if (flag != 2) 1321 if (flag != 2)
1314 for (i=0; i<4; i++) 1322 for (i=0; i<4; i++)
1315 if (m->tile_path[i]) 1323 if (m->tile_path[i])
1320 /* In the game save unique items in the different file, but 1328 /* In the game save unique items in the different file, but
1321 * in the editor save them to the normal map file. 1329 * in the editor save them to the normal map file.
1322 * If unique map, save files in the proper destination (set by 1330 * If unique map, save files in the proper destination (set by
1323 * player) 1331 * player)
1324 */ 1332 */
1325 fp2 = fp; /* save unique items into fp2 */
1326 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) { 1333 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) {
1327 sprintf (buf,"%s.v00",create_items_path (m->path)); 1334 sprintf (buf,"%s.v00",create_items_path (m->path));
1335 sprintf (buf_s, "%s~", buf);
1328 if ((fp2 = fopen (buf, "w")) == NULL) { 1336 if ((fp2 = fopen (buf_s, "w")) == NULL) {
1329 LOG(llevError, "Can't open unique items file %s\n", buf); 1337 LOG(llevError, "Can't open unique items file %s\n", buf_s);
1330 } 1338 }
1331 if (flag == 2) 1339 if (flag == 2)
1332 save_objects(m, fp, fp2, 2); 1340 save_objects(m, fp, fp2, 2);
1333 else 1341 else
1334 save_objects (m, fp, fp2, 0); 1342 save_objects (m, fp, fp2, 0);
1335 if (fp2 != NULL) { 1343 if (fp2 != NULL) {
1336 if (ftell (fp2) == 0) { 1344 if (ftell (fp2) == 0) {
1337 fclose (fp2); 1345 fclose (fp2);
1346 rename (buf_s, buf);
1338 unlink (buf); 1347 unlink (buf);
1339 } else { 1348 } else {
1340 fclose (fp2); 1349 fclose (fp2);
1350 rename (buf_s, buf);
1341 chmod (buf, SAVE_MODE); 1351 chmod (buf, SAVE_MODE);
1342 } 1352 }
1343 } 1353 }
1344 } else { /* save same file when not playing, like in editor */ 1354 } else { /* save same file when not playing, like in editor */
1345 save_objects(m, fp, fp, 0); 1355 save_objects(m, fp, fp, 0);
1347 1357
1348 if (m->compressed && (m->unique || m->templatemap || flag)) 1358 if (m->compressed && (m->unique || m->templatemap || flag))
1349 pclose(fp); 1359 pclose(fp);
1350 else 1360 else
1351 fclose(fp); 1361 fclose(fp);
1362
1363 rename (filename_s, filename);
1352 1364
1353 chmod (filename, SAVE_MODE); 1365 chmod (filename, SAVE_MODE);
1354 return 0; 1366 return 0;
1355} 1367}
1356 1368
1819 flags |= P_IS_ALIVE; 1831 flags |= P_IS_ALIVE;
1820 if (QUERY_FLAG(tmp,FLAG_NO_MAGIC)) 1832 if (QUERY_FLAG(tmp,FLAG_NO_MAGIC))
1821 flags |= P_NO_MAGIC; 1833 flags |= P_NO_MAGIC;
1822 if (QUERY_FLAG(tmp,FLAG_DAMNED)) 1834 if (QUERY_FLAG(tmp,FLAG_DAMNED))
1823 flags |= P_NO_CLERIC; 1835 flags |= P_NO_CLERIC;
1836 if (tmp->type == SAFE_GROUND)
1837 flags |= P_SAFE | P_NO_CLERIC | P_NO_MAGIC;
1824 1838
1825 if (QUERY_FLAG(tmp,FLAG_BLOCKSVIEW)) 1839 if (QUERY_FLAG(tmp,FLAG_BLOCKSVIEW))
1826 flags |= P_BLOCKSVIEW; 1840 flags |= P_BLOCKSVIEW;
1827 } /* for stack of objects */ 1841 } /* for stack of objects */
1828 1842

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines