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.143 by root, Mon Nov 9 19:17:58 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 (!(is_weapon () && level > 0)) 335 if (material == MATERIAL_NULL && !(is_weapon () && level > 0))
336 set_materialname (this, map ? map->difficulty : 5, 0); 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
341 * not in the ideal fashion. 341 * not in the ideal fashion.
725 case KW_invisible: f.get (invisible); break; 725 case KW_invisible: f.get (invisible); break;
726 case KW_magic: f.get (magic); break; 726 case KW_magic: f.get (magic); break;
727 case KW_state: f.get (state); break; 727 case KW_state: f.get (state); break;
728 case KW_move_slow_penalty: f.get (move_slow_penalty); break; 728 case KW_move_slow_penalty: f.get (move_slow_penalty); break;
729 case KW_material: f.get (materials); break; //TODO: nuke 729 case KW_material: f.get (materials); break; //TODO: nuke
730 case KW_materialname: f.get (materialname); break; 730
731 case KW_materialname:
732 {
733 shstr sh;
734 f.get (sh);
735 material = name_to_material (sh);
736 }
737 break;
731 738
732 /* These are the new values */ 739 /* These are the new values */
733 case KW_move_block: set_move (move_block, f.get_str ()); break; 740 case KW_move_block: set_move (move_block, f.get_str ()); break;
734 case KW_move_allow: set_move (move_allow, f.get_str ()); break; 741 case KW_move_allow: set_move (move_allow, f.get_str ()); break;
735 case KW_move_type: set_move (move_type, f.get_str ()); break; 742 case KW_move_type: set_move (move_type, f.get_str ()); break;
852 case KW_reflect_missile: GET_FLAG (this, FLAG_REFL_MISSILE); break; 859 case KW_reflect_missile: GET_FLAG (this, FLAG_REFL_MISSILE); break;
853 case KW_reflect_spell: GET_FLAG (this, FLAG_REFL_SPELL); break; 860 case KW_reflect_spell: GET_FLAG (this, FLAG_REFL_SPELL); break;
854 case KW_no_magic: GET_FLAG (this, FLAG_NO_MAGIC); break; 861 case KW_no_magic: GET_FLAG (this, FLAG_NO_MAGIC); break;
855 case KW_no_drop: GET_FLAG (this, FLAG_NO_DROP); break; 862 case KW_no_drop: GET_FLAG (this, FLAG_NO_DROP); break;
856 case KW_random_movement: GET_FLAG (this, FLAG_RANDOM_MOVE); break; 863 case KW_random_movement: GET_FLAG (this, FLAG_RANDOM_MOVE); break;
857 case KW_no_fix_player: GET_FLAG (this, FLAG_NO_FIX_PLAYER); break;
858 case KW_is_lightable: GET_FLAG (this, FLAG_IS_LIGHTABLE); break; 864 case KW_is_lightable: GET_FLAG (this, FLAG_IS_LIGHTABLE); break;
859 case KW_tear_down: GET_FLAG (this, FLAG_TEAR_DOWN); break; 865 case KW_tear_down: GET_FLAG (this, FLAG_TEAR_DOWN); break;
860 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;
861 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;
862 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;
1168 KW_unaggressive, 1174 KW_unaggressive,
1169 KW_reflect_missile, 1175 KW_reflect_missile,
1170 /* 40 */ 1176 /* 40 */
1171 KW_reflect_spell, 1177 KW_reflect_spell,
1172 KW_no_magic, 1178 KW_no_magic,
1173 KW_no_fix_player, 1179 KW_NULL,
1174 KW_is_lightable, 1180 KW_is_lightable,
1175 KW_tear_down, 1181 KW_tear_down,
1176 KW_run_away, 1182 KW_run_away,
1177 KW_NULL, // pass_thru 1183 KW_NULL, // pass_thru
1178 KW_NULL, // an_pass_thru 1184 KW_NULL, // an_pass_thru
1281 *ptr++ = '\n'; 1287 *ptr++ = '\n';
1282 1288
1283 f.alloc (ptr - cur); 1289 f.alloc (ptr - cur);
1284 } 1290 }
1285 1291
1286#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)
1287#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)
1288 1294
1289 CMP_OUT (x); 1295 CMP_OUT (x);
1290 CMP_OUT (y); 1296 CMP_OUT (y);
1291 1297
1292 CMP_OUT (type); 1298 CMP_OUT (type);
1295 1301
1296 CMP_OUT (name); 1302 CMP_OUT (name);
1297 CMP_OUT (name_pl); 1303 CMP_OUT (name_pl);
1298 1304
1299 CMP_OUT (speed); 1305 CMP_OUT (speed);
1300 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 }
1301 1324
1302 CMP_OUT (title); 1325 CMP_OUT (title);
1303 CMP_OUT (race); 1326 CMP_OUT (race);
1304 CMP_OUT (slaying); 1327 CMP_OUT (slaying);
1305 CMP_OUT (skill); 1328 CMP_OUT (skill);
1306 1329
1307 CMP_OUT (tag); 1330 CMP_OUT (tag);
1308 CMP_OUT (custom_name); 1331 CMP_OUT (custom_name);
1309 1332
1310 if (object *owner = op->owner) 1333 if (object *owner = op->owner)
1311 f.put (KW_owner, static_cast<const char *>(owner->ref ())); 1334 f.put (KW(owner), static_cast<const char *>(owner->ref ()));
1312 1335
1313 // 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
1314 1337
1315 CMP_OUT (other_arch); 1338 CMP_OUT (other_arch);
1316 1339
1317 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 );
1318 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);
1319 1342
1320 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);
1321 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);
1322 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);
1323 1346
1324 if (op->animation_id != arch->animation_id) 1347 if (op->animation_id != arch->animation_id)
1325 if (op->has_anim ()) 1348 if (op->has_anim ())
1326 f.put (KW_animation, op->anim ().name); 1349 f.put (KW(animation), op->anim ().name);
1327 else 1350 else
1328 { 1351 {
1329 f.put (KW_animation, (const char *)0); 1352 f.put (KW(animation));
1330 op->flag [FLAG_ANIMATE] = false; // TODO: why force to false here? 1353 op->flag [FLAG_ANIMATE] = false; // TODO: why force to false here?
1331 } 1354 }
1332 1355
1333 CMP_OUT2 (str, stats.Str); 1356 CMP_OUT2 (str, stats.Str);
1334 CMP_OUT2 (dex, stats.Dex); 1357 CMP_OUT2 (dex, stats.Dex);
1359 CMP_OUT (attack_movement); 1382 CMP_OUT (attack_movement);
1360 CMP_OUT (nrof); 1383 CMP_OUT (nrof);
1361 CMP_OUT (level); 1384 CMP_OUT (level);
1362 CMP_OUT (attacktype); 1385 CMP_OUT (attacktype);
1363 1386
1364 // using memcmp here seems to be a loss - us gcc vectorising? 1387 // using memcmp here seems to be a loss - is gcc vectorising?
1365 for (int i = 0; i < NROFATTACKS; i++) 1388 for (int i = 0; i < NROFATTACKS; i++)
1366 if (expect_false (op->resist[i] != arch->resist[i])) 1389 if (expect_false (op->resist[i] != arch->resist[i]))
1367 f.put (resist_save[i], op->resist[i]); 1390 f.put (resist_save[i], op->resist[i]);
1368 1391
1369 CMP_OUT (path_attuned); 1392 CMP_OUT (path_attuned);
1370 CMP_OUT (path_repelled); 1393 CMP_OUT (path_repelled);
1371 CMP_OUT (path_denied); 1394 CMP_OUT (path_denied);
1395
1372 CMP_OUT2 (material, materials);//TODO: nuke 1396 CMP_OUT2 (material, materials);//TODO: nuke
1373 CMP_OUT (materialname); 1397 if (op->material != arch->material)
1398 f.put (KW(materialname), op->material->name);
1399
1374 CMP_OUT (value); 1400 CMP_OUT (value);
1375 CMP_OUT (carrying); 1401 CMP_OUT (carrying);
1376 CMP_OUT (weight); 1402 CMP_OUT (weight);
1377 CMP_OUT (invisible); 1403 CMP_OUT (invisible);
1378 CMP_OUT (state); 1404 CMP_OUT (state);
1383 CMP_OUT (last_eat); 1409 CMP_OUT (last_eat);
1384 CMP_OUT (glow_radius); 1410 CMP_OUT (glow_radius);
1385 1411
1386 if (op->flag [FLAG_IS_LINKED]) 1412 if (op->flag [FLAG_IS_LINKED])
1387 if (auto (ol, op->find_link ())) 1413 if (auto (ol, op->find_link ()))
1388 f.put (KW_connected, ol->id); 1414 f.put (KW(connected), ol->id);
1389 1415
1390 CMP_OUT (randomitems); 1416 CMP_OUT (randomitems);
1391 CMP_OUT2 (container, weight_limit); 1417 CMP_OUT2 (container, weight_limit);
1392 1418
1393 CMP_OUT (run_away); 1419 CMP_OUT (run_away);
1413 CMP_OUT (move_slow_penalty); 1439 CMP_OUT (move_slow_penalty);
1414 1440
1415 object::flags_t diff = (op->flag ^ arch->flag) & flagmask; 1441 object::flags_t diff = (op->flag ^ arch->flag) & flagmask;
1416 1442
1417 if (diff [FLAG_OBJ_ORIGINAL]) 1443 if (diff [FLAG_OBJ_ORIGINAL])
1418 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));
1419 1445
1420 diff.reset (FLAG_OBJ_ORIGINAL); 1446 diff.reset (FLAG_OBJ_ORIGINAL);
1421 1447
1422 // quickly test whether any other flags differ 1448 // quickly test whether any other flags differ
1423 if (expect_true (diff.any ())) 1449 if (expect_true (diff.any ()))
1424 for (int i = 0; i < NUM_FLAGS; i++) 1450 for (int i = 0; i < NUM_FLAGS; i++)
1425 if (expect_false (diff [i])) 1451 if (expect_false (diff [i]))
1426 f.put (flag_names [i], op->flag [i] ? "1" : "0"); 1452 f.put (flag_names [i], op->flag [i] ? CS(1) : CS(0));
1427 1453
1428 // 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
1429 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 1455 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
1430 if (expect_false (op->slot[i].info != arch->slot[i].info)) 1456 if (expect_false (op->slot[i].info != arch->slot[i].info))
1431 f.put (body_locations[i].save_name, op->slot[i].info); 1457 f.put (body_locations[i].save_name, op->slot[i].info);
1437 * 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.
1438 */ 1464 */
1439bool 1465bool
1440object::write (object_freezer &f) 1466object::write (object_freezer &f)
1441{ 1467{
1442 if (is_arch ()) 1468 if (expect_false (is_arch ()))
1443 { 1469 {
1444 f.put (KW_object, arch->archname); 1470 f.put (KW(object), arch->archname);
1445 write_diff (f, this, archetype::empty); 1471 write_diff (f, this, archetype::empty);
1446 } 1472 }
1447 else 1473 else
1448 { 1474 {
1449 f.put (KW_arch, arch->archname); 1475 f.put (KW(arch), arch->archname);
1450 write_diff (f, this, arch); 1476 write_diff (f, this, arch);
1451 } 1477 }
1452 1478
1453 for (object *tmp = inv; tmp; tmp = tmp->below) 1479 for (object *tmp = inv; tmp; tmp = tmp->below)
1454 tmp->write (f); 1480 tmp->write (f);
1455 1481
1456 f.put (this); 1482 f.put (this);
1457 f.put (KW_end); 1483 f.put (KW(end));
1458 1484
1459 return true; 1485 return true;
1460} 1486}
1461 1487
1462///////////////////////////////////////////////////////////////////////////// 1488/////////////////////////////////////////////////////////////////////////////

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines