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

Comparing deliantra/server/common/loader.C (file contents):
Revision 1.144 by root, Tue Nov 10 04:38:45 2009 UTC vs.
Revision 1.148 by root, Wed Nov 11 23:27:56 2009 UTC

330 330
331 if (!name_pl) 331 if (!name_pl)
332 name_pl = name; 332 name_pl = name;
333 333
334 /* objects now have a materialname. try to patch it in */ 334 /* objects now have a materialname. try to patch it in */
335 if (material == &material_null && !(is_weapon () && level > 0)) 335 if (material == MATERIAL_NULL && !(is_weapon () && level > 0))
336 select_material (this, map ? map->difficulty : 5); 336 select_material (this, map ? map->difficulty : 5);
337 337
338 /* only do these when program is first run - a bit 338 /* only do these when program is first run - a bit
339 * excessive to do this at every run - most of this is 339 * excessive to do this at every run - most of this is
340 * really just to catch any errors - program will still run, but 340 * really just to catch any errors - program will still run, but
859 case KW_reflect_missile: GET_FLAG (this, FLAG_REFL_MISSILE); break; 859 case KW_reflect_missile: GET_FLAG (this, FLAG_REFL_MISSILE); break;
860 case KW_reflect_spell: GET_FLAG (this, FLAG_REFL_SPELL); break; 860 case KW_reflect_spell: GET_FLAG (this, FLAG_REFL_SPELL); break;
861 case KW_no_magic: GET_FLAG (this, FLAG_NO_MAGIC); break; 861 case KW_no_magic: GET_FLAG (this, FLAG_NO_MAGIC); break;
862 case KW_no_drop: GET_FLAG (this, FLAG_NO_DROP); break; 862 case KW_no_drop: GET_FLAG (this, FLAG_NO_DROP); break;
863 case KW_random_movement: GET_FLAG (this, FLAG_RANDOM_MOVE); break; 863 case KW_random_movement: GET_FLAG (this, FLAG_RANDOM_MOVE); break;
864 case KW_no_fix_player: GET_FLAG (this, FLAG_NO_FIX_PLAYER); break;
865 case KW_is_lightable: GET_FLAG (this, FLAG_IS_LIGHTABLE); break; 864 case KW_is_lightable: GET_FLAG (this, FLAG_IS_LIGHTABLE); break;
866 case KW_tear_down: GET_FLAG (this, FLAG_TEAR_DOWN); break; 865 case KW_tear_down: GET_FLAG (this, FLAG_TEAR_DOWN); break;
867 case KW_can_use_shield: GET_FLAG (this, FLAG_USE_SHIELD); break; 866 case KW_can_use_shield: GET_FLAG (this, FLAG_USE_SHIELD); break;
868 case KW_can_cast_spell: GET_FLAG (this, FLAG_CAST_SPELL); break; 867 case KW_can_cast_spell: GET_FLAG (this, FLAG_CAST_SPELL); break;
869 case KW_can_use_scroll: GET_FLAG (this, FLAG_USE_SCROLL); break; 868 case KW_can_use_scroll: GET_FLAG (this, FLAG_USE_SCROLL); break;
1175 KW_unaggressive, 1174 KW_unaggressive,
1176 KW_reflect_missile, 1175 KW_reflect_missile,
1177 /* 40 */ 1176 /* 40 */
1178 KW_reflect_spell, 1177 KW_reflect_spell,
1179 KW_no_magic, 1178 KW_no_magic,
1180 KW_no_fix_player, 1179 KW_NULL,
1181 KW_is_lightable, 1180 KW_is_lightable,
1182 KW_tear_down, 1181 KW_tear_down,
1183 KW_run_away, 1182 KW_run_away,
1184 KW_NULL, // pass_thru 1183 KW_NULL, // pass_thru
1185 KW_NULL, // an_pass_thru 1184 KW_NULL, // an_pass_thru
1288 *ptr++ = '\n'; 1287 *ptr++ = '\n';
1289 1288
1290 f.alloc (ptr - cur); 1289 f.alloc (ptr - cur);
1291 } 1290 }
1292 1291
1293#define CMP_OUT(v) if (expect_false (op->v != arch->v)) f.put (KW_ ## v, op->v) 1292#define CMP_OUT(v) if (expect_false (op->v != arch->v)) f.put (KW (v), op->v)
1294#define CMP_OUT2(k,v) if (expect_false (op->v != arch->v)) f.put (KW_ ## k, op->v) 1293#define CMP_OUT2(k,v) if (expect_false (op->v != arch->v)) f.put (KW (k), op->v)
1295 1294
1296 CMP_OUT (x); 1295 CMP_OUT (x);
1297 CMP_OUT (y); 1296 CMP_OUT (y);
1298 1297
1299 CMP_OUT (type); 1298 CMP_OUT (type);
1302 1301
1303 CMP_OUT (name); 1302 CMP_OUT (name);
1304 CMP_OUT (name_pl); 1303 CMP_OUT (name_pl);
1305 1304
1306 CMP_OUT (speed); 1305 CMP_OUT (speed);
1307 CMP_OUT (speed_left); 1306
1307 // speed_left is a major time-burner, and has good locality, so
1308 // we use a simple lookup-cache to avoid the very slow printf.
1309 if (op->speed_left != arch->speed_left)
1310 {
1311 static double last_speed_left = 0.;
1312 static char last_speed_left_str [256] = "speed_left 0\n";
1313 static int last_speed_left_len = sizeof ("speed_left 0\n") - 1;
1314
1315 if (last_speed_left != op->speed_left)
1316 {
1317 last_speed_left = op->speed_left;
1318 last_speed_left_len = sizeof ("speed_left ") - 1
1319 + sprintf (last_speed_left_str + sizeof ("speed_left ") - 1, "%.7g\n", last_speed_left);
1320 }
1321
1322 f.add (last_speed_left_str, last_speed_left_len);
1323 }
1308 1324
1309 CMP_OUT (title); 1325 CMP_OUT (title);
1310 CMP_OUT (race); 1326 CMP_OUT (race);
1311 CMP_OUT (slaying); 1327 CMP_OUT (slaying);
1312 CMP_OUT (skill); 1328 CMP_OUT (skill);
1313 1329
1314 CMP_OUT (tag); 1330 CMP_OUT (tag);
1315 CMP_OUT (custom_name); 1331 CMP_OUT (custom_name);
1316 1332
1317 if (object *owner = op->owner) 1333 if (object *owner = op->owner)
1318 f.put (KW_owner, static_cast<const char *>(owner->ref ())); 1334 f.put (KW(owner), static_cast<const char *>(owner->ref ()));
1319 1335
1320 // memory, attacked_by, chosen_skill, spellitem, spell, current_weapon, arch not saved 1336 // memory, attacked_by, chosen_skill, spellitem, spell, current_weapon, arch not saved
1321 1337
1322 CMP_OUT (other_arch); 1338 CMP_OUT (other_arch);
1323 1339
1324 if (op->msg != arch->msg ) f.put (KW_msg , KW_endmsg , op->msg ); 1340 if (op->msg != arch->msg ) f.put (KW(msg) , KW(endmsg) , op->msg );
1325 if (op->lore != arch->lore) f.put (KW_lore, KW_endlore, op->lore); 1341 if (op->lore != arch->lore) f.put (KW(lore), KW(endlore), op->lore);
1326 1342
1327 if (op->face != arch->face ) f.put (KW_face , op->face ? &faces [op->face ] : 0); 1343 if (op->face != arch->face ) f.put (KW(face) , op->face ? &faces [op->face ] : 0);
1328 if (op->sound != arch->sound ) f.put (KW_sound , op->sound ? &faces [op->sound ] : 0); 1344 if (op->sound != arch->sound ) f.put (KW(sound) , op->sound ? &faces [op->sound ] : 0);
1329 if (op->sound_destroy != arch->sound_destroy) f.put (KW_sound_destroy, op->sound_destroy ? &faces [op->sound_destroy] : 0); 1345 if (op->sound_destroy != arch->sound_destroy) f.put (KW(sound_destroy), op->sound_destroy ? &faces [op->sound_destroy] : 0);
1330 1346
1331 if (op->animation_id != arch->animation_id) 1347 if (op->animation_id != arch->animation_id)
1332 if (op->has_anim ()) 1348 if (op->has_anim ())
1333 f.put (KW_animation, op->anim ().name); 1349 f.put (KW(animation), op->anim ().name);
1334 else 1350 else
1335 { 1351 {
1336 f.put (KW_animation, (const char *)0); 1352 f.put (KW(animation));
1337 op->flag [FLAG_ANIMATE] = false; // TODO: why force to false here? 1353 op->flag [FLAG_ANIMATE] = false; // TODO: why force to false here?
1338 } 1354 }
1339 1355
1340 CMP_OUT2 (str, stats.Str); 1356 CMP_OUT2 (str, stats.Str);
1341 CMP_OUT2 (dex, stats.Dex); 1357 CMP_OUT2 (dex, stats.Dex);
1377 CMP_OUT (path_repelled); 1393 CMP_OUT (path_repelled);
1378 CMP_OUT (path_denied); 1394 CMP_OUT (path_denied);
1379 1395
1380 CMP_OUT2 (material, materials);//TODO: nuke 1396 CMP_OUT2 (material, materials);//TODO: nuke
1381 if (op->material != arch->material) 1397 if (op->material != arch->material)
1382 f.put (KW_materialname, op->material->name); 1398 f.put (KW(materialname), op->material->name);
1383 1399
1384 CMP_OUT (value); 1400 CMP_OUT (value);
1385 CMP_OUT (carrying); 1401 CMP_OUT (carrying);
1386 CMP_OUT (weight); 1402 CMP_OUT (weight);
1387 CMP_OUT (invisible); 1403 CMP_OUT (invisible);
1393 CMP_OUT (last_eat); 1409 CMP_OUT (last_eat);
1394 CMP_OUT (glow_radius); 1410 CMP_OUT (glow_radius);
1395 1411
1396 if (op->flag [FLAG_IS_LINKED]) 1412 if (op->flag [FLAG_IS_LINKED])
1397 if (auto (ol, op->find_link ())) 1413 if (auto (ol, op->find_link ()))
1398 f.put (KW_connected, ol->id); 1414 f.put (KW(connected), ol->id);
1399 1415
1400 CMP_OUT (randomitems); 1416 CMP_OUT (randomitems);
1401 CMP_OUT2 (container, weight_limit); 1417 CMP_OUT2 (container, weight_limit);
1402 1418
1403 CMP_OUT (run_away); 1419 CMP_OUT (run_away);
1423 CMP_OUT (move_slow_penalty); 1439 CMP_OUT (move_slow_penalty);
1424 1440
1425 object::flags_t diff = (op->flag ^ arch->flag) & flagmask; 1441 object::flags_t diff = (op->flag ^ arch->flag) & flagmask;
1426 1442
1427 if (diff [FLAG_OBJ_ORIGINAL]) 1443 if (diff [FLAG_OBJ_ORIGINAL])
1428 f.put (flag_names [FLAG_OBJ_ORIGINAL], op->flag [FLAG_OBJ_ORIGINAL] ? "1" : "0"); 1444 f.put (flag_names [FLAG_OBJ_ORIGINAL], op->flag [FLAG_OBJ_ORIGINAL] ? CS(1) : CS(0));
1429 1445
1430 diff.reset (FLAG_OBJ_ORIGINAL); 1446 diff.reset (FLAG_OBJ_ORIGINAL);
1431 1447
1432 // quickly test whether any other flags differ 1448 // quickly test whether any other flags differ
1433 if (expect_true (diff.any ())) 1449 if (expect_true (diff.any ()))
1434 for (int i = 0; i < NUM_FLAGS; i++) 1450 for (int i = 0; i < NUM_FLAGS; i++)
1435 if (expect_false (diff [i])) 1451 if (expect_false (diff [i]))
1436 f.put (flag_names [i], op->flag [i] ? "1" : "0"); 1452 f.put (flag_names [i], op->flag [i] ? CS(1) : CS(0));
1437 1453
1438 // save body locations. gcc's memcmp does an abysmal job when used 1454 // save body locations. gcc's memcmp does an abysmal job when used
1439 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 1455 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
1440 if (expect_false (op->slot[i].info != arch->slot[i].info)) 1456 if (expect_false (op->slot[i].info != arch->slot[i].info))
1441 f.put (body_locations[i].save_name, op->slot[i].info); 1457 f.put (body_locations[i].save_name, op->slot[i].info);
1447 * the only place this is not set is when saving the player. 1463 * the only place this is not set is when saving the player.
1448 */ 1464 */
1449bool 1465bool
1450object::write (object_freezer &f) 1466object::write (object_freezer &f)
1451{ 1467{
1452 if (is_arch ()) 1468 if (expect_false (is_arch ()))
1453 { 1469 {
1454 f.put (KW_object, arch->archname); 1470 f.put (KW(object), arch->archname);
1455 write_diff (f, this, archetype::empty); 1471 write_diff (f, this, archetype::empty);
1456 } 1472 }
1457 else 1473 else
1458 { 1474 {
1459 f.put (KW_arch, arch->archname); 1475 f.put (KW(arch), arch->archname);
1460 write_diff (f, this, arch); 1476 write_diff (f, this, arch);
1461 } 1477 }
1462 1478
1463 for (object *tmp = inv; tmp; tmp = tmp->below) 1479 for (object *tmp = inv; tmp; tmp = tmp->below)
1464 tmp->write (f); 1480 tmp->write (f);
1465 1481
1466 f.put (this); 1482 f.put (this);
1467 f.put (KW_end); 1483 f.put (KW(end));
1468 1484
1469 return true; 1485 return true;
1470} 1486}
1471 1487
1472///////////////////////////////////////////////////////////////////////////// 1488/////////////////////////////////////////////////////////////////////////////

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines