… | |
… | |
29 | #include <global.h> |
29 | #include <global.h> |
30 | #include <loader.h> |
30 | #include <loader.h> |
31 | #include <sproto.h> |
31 | #include <sproto.h> |
32 | |
32 | |
33 | ///////////////////////////////////////////////////////////////////////////// |
33 | ///////////////////////////////////////////////////////////////////////////// |
34 | |
|
|
35 | /* Maps the MOVE_* values to names */ |
|
|
36 | static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; |
|
|
37 | |
34 | |
38 | /* This table is only necessary to convert objects that existed before the |
35 | /* This table is only necessary to convert objects that existed before the |
39 | * spell object conversion to the new object. It was not practical |
36 | * spell object conversion to the new object. It was not practical |
40 | * to go through every mapping looking for every potion, rod, wand, etc |
37 | * to go through every mapping looking for every potion, rod, wand, etc |
41 | * that had a sp set and update to the new value. So this maps the |
38 | * that had a sp set and update to the new value. So this maps the |
… | |
… | |
253 | "spell_cause_rabies", /* 204 */ |
250 | "spell_cause_rabies", /* 204 */ |
254 | "spell_glyph", /* 205 */ |
251 | "spell_glyph", /* 205 */ |
255 | NULL |
252 | NULL |
256 | }; |
253 | }; |
257 | |
254 | |
258 | extern int arch_init; |
255 | extern bool loading_arch; |
259 | |
256 | |
260 | /* This function checks the object after it has been loaded (when we |
257 | /* This function checks the object after it has been loaded (when we |
261 | * get the 'end' in the input stream). This function can be used to |
258 | * get the 'end' in the input stream). This function can be used to |
262 | * deal with legacy objects where fields may have changed. It can also be used |
259 | * deal with legacy objects where fields may have changed. It can also be used |
263 | * to check for objects to make sure there are no common errors. |
260 | * to check for objects to make sure there are no common errors. |
… | |
… | |
292 | /* only do these when program is first run - a bit |
289 | /* only do these when program is first run - a bit |
293 | * excessive to do this at every run - most of this is |
290 | * excessive to do this at every run - most of this is |
294 | * really just to catch any errors - program will still run, but |
291 | * really just to catch any errors - program will still run, but |
295 | * not in the ideal fashion. |
292 | * not in the ideal fashion. |
296 | */ |
293 | */ |
297 | if ((op->type == WEAPON || op->type == BOW) && arch_init) |
294 | if ((op->type == WEAPON || op->type == BOW) && loading_arch) |
298 | { |
295 | { |
299 | if (!op->skill) |
296 | if (!op->skill) |
300 | LOG (llevError, "Weapon %s lacks a skill.\n", op->debug_desc ()); |
297 | LOG (llevError, "Weapon %s lacks a skill.\n", op->debug_desc ()); |
301 | else if ((!strcmp (op->skill, "one handed weapons") && op->body_info[1] != -1) || |
298 | else if ((!strcmp (op->skill, "one handed weapons") && op->body_info[1] != -1) || |
302 | (!strcmp (op->skill, "two handed weapons") && op->body_info[1] != -2)) |
299 | (!strcmp (op->skill, "two handed weapons") && op->body_info[1] != -2)) |
… | |
… | |
343 | } |
340 | } |
344 | |
341 | |
345 | /* Old spellcasting object - need to load in the appropiate object */ |
342 | /* Old spellcasting object - need to load in the appropiate object */ |
346 | if ((op->type == ROD || op->type == WAND || op->type == SCROLL || op->type == HORN || op->type == FIREWALL || |
343 | if ((op->type == ROD || op->type == WAND || op->type == SCROLL || op->type == HORN || op->type == FIREWALL || |
347 | /* POTIONS and ALTARS don't always cast spells, but if they do, update them */ |
344 | /* POTIONS and ALTARS don't always cast spells, but if they do, update them */ |
348 | ((op->type == POTION || op->type == ALTAR) && op->stats.sp)) && !op->inv && !arch_init) |
345 | ((op->type == POTION || op->type == ALTAR) && op->stats.sp)) && !op->inv && !loading_arch) |
349 | { |
346 | { |
350 | /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal' |
347 | /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal' |
351 | * in that spell was stored in sp. |
348 | * in that spell was stored in sp. |
352 | */ |
349 | */ |
353 | object *tmp = get_archetype (spell_mapping[op->type == FIREWALL ? op->stats.dam : op->stats.sp]); |
350 | object *tmp = get_archetype (spell_mapping[op->type == FIREWALL ? op->stats.dam : op->stats.sp]); |
354 | insert_ob_in_ob (tmp, op); |
351 | insert_ob_in_ob (tmp, op); |
355 | op->randomitems = NULL; /* So another spell isn't created for this object */ |
352 | op->randomitems = NULL; /* So another spell isn't created for this object */ |
356 | } |
353 | } |
357 | |
354 | |
358 | /* spellbooks & runes use slaying. But not to arch name, but to spell name */ |
355 | /* spellbooks & runes use slaying. But not to arch name, but to spell name */ |
359 | if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !arch_init) |
356 | if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !loading_arch) |
360 | { |
357 | { |
361 | object *tmp = get_archetype_by_object_name (op->slaying); |
358 | object *tmp = get_archetype_by_object_name (op->slaying); |
362 | insert_ob_in_ob (tmp, op); |
359 | insert_ob_in_ob (tmp, op); |
363 | op->randomitems = NULL; /* So another spell isn't created for this object */ |
360 | op->randomitems = NULL; /* So another spell isn't created for this object */ |
364 | /* without this, value is all screwed up */ |
361 | /* without this, value is all screwed up */ |
… | |
… | |
409 | } |
406 | } |
410 | |
407 | |
411 | } |
408 | } |
412 | |
409 | |
413 | static void |
410 | static void |
414 | set_move (MoveType & mt, const char *str) |
411 | set_move (MoveType &mt, const char *str) |
415 | { |
412 | { |
|
|
413 | static const struct flagstr { |
|
|
414 | const char *name; |
|
|
415 | MoveType flags; |
|
|
416 | } move_flags[] = { |
|
|
417 | { "walk" , MOVE_WALK }, |
|
|
418 | { "flying" , MOVE_FLY_LOW | MOVE_FLY_HIGH }, |
|
|
419 | { "fly_low" , MOVE_FLY_LOW }, |
|
|
420 | { "fly_high", MOVE_FLY_HIGH }, |
|
|
421 | { "swim" , MOVE_SWIM }, |
|
|
422 | { "boat" , MOVE_BOAT }, |
|
|
423 | { "all" , MOVE_ALL }, |
|
|
424 | }; |
|
|
425 | |
416 | if (!str) |
426 | if (!str) |
417 | { |
427 | { |
418 | mt = 0; |
428 | mt = 0; |
419 | return; |
429 | return; |
420 | } |
430 | } |
… | |
… | |
427 | |
437 | |
428 | mt = 0; |
438 | mt = 0; |
429 | |
439 | |
430 | for (str = strtok ((char *) str, " "); str; str = strtok (0, " ")) |
440 | for (str = strtok ((char *) str, " "); str; str = strtok (0, " ")) |
431 | { |
441 | { |
432 | if (!strcasecmp (str, "all")) |
442 | bool negate = 0; |
433 | mt |= MOVE_ALL; |
443 | |
434 | else |
444 | if (*str == '-') |
435 | { |
445 | { |
436 | int i, negate = 0; |
446 | negate = 1; |
|
|
447 | str++; |
|
|
448 | } |
437 | |
449 | |
438 | if (*str == '-') |
450 | for (const flagstr *f = move_flags; f < move_flags + sizeof (move_flags) / sizeof (move_flags [0]); ++f) |
|
|
451 | { |
|
|
452 | if (!strcmp (f->name, str)) |
439 | { |
453 | { |
440 | negate = 1; |
|
|
441 | str++; |
|
|
442 | } |
|
|
443 | |
|
|
444 | for (i = 0; move_name[i]; i++) |
|
|
445 | { |
|
|
446 | if (!strcasecmp (move_name[i], str)) |
|
|
447 | { |
|
|
448 | if (negate) |
454 | if (negate) |
449 | mt &= ~(1 << i); |
455 | mt &= ~f->flags; |
450 | else |
|
|
451 | mt |= (1 << i); |
|
|
452 | |
|
|
453 | break; |
|
|
454 | } |
|
|
455 | } |
|
|
456 | |
|
|
457 | if (!move_name[i]) |
|
|
458 | { |
|
|
459 | /* fly is a special case - covers both fly_low and |
|
|
460 | * fly_high - since it doesn't match to a specific |
|
|
461 | * single bit, have to special case it. |
|
|
462 | */ |
|
|
463 | if (!strcasecmp (str, "flying")) |
|
|
464 | { |
|
|
465 | if (negate) |
|
|
466 | mt &= ~MOVE_FLYING; |
|
|
467 | else |
|
|
468 | mt |= MOVE_FLYING; |
|
|
469 | } |
|
|
470 | else |
456 | else |
471 | LOG (llevDebug, "common/loader.l: set_move - unknown move string '%s'\n", str); |
457 | mt |= f->flags; |
|
|
458 | |
|
|
459 | goto next; |
472 | } |
460 | } |
473 | } |
461 | } |
|
|
462 | |
|
|
463 | LOG (llevDebug, "common/loader.C: set_move - unknown move string '%s'\n", str); |
|
|
464 | |
|
|
465 | next: ; |
474 | } |
466 | } |
475 | } |
467 | } |
476 | |
468 | |
477 | #define GET_FLAG(op,flag) \ |
469 | #define GET_FLAG(op,flag) \ |
478 | if (f.get_sint32 ()) \ |
470 | if (f.get_sint32 ()) \ |
… | |
… | |
559 | } |
551 | } |
560 | } |
552 | } |
561 | continue; |
553 | continue; |
562 | |
554 | |
563 | case KW_other_arch: |
555 | case KW_other_arch: |
|
|
556 | other_arch = |
|
|
557 | loading_arch |
|
|
558 | ? archetype::get (f.get_str ()) |
564 | other_arch = archetype::find (f.get_str ()); |
559 | : archetype::find (f.get_str ()); |
|
|
560 | |
|
|
561 | if (!other_arch) |
|
|
562 | LOG (llevError, "%s uses unknown other_arch '%s'.\n", debug_desc (), f.get_str ()); |
565 | break; |
563 | break; |
566 | |
564 | |
567 | case KW_animation: |
565 | case KW_animation: |
568 | { |
566 | { |
569 | CLEAR_FLAG (this, FLAG_ANIMATE); |
567 | CLEAR_FLAG (this, FLAG_ANIMATE); |
… | |
… | |
595 | move_slow |= MOVE_WALK; |
593 | move_slow |= MOVE_WALK; |
596 | f.get (move_slow_penalty); |
594 | f.get (move_slow_penalty); |
597 | break; |
595 | break; |
598 | |
596 | |
599 | case KW_face: |
597 | case KW_face: |
600 | face = &new_faces[FindFace (f.get_str (), 0)]; |
598 | face = face_find (f.get_str ()); |
601 | break; |
599 | break; |
602 | |
600 | |
603 | case KW_x: f.get (x); break; |
601 | case KW_x: f.get (x); break; |
604 | case KW_y: f.get (y); break; |
602 | case KW_y: f.get (y); break; |
605 | |
603 | |
… | |
… | |
886 | case KW_glow_radius: f.get (glow_radius); break; |
884 | case KW_glow_radius: f.get (glow_radius); break; |
887 | case KW_weapontype: f.get (weapontype); break; |
885 | case KW_weapontype: f.get (weapontype); break; |
888 | case KW_tooltype: f.get (tooltype); break; |
886 | case KW_tooltype: f.get (tooltype); break; |
889 | case KW_casting_time: f.get (casting_time); break; |
887 | case KW_casting_time: f.get (casting_time); break; |
890 | case KW_elevation: f.get (elevation); break; |
888 | case KW_elevation: f.get (elevation); break; |
891 | case KW_smoothlevel: f.get (smoothlevel); break; |
889 | case KW_smoothlevel: f.get (smoothlevel); smoothlevel = clamp (smoothlevel, 0, 255); break; |
892 | case KW_client_type: f.get (client_type); break; |
890 | case KW_client_type: f.get (client_type); break; |
893 | case KW_duration: f.get (duration); break; |
891 | case KW_duration: f.get (duration); break; |
894 | case KW_range: f.get (range); break; |
892 | case KW_range: f.get (range); break; |
895 | case KW_range_modifier: f.get (range_modifier); break; |
893 | case KW_range_modifier: f.get (range_modifier); break; |
896 | case KW_dam_modifier: f.get (dam_modifier); break; |
894 | case KW_dam_modifier: f.get (dam_modifier); break; |
… | |
… | |
916 | case KW_connected: |
914 | case KW_connected: |
917 | add_button_link (this, map, f.get_sint32 ()); |
915 | add_button_link (this, map, f.get_sint32 ()); |
918 | break; |
916 | break; |
919 | |
917 | |
920 | case KW_randomitems: |
918 | case KW_randomitems: |
921 | randomitems = find_treasurelist (f.get_str ()); |
919 | if (f.get_str ()) |
|
|
920 | { |
|
|
921 | randomitems = |
|
|
922 | loading_arch |
|
|
923 | ? treasurelist::get (f.get_str ()) |
|
|
924 | : treasurelist::find (f.get_str ()); |
|
|
925 | |
922 | //if (!randomitems) |
926 | if (!randomitems) |
923 | // LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ()); |
927 | LOG (llevError, "%s uses unknown randomitems '%s'.\n", debug_desc (), f.get_str ()); |
|
|
928 | } |
924 | break; |
929 | break; |
925 | |
930 | |
926 | case KW_msg: |
931 | case KW_msg: |
927 | f.get_ml (KW_endmsg, msg); |
932 | f.get_ml (KW_endmsg, msg); |
928 | //TODO: allow longer messages |
933 | //TODO: allow longer messages |
… | |
… | |
949 | break; |
954 | break; |
950 | |
955 | |
951 | case KW_end: |
956 | case KW_end: |
952 | check_loaded_object (this); |
957 | check_loaded_object (this); |
953 | |
958 | |
954 | if (!arch_init) |
959 | if (!loading_arch) |
955 | instantiate (); |
960 | instantiate (); |
956 | |
961 | |
957 | f.next (); |
962 | f.next (); |
958 | return true; |
963 | return true; |
959 | |
964 | |
… | |
… | |
971 | f.next (); |
976 | f.next (); |
972 | } |
977 | } |
973 | } |
978 | } |
974 | |
979 | |
975 | object * |
980 | object * |
976 | object::read (object_thawer &f) |
981 | object::read (object_thawer &f, maptile *map) |
977 | { |
982 | { |
978 | assert (f.kw == KW_arch); |
983 | assert (f.kw == KW_arch); |
979 | |
984 | |
980 | archetype *arch = archetype::find (f.get_str ()); |
985 | archetype *arch = archetype::find (f.get_str ()); |
|
|
986 | |
|
|
987 | if (!arch) |
|
|
988 | { |
|
|
989 | LOG (llevError, "object refering to nonexistant archetype '%s'.\n", f.get_str ()); |
|
|
990 | arch = archetype::find ("earthwall"); |
|
|
991 | } |
|
|
992 | |
981 | assert (arch); //D maybe use exception handling of sorts? |
993 | assert (arch); //D maybe use exception handling of sorts? |
982 | |
994 | |
983 | object *op = object::create (); |
995 | object *op = object::create (); |
984 | |
996 | |
985 | op->arch = arch; |
997 | op->map = map; |
986 | arch->clone.copy_to (op); |
998 | arch->clone.copy_to (op); |
987 | // copy_to activates, this should be fixed properly |
999 | // copy_to activates, this should be fixed properly |
988 | op->deactivate (); |
1000 | op->deactivate (); |
989 | |
1001 | |
990 | if (!op->parse_kv (f)) |
1002 | if (!op->parse_kv (f)) |
991 | { |
1003 | { |
992 | delete op; |
1004 | op->destroy (true); |
993 | return 0; |
1005 | return 0; |
994 | } |
1006 | } |
995 | |
1007 | |
996 | return op; |
1008 | return op; |
997 | } |
1009 | } |
… | |
… | |
1005 | int |
1017 | int |
1006 | set_variable (object *op, char *buf) |
1018 | set_variable (object *op, char *buf) |
1007 | { |
1019 | { |
1008 | object_thawer f (buf, (AV *)0); |
1020 | object_thawer f (buf, (AV *)0); |
1009 | |
1021 | |
|
|
1022 | f.kw = KW_arch; // special hack so that parse_kv skips |
1010 | return op->parse_kv (f); |
1023 | return op->parse_kv (f); |
1011 | } |
1024 | } |
1012 | |
1025 | |
1013 | /* This returns a string of the integer movement type */ |
1026 | /* This returns a string of the integer movement type */ |
1014 | #if 0 |
1027 | #if 0 |
… | |
… | |
1242 | f.put (KW_msg, KW_endmsg, op->msg); |
1255 | f.put (KW_msg, KW_endmsg, op->msg); |
1243 | if (op->lore != tmp->lore) |
1256 | if (op->lore != tmp->lore) |
1244 | f.put (KW_lore, KW_endlore, op->lore); |
1257 | f.put (KW_lore, KW_endlore, op->lore); |
1245 | |
1258 | |
1246 | CMP_OUT (other_arch); |
1259 | CMP_OUT (other_arch); |
1247 | CMP_OUT (face); |
1260 | |
|
|
1261 | if (op->face != tmp->face) f.put (KW_face, op->face ? &faces [op->face] : 0); |
1248 | |
1262 | |
1249 | if (op->animation_id != tmp->animation_id) |
1263 | if (op->animation_id != tmp->animation_id) |
1250 | if (op->animation_id) |
1264 | if (op->animation_id) |
1251 | { |
1265 | { |
1252 | f.put (KW_animation, animations[GET_ANIM_ID (op)].name); |
1266 | f.put (KW_animation, animations[GET_ANIM_ID (op)].name); |