1 | %{ |
1 | %{ |
2 | /* |
2 | /* |
3 | * static char *rcsid_object_c = |
3 | * static char *rcsid_object_c = |
4 | * "$Id: loader.l,v 1.6 2006/07/01 21:06:06 root Exp $"; |
4 | * "$Id: loader.l,v 1.17 2006/08/31 09:19:33 root Exp $"; |
5 | */ |
5 | */ |
6 | |
6 | |
7 | /* |
7 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
9 | |
9 | |
… | |
… | |
35 | #include <global.h> |
35 | #include <global.h> |
36 | #include <loader.h> |
36 | #include <loader.h> |
37 | #include <newserver.h> |
37 | #include <newserver.h> |
38 | #include <sproto.h> |
38 | #include <sproto.h> |
39 | |
39 | |
40 | #define YY_DECL int lex_load(object *op, int map_flags) |
40 | #define YY_DECL int lex_load(object *op, object_thawer &thawer, int map_flags) |
41 | |
41 | |
42 | static char *yval(); |
42 | static char *yval(); |
43 | |
43 | |
44 | static int lex_error; |
44 | static int lex_error; |
45 | static char msgbuf[HUGE_BUF]; |
45 | static char msgbuf[65536]; |
46 | static char lorebuf[HUGE_BUF]; |
46 | static char lorebuf[65536]; |
47 | |
47 | |
48 | /* Maps the MOVE_* values to names */ |
48 | /* Maps the MOVE_* values to names */ |
49 | static const char *const move_name[] = {"walk", "fly_low", "fly_high", "swim", "boat", |
49 | static const char *const move_name[] = {"walk", "fly_low", "fly_high", "swim", "boat", |
50 | NULL}; |
50 | NULL}; |
51 | |
51 | |
… | |
… | |
57 | * If you are adding a new spell, you should not modify this - you |
57 | * If you are adding a new spell, you should not modify this - you |
58 | * new spell won't have been used, and thus won't have any legacy object. |
58 | * new spell won't have been used, and thus won't have any legacy object. |
59 | * NULL entries in this table are valid - to denote objects that should |
59 | * NULL entries in this table are valid - to denote objects that should |
60 | * not be updated for whatever reason. |
60 | * not be updated for whatever reason. |
61 | */ |
61 | */ |
62 | const char *const spell_mapping[] = { |
62 | const char *spell_mapping[] = { |
63 | "spell_magic_bullet", /* 0 */ |
63 | "spell_magic_bullet", /* 0 */ |
64 | "spell_small_fireball", /* 1 */ |
64 | "spell_small_fireball", /* 1 */ |
65 | "spell_medium_fireball", /* 2 */ |
65 | "spell_medium_fireball", /* 2 */ |
66 | "spell_large_fireball", /* 3 */ |
66 | "spell_large_fireball", /* 3 */ |
67 | "spell_burning_hands", /* 4 */ |
67 | "spell_burning_hands", /* 4 */ |
… | |
… | |
693 | ^name_pl{S} { char *yv=yval(); |
693 | ^name_pl{S} { char *yv=yval(); |
694 | |
694 | |
695 | if (*yv=='\0') LOG(llevError,"Name without val\n"); |
695 | if (*yv=='\0') LOG(llevError,"Name without val\n"); |
696 | else FREE_AND_COPY(op->name_pl, yv); |
696 | else FREE_AND_COPY(op->name_pl, yv); |
697 | } |
697 | } |
|
|
698 | ^attach{S} { char *yv=yval(); |
|
|
699 | if (*yv) |
|
|
700 | op->attach = add_string (yv); |
|
|
701 | } |
698 | ^skill{S} FREE_AND_COPY(op->skill,yval()); |
702 | ^skill{S} FREE_AND_COPY(op->skill,yval()); |
699 | ^custom_name{S} { char *yv=yval(); |
703 | ^custom_name{S} { char *yv=yval(); |
700 | |
704 | |
701 | if (*yv=='\0') LOG(llevError,"Custom name without val\n"); |
705 | if (*yv=='\0') LOG(llevError,"Custom name without val\n"); |
702 | else FREE_AND_COPY(op->custom_name, yv); |
706 | else FREE_AND_COPY(op->custom_name, yv); |
… | |
… | |
712 | */ |
716 | */ |
713 | if (op->arch) { |
717 | if (op->arch) { |
714 | object *tmp; |
718 | object *tmp; |
715 | char *yv=yval(); |
719 | char *yv=yval(); |
716 | |
720 | |
717 | tmp=get_object(); |
|
|
718 | tmp->arch = find_archetype(yv); |
721 | archetype *arch = find_archetype(yv); |
719 | if (tmp->arch!=NULL) |
722 | if (arch!=NULL) |
720 | copy_object(&tmp->arch->clone,tmp); |
723 | tmp = arch_to_object (arch); |
721 | else { |
724 | else { |
|
|
725 | tmp = get_object (); |
722 | if (tmp->name) free_string(tmp->name); |
726 | if (tmp->name) free_string(tmp->name); |
723 | /* record the name of the broken object */ |
727 | /* record the name of the broken object */ |
724 | tmp->name = add_string(yv); |
728 | tmp->name = add_string(yv); |
725 | } |
729 | } |
726 | strcpy(msgbuf, ""); |
730 | strcpy(msgbuf, ""); |
727 | strcpy(lorebuf, ""); |
731 | strcpy(lorebuf, ""); |
728 | lex_load(tmp, map_flags); |
732 | lex_load(tmp, thawer, map_flags); |
729 | if (tmp->arch) { |
733 | if (tmp->arch) { |
730 | insert_ob_in_ob(tmp,op); |
734 | insert_ob_in_ob(tmp,op); |
731 | } |
735 | } |
732 | else { |
736 | else { |
733 | LOG(llevDebug,"Discarding object without arch: %s\n", tmp->name?tmp->name:"(null)"); |
737 | LOG(llevDebug,"Discarding object without arch: %s\n", tmp->name?tmp->name:"(null)"); |
… | |
… | |
737 | /* This is the actual archetype definition then */ |
741 | /* This is the actual archetype definition then */ |
738 | else { |
742 | else { |
739 | char *yv=yval(); |
743 | char *yv=yval(); |
740 | |
744 | |
741 | op->arch=find_archetype(yv); |
745 | op->arch=find_archetype(yv); |
742 | if (op->arch!=NULL) copy_object(&op->arch->clone,op); |
746 | if (op->arch!=NULL) { |
743 | else if (!arch_init) { |
747 | copy_object(&op->arch->clone,op); |
|
|
748 | } else if (!arch_init) { |
744 | if (op->name) free_string(op->name); |
749 | if (op->name) free_string(op->name); |
745 | /* record the name of the broken object */ |
750 | /* record the name of the broken object */ |
746 | op->name = add_string(yv); |
751 | op->name = add_string(yv); |
747 | } |
752 | } |
748 | } |
753 | } |
… | |
… | |
762 | ^more{WS}$ { /* We need to record that this is a multipart object, |
767 | ^more{WS}$ { /* We need to record that this is a multipart object, |
763 | * so the calling function can glue things back together |
768 | * so the calling function can glue things back together |
764 | */ |
769 | */ |
765 | ismore=1; |
770 | ismore=1; |
766 | } |
771 | } |
767 | |
|
|
768 | ^end{WS}$ { check_loaded_object(op); |
772 | ^end{WS}$ { check_loaded_object(op); |
|
|
773 | |
|
|
774 | if (!arch_init) |
|
|
775 | op->instantiate (); |
|
|
776 | |
769 | if (ismore) return LL_MORE; |
777 | if (ismore) return LL_MORE; |
770 | else return LL_NORMAL; |
778 | else return LL_NORMAL; |
771 | } |
779 | } |
|
|
780 | ^oid{S} { |
|
|
781 | thawer.get (op, IVAL); |
|
|
782 | } |
772 | ^last_heal{S} op->last_heal = IVAL; |
783 | ^last_heal{S} op->last_heal = IVAL; |
773 | ^last_sp{S} op->last_sp = IVAL; |
784 | ^last_sp{S} op->last_sp = IVAL; |
774 | ^last_grace{S} op->last_grace = IVAL; |
785 | ^last_grace{S} op->last_grace = IVAL; |
775 | ^last_eat{S} op->last_eat = IVAL; |
786 | ^last_eat{S} op->last_eat = IVAL; |
776 | ^speed{S} { op->speed = FVAL; |
787 | ^speed{S} { op->speed = FVAL; |
… | |
… | |
984 | ^resist_disease{S} SET_RESIST(op, ATNR_DISEASE, IVAL); |
995 | ^resist_disease{S} SET_RESIST(op, ATNR_DISEASE, IVAL); |
985 | |
996 | |
986 | /* Old style resistances */ |
997 | /* Old style resistances */ |
987 | ^immune{S} set_protection(op, IVAL, RESIST_IMMUNE); |
998 | ^immune{S} set_protection(op, IVAL, RESIST_IMMUNE); |
988 | ^protected{S} set_protection(op, IVAL, RESIST_PROT); |
999 | ^protected{S} set_protection(op, IVAL, RESIST_PROT); |
989 | ^vulnerable{S} set_protection(op, IVAL, RESIST_VULN); |
1000 | ^vulnerable{S} set_protection(op, IVAL, (uint16) RESIST_VULN); |
990 | |
1001 | |
991 | /* old values - keep them around for now, but they should be removed at some point */ |
1002 | /* old values - keep them around for now, but they should be removed at some point */ |
992 | ^has_ready_rod{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
1003 | ^has_ready_rod{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
993 | ^has_ready_horn{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
1004 | ^has_ready_horn{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
994 | ^has_ready_wand{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
1005 | ^has_ready_wand{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
… | |
… | |
1033 | ^can_impale{S} { /* That these are for the new combat code */ } |
1044 | ^can_impale{S} { /* That these are for the new combat code */ } |
1034 | ^can_cut{S} { /* just ignore for now */ } |
1045 | ^can_cut{S} { /* just ignore for now */ } |
1035 | ^can_dam_armour{S} { } |
1046 | ^can_dam_armour{S} { } |
1036 | ^weapontype{S} op->weapontype = IVAL; |
1047 | ^weapontype{S} op->weapontype = IVAL; |
1037 | ^tooltype{S} op->tooltype = IVAL; |
1048 | ^tooltype{S} op->tooltype = IVAL; |
1038 | ^casting_time{S} op->casting_time = FVAL; |
1049 | ^casting_time{S} op->casting_time = (sint16) FVAL; |
1039 | ^elevation{S} op->elevation = IVAL; |
1050 | ^elevation{S} op->elevation = IVAL; |
1040 | ^smoothlevel{S} op->smoothlevel = IVAL; |
1051 | ^smoothlevel{S} op->smoothlevel = IVAL; |
1041 | ^client_type{S} op->client_type = IVAL; |
1052 | ^client_type{S} op->client_type = IVAL; |
1042 | ^body_{A} set_body_info(op, yytext); |
1053 | ^body_{A} set_body_info(op, yytext); |
1043 | ^duration{S} op->duration = IVAL; |
1054 | ^duration{S} op->duration = IVAL; |
… | |
… | |
1045 | ^range_modifier{S} op->range_modifier = IVAL; |
1056 | ^range_modifier{S} op->range_modifier = IVAL; |
1046 | ^dam_modifier{S} op->dam_modifier = IVAL; |
1057 | ^dam_modifier{S} op->dam_modifier = IVAL; |
1047 | ^duration_modifier{S} op->duration_modifier = IVAL; |
1058 | ^duration_modifier{S} op->duration_modifier = IVAL; |
1048 | ^is_buildable{S} SET_OR_CLEAR_FLAG( op, FLAG_IS_BUILDABLE, IVAL ); |
1059 | ^is_buildable{S} SET_OR_CLEAR_FLAG( op, FLAG_IS_BUILDABLE, IVAL ); |
1049 | |
1060 | |
1050 | ^event_apply{S} { |
1061 | ^event_ { |
1051 | char *yv=yval(); |
1062 | LOG (llevError, "stray event_* in map file, skipping."); |
1052 | if (*yv=='\0') |
|
|
1053 | LOG(llevError,"Event (apply) without val\n"); |
|
|
1054 | else |
|
|
1055 | insert_event(op,EVENT_APPLY,yv,NULL,NULL); |
|
|
1056 | } |
1063 | } |
1057 | |
|
|
1058 | ^event_apply_plugin{S} { |
|
|
1059 | char *yv=yval(); |
|
|
1060 | if (*yv=='\0') |
|
|
1061 | LOG(llevError,"Event (apply) without plugin\n"); |
|
|
1062 | else |
|
|
1063 | insert_event(op,EVENT_APPLY,NULL,yv,NULL); |
|
|
1064 | } |
|
|
1065 | |
|
|
1066 | ^event_apply_options{S} { |
|
|
1067 | char *yv=yval(); |
|
|
1068 | if (*yv=='\0') |
|
|
1069 | LOG(llevError,"Event (apply) without options\n"); |
|
|
1070 | else |
|
|
1071 | insert_event(op,EVENT_APPLY,NULL,NULL,yv); |
|
|
1072 | } |
|
|
1073 | |
|
|
1074 | ^event_attack{S} { |
|
|
1075 | char *yv=yval(); |
|
|
1076 | if (*yv=='\0') |
|
|
1077 | LOG(llevError,"Event (attack) without val\n"); |
|
|
1078 | else |
|
|
1079 | insert_event(op,EVENT_ATTACK,yv,NULL,NULL); |
|
|
1080 | } |
|
|
1081 | |
|
|
1082 | ^event_attack_plugin{S} { |
|
|
1083 | char *yv=yval(); |
|
|
1084 | if (*yv=='\0') |
|
|
1085 | LOG(llevError,"Event (attack) without plugin\n"); |
|
|
1086 | else |
|
|
1087 | insert_event(op,EVENT_ATTACK,NULL,yv,NULL); |
|
|
1088 | } |
|
|
1089 | |
|
|
1090 | ^event_attack_options{S} { |
|
|
1091 | char *yv=yval(); |
|
|
1092 | if (*yv=='\0') |
|
|
1093 | LOG(llevError,"Event (attack) without options\n"); |
|
|
1094 | else |
|
|
1095 | insert_event(op,EVENT_ATTACK,NULL,NULL,yv); |
|
|
1096 | } |
|
|
1097 | ^event_death{S} { |
|
|
1098 | char *yv=yval(); |
|
|
1099 | if (*yv=='\0') |
|
|
1100 | LOG(llevError,"Event (death) without val\n"); |
|
|
1101 | else |
|
|
1102 | insert_event(op,EVENT_DEATH,yv,NULL,NULL); |
|
|
1103 | } |
|
|
1104 | |
|
|
1105 | ^event_death_plugin{S} { |
|
|
1106 | char *yv=yval(); |
|
|
1107 | if (*yv=='\0') |
|
|
1108 | LOG(llevError,"Event (death) without plugin\n"); |
|
|
1109 | else |
|
|
1110 | insert_event(op,EVENT_DEATH,NULL,yv,NULL); |
|
|
1111 | } |
|
|
1112 | |
|
|
1113 | ^event_death_options{S} { |
|
|
1114 | char *yv=yval(); |
|
|
1115 | if (*yv=='\0') |
|
|
1116 | LOG(llevError,"Event (death) without options\n"); |
|
|
1117 | else |
|
|
1118 | insert_event(op,EVENT_DEATH,NULL,NULL,yv); |
|
|
1119 | } |
|
|
1120 | ^event_drop{S} { |
|
|
1121 | char *yv=yval(); |
|
|
1122 | if (*yv=='\0') |
|
|
1123 | LOG(llevError,"Event (drop) without val\n"); |
|
|
1124 | else |
|
|
1125 | insert_event(op,EVENT_DROP,yv,NULL,NULL); |
|
|
1126 | } |
|
|
1127 | |
|
|
1128 | ^event_drop_plugin{S} { |
|
|
1129 | char *yv=yval(); |
|
|
1130 | if (*yv=='\0') |
|
|
1131 | LOG(llevError,"Event (drop) without plugin\n"); |
|
|
1132 | else |
|
|
1133 | insert_event(op,EVENT_DROP,NULL,yv,NULL); |
|
|
1134 | } |
|
|
1135 | |
|
|
1136 | ^event_drop_options{S} { |
|
|
1137 | char *yv=yval(); |
|
|
1138 | if (*yv=='\0') |
|
|
1139 | LOG(llevError,"Event (drop) without options\n"); |
|
|
1140 | else |
|
|
1141 | insert_event(op,EVENT_DROP,NULL,NULL,yv); |
|
|
1142 | } |
|
|
1143 | ^event_pickup{S} { |
|
|
1144 | char *yv=yval(); |
|
|
1145 | if (*yv=='\0') |
|
|
1146 | LOG(llevError,"Event (pickup) without val\n"); |
|
|
1147 | else |
|
|
1148 | insert_event(op,EVENT_PICKUP,yv,NULL,NULL); |
|
|
1149 | } |
|
|
1150 | |
|
|
1151 | ^event_pickup_plugin{S} { |
|
|
1152 | char *yv=yval(); |
|
|
1153 | if (*yv=='\0') |
|
|
1154 | LOG(llevError,"Event (pickup) without plugin\n"); |
|
|
1155 | else |
|
|
1156 | insert_event(op,EVENT_PICKUP,NULL,yv,NULL); |
|
|
1157 | } |
|
|
1158 | |
|
|
1159 | ^event_pickup_options{S} { |
|
|
1160 | char *yv=yval(); |
|
|
1161 | if (*yv=='\0') |
|
|
1162 | LOG(llevError,"Event (pickup) without options\n"); |
|
|
1163 | else |
|
|
1164 | insert_event(op,EVENT_PICKUP,NULL,NULL,yv); |
|
|
1165 | } |
|
|
1166 | ^event_say{S} { |
|
|
1167 | char *yv=yval(); |
|
|
1168 | if (*yv=='\0') |
|
|
1169 | LOG(llevError,"Event (say) without val\n"); |
|
|
1170 | else |
|
|
1171 | insert_event(op,EVENT_SAY,yv,NULL,NULL); |
|
|
1172 | } |
|
|
1173 | |
|
|
1174 | ^event_say_plugin{S} { |
|
|
1175 | char *yv=yval(); |
|
|
1176 | if (*yv=='\0') |
|
|
1177 | LOG(llevError,"Event (say) without plugin\n"); |
|
|
1178 | else |
|
|
1179 | insert_event(op,EVENT_SAY,NULL,yv,NULL); |
|
|
1180 | } |
|
|
1181 | |
|
|
1182 | ^event_say_options{S} { |
|
|
1183 | char *yv=yval(); |
|
|
1184 | if (*yv=='\0') |
|
|
1185 | LOG(llevError,"Event (say) without options\n"); |
|
|
1186 | else |
|
|
1187 | insert_event(op,EVENT_SAY,NULL,NULL,yv); |
|
|
1188 | } |
|
|
1189 | ^event_stop{S} { |
|
|
1190 | char *yv=yval(); |
|
|
1191 | if (*yv=='\0') |
|
|
1192 | LOG(llevError,"Event (stop) without val\n"); |
|
|
1193 | else |
|
|
1194 | insert_event(op,EVENT_STOP,yv,NULL,NULL); |
|
|
1195 | } |
|
|
1196 | |
|
|
1197 | ^event_stop_plugin{S} { |
|
|
1198 | char *yv=yval(); |
|
|
1199 | if (*yv=='\0') |
|
|
1200 | LOG(llevError,"Event (stop) without plugin\n"); |
|
|
1201 | else |
|
|
1202 | insert_event(op,EVENT_STOP,NULL,yv,NULL); |
|
|
1203 | } |
|
|
1204 | |
|
|
1205 | ^event_stop_options{S} { |
|
|
1206 | char *yv=yval(); |
|
|
1207 | if (*yv=='\0') |
|
|
1208 | LOG(llevError,"Event (stop) without options\n"); |
|
|
1209 | else |
|
|
1210 | insert_event(op,EVENT_STOP,NULL,NULL,yv); |
|
|
1211 | } |
|
|
1212 | ^event_time{S} { |
|
|
1213 | char *yv=yval(); |
|
|
1214 | if (*yv=='\0') |
|
|
1215 | LOG(llevError,"Event (time) without val\n"); |
|
|
1216 | else |
|
|
1217 | insert_event(op,EVENT_TIME,yv,NULL,NULL); |
|
|
1218 | } |
|
|
1219 | |
|
|
1220 | ^event_time_plugin{S} { |
|
|
1221 | char *yv=yval(); |
|
|
1222 | if (*yv=='\0') |
|
|
1223 | LOG(llevError,"Event (time) without plugin\n"); |
|
|
1224 | else |
|
|
1225 | insert_event(op,EVENT_TIME,NULL,yv,NULL); |
|
|
1226 | } |
|
|
1227 | |
|
|
1228 | ^event_time_options{S} { |
|
|
1229 | char *yv=yval(); |
|
|
1230 | if (*yv=='\0') |
|
|
1231 | LOG(llevError,"Event (time) without options\n"); |
|
|
1232 | else |
|
|
1233 | insert_event(op,EVENT_TIME,NULL,NULL,yv); |
|
|
1234 | } |
|
|
1235 | ^event_throw{S} { |
|
|
1236 | char *yv=yval(); |
|
|
1237 | if (*yv=='\0') |
|
|
1238 | LOG(llevError,"Event (throw) without val\n"); |
|
|
1239 | else |
|
|
1240 | insert_event(op,EVENT_THROW,yv,NULL,NULL); |
|
|
1241 | } |
|
|
1242 | |
|
|
1243 | ^event_throw_plugin{S} { |
|
|
1244 | char *yv=yval(); |
|
|
1245 | if (*yv=='\0') |
|
|
1246 | LOG(llevError,"Event (throw) without plugin\n"); |
|
|
1247 | else |
|
|
1248 | insert_event(op,EVENT_THROW,NULL,yv,NULL); |
|
|
1249 | } |
|
|
1250 | |
|
|
1251 | ^event_throw_options{S} { |
|
|
1252 | char *yv=yval(); |
|
|
1253 | if (*yv=='\0') |
|
|
1254 | LOG(llevError,"Event (apply) without options\n"); |
|
|
1255 | else |
|
|
1256 | insert_event(op,EVENT_THROW,NULL,NULL,yv); |
|
|
1257 | } |
|
|
1258 | ^event_trigger{S} { |
|
|
1259 | char *yv=yval(); |
|
|
1260 | if (*yv=='\0') |
|
|
1261 | LOG(llevError,"Event (trigger) without val\n"); |
|
|
1262 | else |
|
|
1263 | insert_event(op,EVENT_TRIGGER,yv,NULL,NULL); |
|
|
1264 | } |
|
|
1265 | |
|
|
1266 | ^event_trigger_plugin{S} { |
|
|
1267 | char *yv=yval(); |
|
|
1268 | if (*yv=='\0') |
|
|
1269 | LOG(llevError,"Event (trigger) without plugin\n"); |
|
|
1270 | else |
|
|
1271 | insert_event(op,EVENT_TRIGGER,NULL,yv,NULL); |
|
|
1272 | } |
|
|
1273 | |
|
|
1274 | ^event_trigger_options{S} { |
|
|
1275 | char *yv=yval(); |
|
|
1276 | if (*yv=='\0') |
|
|
1277 | LOG(llevError,"Event (trigger) without options\n"); |
|
|
1278 | else |
|
|
1279 | insert_event(op,EVENT_TRIGGER,NULL,NULL,yv); |
|
|
1280 | } |
|
|
1281 | ^event_close{S} { |
|
|
1282 | char *yv=yval(); |
|
|
1283 | if (*yv=='\0') |
|
|
1284 | LOG(llevError,"Event (close) without val\n"); |
|
|
1285 | else |
|
|
1286 | insert_event(op,EVENT_CLOSE,yv,NULL,NULL); |
|
|
1287 | } |
|
|
1288 | |
|
|
1289 | ^event_close_plugin{S} { |
|
|
1290 | char *yv=yval(); |
|
|
1291 | if (*yv=='\0') |
|
|
1292 | LOG(llevError,"Event (close) without plugin\n"); |
|
|
1293 | else |
|
|
1294 | insert_event(op,EVENT_CLOSE,NULL,yv,NULL); |
|
|
1295 | } |
|
|
1296 | |
|
|
1297 | ^event_close_options{S} { |
|
|
1298 | char *yv=yval(); |
|
|
1299 | if (*yv=='\0') |
|
|
1300 | LOG(llevError,"Event (close) without options\n"); |
|
|
1301 | else |
|
|
1302 | insert_event(op,EVENT_CLOSE,NULL,NULL,yv); |
|
|
1303 | } |
|
|
1304 | ^event_timer{S} { |
|
|
1305 | char *yv=yval(); |
|
|
1306 | if (*yv=='\0') |
|
|
1307 | LOG(llevError,"Event (timer) without val\n"); |
|
|
1308 | else |
|
|
1309 | insert_event(op,EVENT_TIMER,yv,NULL,NULL); |
|
|
1310 | } |
|
|
1311 | |
|
|
1312 | ^event_timer_plugin{S} { |
|
|
1313 | char *yv=yval(); |
|
|
1314 | if (*yv=='\0') |
|
|
1315 | LOG(llevError,"Event (timer) without plugin\n"); |
|
|
1316 | else |
|
|
1317 | insert_event(op,EVENT_TIMER,NULL,yv,NULL); |
|
|
1318 | } |
|
|
1319 | |
|
|
1320 | ^event_timer_options{S} { |
|
|
1321 | char *yv=yval(); |
|
|
1322 | if (*yv=='\0') |
|
|
1323 | LOG(llevError,"Event (timer) without options\n"); |
|
|
1324 | else |
|
|
1325 | insert_event(op,EVENT_TIMER,NULL,NULL,yv); |
|
|
1326 | } |
|
|
1327 | |
|
|
1328 | ^current_weapon_script{S} { char *yv=yval(); |
|
|
1329 | |
|
|
1330 | if (*yv=='\0') LOG(llevError,"Script (current weapon) without val\n"); |
|
|
1331 | else |
|
|
1332 | { |
|
|
1333 | FREE_AND_COPY(op->current_weapon_script, yv); |
|
|
1334 | }; |
|
|
1335 | } |
|
|
1336 | |
1064 | |
1337 | <*>(^{WS}$)|\n {/* ignore empty lines, newlines we don't do above */} |
1065 | <*>(^{WS}$)|\n {/* ignore empty lines, newlines we don't do above */} |
1338 | #.*\n {} |
1066 | #.*\n {} |
1339 | |
1067 | |
1340 | <<EOF>> {/* If we got an error, return the error. Otherwise, return that we got EOF */ |
1068 | <<EOF>> {/* If we got an error, return the error. Otherwise, return that we got EOF */ |
… | |
… | |
1398 | * be reset. |
1126 | * be reset. |
1399 | * LO_NOREAD (3): Reset the buffers, but don't read from it. (op can be null) |
1127 | * LO_NOREAD (3): Reset the buffers, but don't read from it. (op can be null) |
1400 | * |
1128 | * |
1401 | */ |
1129 | */ |
1402 | |
1130 | |
1403 | int load_object(FILE *fp, object *op, int bufstate, int map_flags) { |
1131 | int load_object(object_thawer &fp, object *op, int bufstate, int map_flags) { |
1404 | int retval; |
1132 | int retval; |
1405 | char inbuf[MAX_BUF]; |
1133 | char inbuf[MAX_BUF]; |
1406 | |
1134 | |
1407 | strcpy(msgbuf, ""); |
1135 | strcpy(msgbuf, ""); |
1408 | strcpy(lorebuf, ""); |
1136 | strcpy(lorebuf, ""); |
… | |
… | |
1414 | } |
1142 | } |
1415 | if (bufstate==LO_LINEMODE) { |
1143 | if (bufstate==LO_LINEMODE) { |
1416 | YY_BUFFER_STATE yybufstate; |
1144 | YY_BUFFER_STATE yybufstate; |
1417 | while (fgets(inbuf, MAX_BUF-3, fp)) { |
1145 | while (fgets(inbuf, MAX_BUF-3, fp)) { |
1418 | yybufstate=yy_scan_string(inbuf); |
1146 | yybufstate=yy_scan_string(inbuf); |
1419 | retval=lex_load(op, map_flags); |
1147 | retval=lex_load(op, fp, map_flags); |
1420 | yy_delete_buffer(yybufstate); |
1148 | yy_delete_buffer(yybufstate); |
1421 | if (retval==LL_NORMAL) return retval; |
1149 | if (retval==LL_NORMAL) return retval; |
1422 | } |
1150 | } |
1423 | LOG(llevDebug,"Got eof while scanning strings\n"); |
1151 | LOG(llevDebug,"Got eof while scanning strings\n"); |
1424 | return LL_EOF; |
1152 | return LL_EOF; |
1425 | } |
1153 | } |
1426 | |
1154 | |
1427 | retval=lex_load(op, map_flags); |
1155 | retval=lex_load(op, fp, map_flags); |
1428 | if (op->current_weapon_script != NULL) |
|
|
1429 | { |
|
|
1430 | op->current_weapon = find_best_weapon_used_match(op, op->current_weapon_script); |
|
|
1431 | LOG(llevDebug, "CurrentWeapon Loaded !\n"); |
|
|
1432 | }; |
|
|
1433 | |
1156 | |
1434 | /* LOG(llevDebug," load completed, object=%s\n",op->name);*/ |
1157 | /* LOG(llevDebug," load completed, object=%s\n",op->name);*/ |
1435 | return retval; |
1158 | return retval; |
1436 | } |
1159 | } |
1437 | |
1160 | |
… | |
… | |
1443 | * override values and in c_wiz to mutate values. |
1166 | * override values and in c_wiz to mutate values. |
1444 | */ |
1167 | */ |
1445 | int set_variable(object *op,char *buf) { |
1168 | int set_variable(object *op,char *buf) { |
1446 | YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; |
1169 | YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; |
1447 | int retval; |
1170 | int retval; |
|
|
1171 | object_thawer thawer (0); |
1448 | |
1172 | |
1449 | strcpy(msgbuf, ""); |
1173 | strcpy(msgbuf, ""); |
1450 | strcpy(lorebuf, ""); |
1174 | strcpy(lorebuf, ""); |
1451 | yy_push_state(INITIAL); |
1175 | yy_push_state(INITIAL); |
1452 | yybufstate=yy_scan_string(buf); |
1176 | yybufstate=yy_scan_string(buf); |
1453 | retval=lex_load(op,0); |
1177 | retval=lex_load(op,thawer,0); |
1454 | yy_switch_to_buffer(yycurbuf); |
1178 | yy_switch_to_buffer(yycurbuf); |
1455 | yy_delete_buffer(yybufstate); |
1179 | yy_delete_buffer(yybufstate); |
1456 | yy_pop_state(); |
1180 | yy_pop_state(); |
1457 | return retval; |
1181 | return retval; |
1458 | } |
1182 | } |
… | |
… | |
1513 | /*For get_ob_diff speed reason*/ |
1237 | /*For get_ob_diff speed reason*/ |
1514 | typedef struct { |
1238 | typedef struct { |
1515 | const char *name; |
1239 | const char *name; |
1516 | int length; |
1240 | int length; |
1517 | }genericname; |
1241 | }genericname; |
1518 | static genericname evtnames[13]= |
|
|
1519 | { |
|
|
1520 | {"event_none ",11}, |
|
|
1521 | {"event_apply ",12}, |
|
|
1522 | {"event_attack ",13}, |
|
|
1523 | {"event_death ",12}, |
|
|
1524 | {"event_drop ",11}, |
|
|
1525 | {"event_pickup ",13}, |
|
|
1526 | {"event_say ",10}, |
|
|
1527 | {"event_stop ",11}, |
|
|
1528 | {"event_time ",11}, |
|
|
1529 | {"event_throw ",12}, |
|
|
1530 | {"event_trigger ",14}, |
|
|
1531 | {"event_close ",12}, |
|
|
1532 | {"event_timer ",12} |
|
|
1533 | } ; |
|
|
1534 | |
|
|
1535 | static genericname plgnames[13]= |
|
|
1536 | { |
|
|
1537 | {"event_none_plugin ",18}, |
|
|
1538 | {"event_apply_plugin ",19}, |
|
|
1539 | {"event_attack_plugin ",20}, |
|
|
1540 | {"event_death_plugin ",19}, |
|
|
1541 | {"event_drop_plugin ",18}, |
|
|
1542 | {"event_pickup_plugin ",20}, |
|
|
1543 | {"event_say_plugin ",17}, |
|
|
1544 | {"event_stop_plugin ",18}, |
|
|
1545 | {"event_time_plugin ",18}, |
|
|
1546 | {"event_throw_plugin ",19}, |
|
|
1547 | {"event_trigger_plugin ",21}, |
|
|
1548 | {"event_close_plugin ",19}, |
|
|
1549 | {"event_timer_plugin ",19} |
|
|
1550 | }; |
|
|
1551 | |
|
|
1552 | static genericname plgoptions[13]= |
|
|
1553 | { |
|
|
1554 | {"event_none_options ",19}, |
|
|
1555 | {"event_apply_options ",20}, |
|
|
1556 | {"event_attack_options ",21}, |
|
|
1557 | {"event_death_options ",20}, |
|
|
1558 | {"event_drop_options ",19}, |
|
|
1559 | {"event_pickup_options ",21}, |
|
|
1560 | {"event_say_options ",18}, |
|
|
1561 | {"event_stop_options ",19}, |
|
|
1562 | {"event_time_options ",19}, |
|
|
1563 | {"event_throw_options ",20}, |
|
|
1564 | {"event_trigger_options ",22}, |
|
|
1565 | {"event_close_options ",20}, |
|
|
1566 | {"event_timer_options ",20} |
|
|
1567 | }; |
|
|
1568 | |
1242 | |
1569 | /* This returns a string of the integer movement type */ |
1243 | /* This returns a string of the integer movement type */ |
1570 | static char* get_string_move_type(MoveType mt) |
1244 | static char* get_string_move_type(MoveType mt) |
1571 | { |
1245 | { |
1572 | static char retbuf[MAX_BUF], retbuf_all[MAX_BUF]; |
1246 | static char retbuf[MAX_BUF], retbuf_all[MAX_BUF]; |
… | |
… | |
1727 | op->other_arch->name) { |
1401 | op->other_arch->name) { |
1728 | ADD_STRINGLINE_ENTRY(fastbuf,"other_arch ",op->other_arch->name,11); |
1402 | ADD_STRINGLINE_ENTRY(fastbuf,"other_arch ",op->other_arch->name,11); |
1729 | } |
1403 | } |
1730 | if(op->face!=op2->face) { |
1404 | if(op->face!=op2->face) { |
1731 | ADD_STRINGLINE_ENTRY(fastbuf,"face ",op->face->name,5); |
1405 | ADD_STRINGLINE_ENTRY(fastbuf,"face ",op->face->name,5); |
1732 | } |
|
|
1733 | |
|
|
1734 | for(etmp=op->events;etmp!=NULL;etmp=etmp->next) |
|
|
1735 | { |
|
|
1736 | /* First we find the event for the reference object */ |
|
|
1737 | etmp2=find_event(op2,etmp->type); |
|
|
1738 | if ((etmp->hook != NULL) && ((etmp2 == NULL) || (etmp2->hook == NULL) || (strcmp(etmp2->hook,etmp->hook)))) |
|
|
1739 | /* Either there's no matching event in the reference object, |
|
|
1740 | * or the hook is different */ |
|
|
1741 | { |
|
|
1742 | ADD_STRINGLINE_ENTRY(fastbuf,evtnames[etmp->type].name,etmp->hook,evtnames[etmp->type].length); |
|
|
1743 | } |
|
|
1744 | if ((etmp->plugin != NULL) && ((etmp2 == NULL) || (etmp2->plugin == NULL) || (strcmp(etmp2->plugin,etmp->plugin)))) |
|
|
1745 | { |
|
|
1746 | |
|
|
1747 | ADD_STRINGLINE_ENTRY(fastbuf,plgnames[etmp->type].name,etmp->plugin,plgnames[etmp->type].length); |
|
|
1748 | } |
|
|
1749 | if ((etmp->options != NULL) && ((etmp2 == NULL) || (etmp2->options == NULL) || (strcmp(etmp2->options,etmp->options)))) |
|
|
1750 | { |
|
|
1751 | ADD_STRINGLINE_ENTRY(fastbuf,plgoptions[etmp->type].name,etmp->options,plgoptions[etmp->type].length); |
|
|
1752 | } |
|
|
1753 | |
|
|
1754 | } |
1406 | } |
1755 | |
1407 | |
1756 | if (op->animation_id != op2->animation_id) { |
1408 | if (op->animation_id != op2->animation_id) { |
1757 | if (op->animation_id) { |
1409 | if (op->animation_id) { |
1758 | ADD_STRINGLINE_ENTRY(fastbuf,"animation ",animations[GET_ANIM_ID(op)].name,10); |
1410 | ADD_STRINGLINE_ENTRY(fastbuf,"animation ",animations[GET_ANIM_ID(op)].name,10); |
… | |
… | |
1909 | if (op->will_apply!=op2->will_apply) |
1561 | if (op->will_apply!=op2->will_apply) |
1910 | FAST_SAVE_LONG(fastbuf,"will_apply ",op->will_apply,11); |
1562 | FAST_SAVE_LONG(fastbuf,"will_apply ",op->will_apply,11); |
1911 | if(op->smoothlevel!=op2->smoothlevel) |
1563 | if(op->smoothlevel!=op2->smoothlevel) |
1912 | FAST_SAVE_LONG(fastbuf,"smoothlevel ",op->smoothlevel,12); |
1564 | FAST_SAVE_LONG(fastbuf,"smoothlevel ",op->smoothlevel,12); |
1913 | |
1565 | |
1914 | if (op->current_weapon_script!=op2->current_weapon_script){ |
|
|
1915 | ADD_STRINGLINE_ENTRY(fastbuf,"current_weapon_script ",op->current_weapon_script,22); |
|
|
1916 | }; |
|
|
1917 | |
|
|
1918 | if(op->weapontype && op->weapontype!=op2->weapontype) { |
1566 | if(op->weapontype && op->weapontype!=op2->weapontype) { |
1919 | FAST_SAVE_LONG(fastbuf,"weapontype ",op->weapontype,11); |
1567 | FAST_SAVE_LONG(fastbuf,"weapontype ",op->weapontype,11); |
1920 | } |
1568 | } |
1921 | if(op->tooltype && op->tooltype!=op2->tooltype) { |
1569 | if(op->tooltype && op->tooltype!=op2->tooltype) { |
1922 | FAST_SAVE_LONG(fastbuf,"tooltype ",op->tooltype,9); |
1570 | FAST_SAVE_LONG(fastbuf,"tooltype ",op->tooltype,9); |
… | |
… | |
1992 | get_string_move_type(op->move_slow), |
1640 | get_string_move_type(op->move_slow), |
1993 | 10); |
1641 | 10); |
1994 | } |
1642 | } |
1995 | |
1643 | |
1996 | if (op->move_slow_penalty != op2->move_slow_penalty) { |
1644 | if (op->move_slow_penalty != op2->move_slow_penalty) { |
1997 | FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",op->move_slow_penalty,18); |
1645 | FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",(long) op->move_slow_penalty,18); |
1998 | } |
1646 | } |
1999 | |
1647 | |
2000 | if (!COMPARE_FLAGS(op,op2)) { |
1648 | if (!COMPARE_FLAGS(op,op2)) { |
2001 | for (tmp=0; tmp <= NUM_FLAGS; tmp++) { |
1649 | for (tmp=0; tmp <= NUM_FLAGS; tmp++) { |
2002 | if (flag_names[tmp] && (QUERY_FLAG(op, tmp) != QUERY_FLAG(op2, tmp))) { |
1650 | if (flag_names[tmp] && (QUERY_FLAG(op, tmp) != QUERY_FLAG(op2, tmp))) { |
… | |
… | |
2025 | * the only place this is not set is when saving the player. |
1673 | * the only place this is not set is when saving the player. |
2026 | * If bit 1 of flag is set, don't remove the object after save. As of now, |
1674 | * If bit 1 of flag is set, don't remove the object after save. As of now, |
2027 | * all of the callers are setting this. |
1675 | * all of the callers are setting this. |
2028 | */ |
1676 | */ |
2029 | |
1677 | |
2030 | void save_object(FILE *fp,object *op, int flag) { |
1678 | void save_object(object_freezer &fp,object *op, int flag) { |
2031 | archetype *at; |
1679 | archetype *at; |
2032 | char *cp; |
1680 | char *cp; |
2033 | object *tmp,*old; |
1681 | object *tmp,*old; |
2034 | |
1682 | |
2035 | /* Even if the object does have an owner, it would seem that we should |
1683 | /* Even if the object does have an owner, it would seem that we should |
2036 | * still save it. |
1684 | * still save it. |
2037 | */ |
1685 | */ |
2038 | if(op->owner!=NULL || fp == NULL) |
1686 | if(op->owner!=NULL) |
2039 | return; |
1687 | return; |
2040 | |
1688 | |
2041 | /* If it is unpaid and we don't want to save those, just return. */ |
1689 | /* If it is unpaid and we don't want to save those, just return. */ |
2042 | if(!(flag&1)&&(QUERY_FLAG(op, FLAG_UNPAID))) { |
1690 | if(!(flag&1)&&(QUERY_FLAG(op, FLAG_UNPAID))) { |
2043 | return; |
1691 | return; |
… | |
… | |
2074 | if (!(flag&2)) { |
1722 | if (!(flag&2)) { |
2075 | remove_ob(op); |
1723 | remove_ob(op); |
2076 | free_object (op); |
1724 | free_object (op); |
2077 | } |
1725 | } |
2078 | |
1726 | |
|
|
1727 | fp.put (op); |
2079 | fprintf(fp,"end\n"); |
1728 | fprintf(fp,"end\n"); |
2080 | } |
|
|
2081 | |
|
|
2082 | void insert_event(object* op, int etype, char *ehook, char *eplug, char *eoptions) |
|
|
2083 | { |
|
|
2084 | event *evt; |
|
|
2085 | event *tmp; |
|
|
2086 | |
|
|
2087 | evt = find_event(op,etype); |
|
|
2088 | if (evt == NULL) |
|
|
2089 | { |
|
|
2090 | evt = (event *)malloc(sizeof(event)); |
|
|
2091 | evt->next = NULL; |
|
|
2092 | evt->type = etype; |
|
|
2093 | evt->hook = NULL; |
|
|
2094 | evt->plugin = NULL; |
|
|
2095 | evt->options = NULL; |
|
|
2096 | if (op->events==NULL) |
|
|
2097 | { |
|
|
2098 | op->events=evt; |
|
|
2099 | } |
|
|
2100 | else |
|
|
2101 | { |
|
|
2102 | for(tmp=op->events;;tmp=tmp->next) |
|
|
2103 | { |
|
|
2104 | if (tmp->next == NULL) |
|
|
2105 | { |
|
|
2106 | tmp->next = evt; |
|
|
2107 | break; |
|
|
2108 | } |
|
|
2109 | } |
|
|
2110 | } |
|
|
2111 | } |
|
|
2112 | if (ehook != NULL) |
|
|
2113 | FREE_AND_COPY(evt->hook,ehook); |
|
|
2114 | if (eplug != NULL) |
|
|
2115 | FREE_AND_COPY(evt->plugin,eplug); |
|
|
2116 | if (eoptions != NULL) |
|
|
2117 | FREE_AND_COPY(evt->options,eoptions); |
|
|
2118 | } |
1729 | } |
2119 | |
1730 | |
2120 | event* find_event(object* op, int etype) |
1731 | event* find_event(object* op, int etype) |
2121 | { |
1732 | { |
2122 | event *found; |
1733 | event *found; |