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

Comparing deliantra/server/common/loader.l (file contents):
Revision 1.9 by root, Sat Aug 26 23:36:29 2006 UTC vs.
Revision 1.16 by root, Thu Aug 31 06:23:19 2006 UTC

1%{ 1%{
2/* 2/*
3 * static char *rcsid_object_c = 3 * static char *rcsid_object_c =
4 * "$Id: loader.l,v 1.9 2006/08/26 23:36:29 root Exp $"; 4 * "$Id: loader.l,v 1.16 2006/08/31 06:23:19 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
42static char *yval(); 42static char *yval();
43 43
44static int lex_error; 44static int lex_error;
45static char msgbuf[65536]; 45static char msgbuf[65536];
727 /* record the name of the broken object */ 727 /* record the name of the broken object */
728 tmp->name = add_string(yv); 728 tmp->name = add_string(yv);
729 } 729 }
730 strcpy(msgbuf, ""); 730 strcpy(msgbuf, "");
731 strcpy(lorebuf, ""); 731 strcpy(lorebuf, "");
732 lex_load(tmp, map_flags); 732 lex_load(tmp, thawer, map_flags);
733 if (tmp->arch) { 733 if (tmp->arch) {
734 insert_ob_in_ob(tmp,op); 734 insert_ob_in_ob(tmp,op);
735 } 735 }
736 else { 736 else {
737 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)");
743 char *yv=yval(); 743 char *yv=yval();
744 744
745 op->arch=find_archetype(yv); 745 op->arch=find_archetype(yv);
746 if (op->arch!=NULL) { 746 if (op->arch!=NULL) {
747 copy_object(&op->arch->clone,op); 747 copy_object(&op->arch->clone,op);
748 op->instantiate ();
749 } else if (!arch_init) { 748 } else if (!arch_init) {
750 if (op->name) free_string(op->name); 749 if (op->name) free_string(op->name);
751 /* record the name of the broken object */ 750 /* record the name of the broken object */
752 op->name = add_string(yv); 751 op->name = add_string(yv);
753 } 752 }
768^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,
769 * so the calling function can glue things back together 768 * so the calling function can glue things back together
770 */ 769 */
771 ismore=1; 770 ismore=1;
772 } 771 }
773
774^end{WS}$ { check_loaded_object(op); 772^end{WS}$ { check_loaded_object(op);
773
774 if (!arch_init)
775 op->instantiate ();
776
775 if (ismore) return LL_MORE; 777 if (ismore) return LL_MORE;
776 else return LL_NORMAL; 778 else return LL_NORMAL;
777 } 779 }
780^oid{S} {
781 thawer.get (op, IVAL);
782 }
778^last_heal{S} op->last_heal = IVAL; 783^last_heal{S} op->last_heal = IVAL;
779^last_sp{S} op->last_sp = IVAL; 784^last_sp{S} op->last_sp = IVAL;
780^last_grace{S} op->last_grace = IVAL; 785^last_grace{S} op->last_grace = IVAL;
781^last_eat{S} op->last_eat = IVAL; 786^last_eat{S} op->last_eat = IVAL;
782^speed{S} { op->speed = FVAL; 787^speed{S} { op->speed = FVAL;
1051^range_modifier{S} op->range_modifier = IVAL; 1056^range_modifier{S} op->range_modifier = IVAL;
1052^dam_modifier{S} op->dam_modifier = IVAL; 1057^dam_modifier{S} op->dam_modifier = IVAL;
1053^duration_modifier{S} op->duration_modifier = IVAL; 1058^duration_modifier{S} op->duration_modifier = IVAL;
1054^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 );
1055 1060
1056^event_apply{S} { 1061^event_ {
1057 char *yv=yval(); 1062 LOG (llevError, "stray event_* in map file, skipping.");
1058 if (*yv=='\0')
1059 LOG(llevError,"Event (apply) without val\n");
1060 else
1061 insert_event(op,EVENT_APPLY,yv,NULL,NULL);
1062} 1063}
1063
1064^event_apply_plugin{S} {
1065 char *yv=yval();
1066 if (*yv=='\0')
1067 LOG(llevError,"Event (apply) without plugin\n");
1068 else
1069 insert_event(op,EVENT_APPLY,NULL,yv,NULL);
1070}
1071
1072^event_apply_options{S} {
1073 char *yv=yval();
1074 if (*yv=='\0')
1075 LOG(llevError,"Event (apply) without options\n");
1076 else
1077 insert_event(op,EVENT_APPLY,NULL,NULL,yv);
1078}
1079
1080^event_attack{S} {
1081 char *yv=yval();
1082 if (*yv=='\0')
1083 LOG(llevError,"Event (attack) without val\n");
1084 else
1085 insert_event(op,EVENT_ATTACK,yv,NULL,NULL);
1086}
1087
1088^event_attack_plugin{S} {
1089 char *yv=yval();
1090 if (*yv=='\0')
1091 LOG(llevError,"Event (attack) without plugin\n");
1092 else
1093 insert_event(op,EVENT_ATTACK,NULL,yv,NULL);
1094}
1095
1096^event_attack_options{S} {
1097 char *yv=yval();
1098 if (*yv=='\0')
1099 LOG(llevError,"Event (attack) without options\n");
1100 else
1101 insert_event(op,EVENT_ATTACK,NULL,NULL,yv);
1102}
1103^event_death{S} {
1104 char *yv=yval();
1105 if (*yv=='\0')
1106 LOG(llevError,"Event (death) without val\n");
1107 else
1108 insert_event(op,EVENT_DEATH,yv,NULL,NULL);
1109}
1110
1111^event_death_plugin{S} {
1112 char *yv=yval();
1113 if (*yv=='\0')
1114 LOG(llevError,"Event (death) without plugin\n");
1115 else
1116 insert_event(op,EVENT_DEATH,NULL,yv,NULL);
1117}
1118
1119^event_death_options{S} {
1120 char *yv=yval();
1121 if (*yv=='\0')
1122 LOG(llevError,"Event (death) without options\n");
1123 else
1124 insert_event(op,EVENT_DEATH,NULL,NULL,yv);
1125}
1126^event_drop{S} {
1127 char *yv=yval();
1128 if (*yv=='\0')
1129 LOG(llevError,"Event (drop) without val\n");
1130 else
1131 insert_event(op,EVENT_DROP,yv,NULL,NULL);
1132}
1133
1134^event_drop_plugin{S} {
1135 char *yv=yval();
1136 if (*yv=='\0')
1137 LOG(llevError,"Event (drop) without plugin\n");
1138 else
1139 insert_event(op,EVENT_DROP,NULL,yv,NULL);
1140}
1141
1142^event_drop_options{S} {
1143 char *yv=yval();
1144 if (*yv=='\0')
1145 LOG(llevError,"Event (drop) without options\n");
1146 else
1147 insert_event(op,EVENT_DROP,NULL,NULL,yv);
1148}
1149^event_pickup{S} {
1150 char *yv=yval();
1151 if (*yv=='\0')
1152 LOG(llevError,"Event (pickup) without val\n");
1153 else
1154 insert_event(op,EVENT_PICKUP,yv,NULL,NULL);
1155}
1156
1157^event_pickup_plugin{S} {
1158 char *yv=yval();
1159 if (*yv=='\0')
1160 LOG(llevError,"Event (pickup) without plugin\n");
1161 else
1162 insert_event(op,EVENT_PICKUP,NULL,yv,NULL);
1163}
1164
1165^event_pickup_options{S} {
1166 char *yv=yval();
1167 if (*yv=='\0')
1168 LOG(llevError,"Event (pickup) without options\n");
1169 else
1170 insert_event(op,EVENT_PICKUP,NULL,NULL,yv);
1171}
1172^event_say{S} {
1173 char *yv=yval();
1174 if (*yv=='\0')
1175 LOG(llevError,"Event (say) without val\n");
1176 else
1177 insert_event(op,EVENT_SAY,yv,NULL,NULL);
1178}
1179
1180^event_say_plugin{S} {
1181 char *yv=yval();
1182 if (*yv=='\0')
1183 LOG(llevError,"Event (say) without plugin\n");
1184 else
1185 insert_event(op,EVENT_SAY,NULL,yv,NULL);
1186}
1187
1188^event_say_options{S} {
1189 char *yv=yval();
1190 if (*yv=='\0')
1191 LOG(llevError,"Event (say) without options\n");
1192 else
1193 insert_event(op,EVENT_SAY,NULL,NULL,yv);
1194}
1195^event_stop{S} {
1196 char *yv=yval();
1197 if (*yv=='\0')
1198 LOG(llevError,"Event (stop) without val\n");
1199 else
1200 insert_event(op,EVENT_STOP,yv,NULL,NULL);
1201}
1202
1203^event_stop_plugin{S} {
1204 char *yv=yval();
1205 if (*yv=='\0')
1206 LOG(llevError,"Event (stop) without plugin\n");
1207 else
1208 insert_event(op,EVENT_STOP,NULL,yv,NULL);
1209}
1210
1211^event_stop_options{S} {
1212 char *yv=yval();
1213 if (*yv=='\0')
1214 LOG(llevError,"Event (stop) without options\n");
1215 else
1216 insert_event(op,EVENT_STOP,NULL,NULL,yv);
1217}
1218^event_time{S} {
1219 char *yv=yval();
1220 if (*yv=='\0')
1221 LOG(llevError,"Event (time) without val\n");
1222 else
1223 insert_event(op,EVENT_TIME,yv,NULL,NULL);
1224}
1225
1226^event_time_plugin{S} {
1227 char *yv=yval();
1228 if (*yv=='\0')
1229 LOG(llevError,"Event (time) without plugin\n");
1230 else
1231 insert_event(op,EVENT_TIME,NULL,yv,NULL);
1232}
1233
1234^event_time_options{S} {
1235 char *yv=yval();
1236 if (*yv=='\0')
1237 LOG(llevError,"Event (time) without options\n");
1238 else
1239 insert_event(op,EVENT_TIME,NULL,NULL,yv);
1240}
1241^event_throw{S} {
1242 char *yv=yval();
1243 if (*yv=='\0')
1244 LOG(llevError,"Event (throw) without val\n");
1245 else
1246 insert_event(op,EVENT_THROW,yv,NULL,NULL);
1247}
1248
1249^event_throw_plugin{S} {
1250 char *yv=yval();
1251 if (*yv=='\0')
1252 LOG(llevError,"Event (throw) without plugin\n");
1253 else
1254 insert_event(op,EVENT_THROW,NULL,yv,NULL);
1255}
1256
1257^event_throw_options{S} {
1258 char *yv=yval();
1259 if (*yv=='\0')
1260 LOG(llevError,"Event (apply) without options\n");
1261 else
1262 insert_event(op,EVENT_THROW,NULL,NULL,yv);
1263}
1264^event_trigger{S} {
1265 char *yv=yval();
1266 if (*yv=='\0')
1267 LOG(llevError,"Event (trigger) without val\n");
1268 else
1269 insert_event(op,EVENT_TRIGGER,yv,NULL,NULL);
1270}
1271
1272^event_trigger_plugin{S} {
1273 char *yv=yval();
1274 if (*yv=='\0')
1275 LOG(llevError,"Event (trigger) without plugin\n");
1276 else
1277 insert_event(op,EVENT_TRIGGER,NULL,yv,NULL);
1278}
1279
1280^event_trigger_options{S} {
1281 char *yv=yval();
1282 if (*yv=='\0')
1283 LOG(llevError,"Event (trigger) without options\n");
1284 else
1285 insert_event(op,EVENT_TRIGGER,NULL,NULL,yv);
1286}
1287^event_close{S} {
1288 char *yv=yval();
1289 if (*yv=='\0')
1290 LOG(llevError,"Event (close) without val\n");
1291 else
1292 insert_event(op,EVENT_CLOSE,yv,NULL,NULL);
1293}
1294
1295^event_close_plugin{S} {
1296 char *yv=yval();
1297 if (*yv=='\0')
1298 LOG(llevError,"Event (close) without plugin\n");
1299 else
1300 insert_event(op,EVENT_CLOSE,NULL,yv,NULL);
1301}
1302
1303^event_close_options{S} {
1304 char *yv=yval();
1305 if (*yv=='\0')
1306 LOG(llevError,"Event (close) without options\n");
1307 else
1308 insert_event(op,EVENT_CLOSE,NULL,NULL,yv);
1309}
1310^event_timer{S} {
1311 char *yv=yval();
1312 if (*yv=='\0')
1313 LOG(llevError,"Event (timer) without val\n");
1314 else
1315 insert_event(op,EVENT_TIMER,yv,NULL,NULL);
1316}
1317
1318^event_timer_plugin{S} {
1319 char *yv=yval();
1320 if (*yv=='\0')
1321 LOG(llevError,"Event (timer) without plugin\n");
1322 else
1323 insert_event(op,EVENT_TIMER,NULL,yv,NULL);
1324}
1325
1326^event_timer_options{S} {
1327 char *yv=yval();
1328 if (*yv=='\0')
1329 LOG(llevError,"Event (timer) without options\n");
1330 else
1331 insert_event(op,EVENT_TIMER,NULL,NULL,yv);
1332}
1333
1334^current_weapon_script{S} { char *yv=yval();
1335
1336 if (*yv=='\0') LOG(llevError,"Script (current weapon) without val\n");
1337 else
1338 {
1339 FREE_AND_COPY(op->current_weapon_script, yv);
1340 };
1341 }
1342 1064
1343<*>(^{WS}$)|\n {/* ignore empty lines, newlines we don't do above */} 1065<*>(^{WS}$)|\n {/* ignore empty lines, newlines we don't do above */}
1344#.*\n {} 1066#.*\n {}
1345 1067
1346<<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 */
1404 * be reset. 1126 * be reset.
1405 * 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)
1406 * 1128 *
1407 */ 1129 */
1408 1130
1409int load_object(FILE *fp, object *op, int bufstate, int map_flags) { 1131int load_object(object_thawer &fp, object *op, int bufstate, int map_flags) {
1410 int retval; 1132 int retval;
1411 char inbuf[MAX_BUF]; 1133 char inbuf[MAX_BUF];
1412 1134
1413 strcpy(msgbuf, ""); 1135 strcpy(msgbuf, "");
1414 strcpy(lorebuf, ""); 1136 strcpy(lorebuf, "");
1420 } 1142 }
1421 if (bufstate==LO_LINEMODE) { 1143 if (bufstate==LO_LINEMODE) {
1422 YY_BUFFER_STATE yybufstate; 1144 YY_BUFFER_STATE yybufstate;
1423 while (fgets(inbuf, MAX_BUF-3, fp)) { 1145 while (fgets(inbuf, MAX_BUF-3, fp)) {
1424 yybufstate=yy_scan_string(inbuf); 1146 yybufstate=yy_scan_string(inbuf);
1425 retval=lex_load(op, map_flags); 1147 retval=lex_load(op, fp, map_flags);
1426 yy_delete_buffer(yybufstate); 1148 yy_delete_buffer(yybufstate);
1427 if (retval==LL_NORMAL) return retval; 1149 if (retval==LL_NORMAL) return retval;
1428 } 1150 }
1429 LOG(llevDebug,"Got eof while scanning strings\n"); 1151 LOG(llevDebug,"Got eof while scanning strings\n");
1430 return LL_EOF; 1152 return LL_EOF;
1431 } 1153 }
1432 1154
1433 retval=lex_load(op, map_flags); 1155 retval=lex_load(op, fp, map_flags);
1434 if (op->current_weapon_script != NULL)
1435 {
1436 op->current_weapon = find_best_weapon_used_match(op, op->current_weapon_script);
1437 LOG(llevDebug, "CurrentWeapon Loaded !\n");
1438 };
1439 1156
1440/* LOG(llevDebug," load completed, object=%s\n",op->name);*/ 1157/* LOG(llevDebug," load completed, object=%s\n",op->name);*/
1441 return retval; 1158 return retval;
1442} 1159}
1443 1160
1449 * override values and in c_wiz to mutate values. 1166 * override values and in c_wiz to mutate values.
1450 */ 1167 */
1451int set_variable(object *op,char *buf) { 1168int set_variable(object *op,char *buf) {
1452 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; 1169 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER;
1453 int retval; 1170 int retval;
1171 object_thawer thawer (0);
1454 1172
1455 strcpy(msgbuf, ""); 1173 strcpy(msgbuf, "");
1456 strcpy(lorebuf, ""); 1174 strcpy(lorebuf, "");
1457 yy_push_state(INITIAL); 1175 yy_push_state(INITIAL);
1458 yybufstate=yy_scan_string(buf); 1176 yybufstate=yy_scan_string(buf);
1459 retval=lex_load(op,0); 1177 retval=lex_load(op,thawer,0);
1460 yy_switch_to_buffer(yycurbuf); 1178 yy_switch_to_buffer(yycurbuf);
1461 yy_delete_buffer(yybufstate); 1179 yy_delete_buffer(yybufstate);
1462 yy_pop_state(); 1180 yy_pop_state();
1463 return retval; 1181 return retval;
1464} 1182}
1915 if (op->will_apply!=op2->will_apply) 1633 if (op->will_apply!=op2->will_apply)
1916 FAST_SAVE_LONG(fastbuf,"will_apply ",op->will_apply,11); 1634 FAST_SAVE_LONG(fastbuf,"will_apply ",op->will_apply,11);
1917 if(op->smoothlevel!=op2->smoothlevel) 1635 if(op->smoothlevel!=op2->smoothlevel)
1918 FAST_SAVE_LONG(fastbuf,"smoothlevel ",op->smoothlevel,12); 1636 FAST_SAVE_LONG(fastbuf,"smoothlevel ",op->smoothlevel,12);
1919 1637
1920 if (op->current_weapon_script!=op2->current_weapon_script){
1921 ADD_STRINGLINE_ENTRY(fastbuf,"current_weapon_script ",op->current_weapon_script,22);
1922 };
1923
1924 if(op->weapontype && op->weapontype!=op2->weapontype) { 1638 if(op->weapontype && op->weapontype!=op2->weapontype) {
1925 FAST_SAVE_LONG(fastbuf,"weapontype ",op->weapontype,11); 1639 FAST_SAVE_LONG(fastbuf,"weapontype ",op->weapontype,11);
1926 } 1640 }
1927 if(op->tooltype && op->tooltype!=op2->tooltype) { 1641 if(op->tooltype && op->tooltype!=op2->tooltype) {
1928 FAST_SAVE_LONG(fastbuf,"tooltype ",op->tooltype,9); 1642 FAST_SAVE_LONG(fastbuf,"tooltype ",op->tooltype,9);
2031 * the only place this is not set is when saving the player. 1745 * the only place this is not set is when saving the player.
2032 * If bit 1 of flag is set, don't remove the object after save. As of now, 1746 * If bit 1 of flag is set, don't remove the object after save. As of now,
2033 * all of the callers are setting this. 1747 * all of the callers are setting this.
2034 */ 1748 */
2035 1749
2036void save_object(FILE *fp,object *op, int flag) { 1750void save_object(object_freezer &fp,object *op, int flag) {
2037 archetype *at; 1751 archetype *at;
2038 char *cp; 1752 char *cp;
2039 object *tmp,*old; 1753 object *tmp,*old;
2040 1754
2041 /* Even if the object does have an owner, it would seem that we should 1755 /* Even if the object does have an owner, it would seem that we should
2042 * still save it. 1756 * still save it.
2043 */ 1757 */
2044 if(op->owner!=NULL || fp == NULL) 1758 if(op->owner!=NULL)
2045 return; 1759 return;
2046 1760
2047 /* If it is unpaid and we don't want to save those, just return. */ 1761 /* If it is unpaid and we don't want to save those, just return. */
2048 if(!(flag&1)&&(QUERY_FLAG(op, FLAG_UNPAID))) { 1762 if(!(flag&1)&&(QUERY_FLAG(op, FLAG_UNPAID))) {
2049 return; 1763 return;
2080 if (!(flag&2)) { 1794 if (!(flag&2)) {
2081 remove_ob(op); 1795 remove_ob(op);
2082 free_object (op); 1796 free_object (op);
2083 } 1797 }
2084 1798
1799 fp.put (op);
2085 fprintf(fp,"end\n"); 1800 fprintf(fp,"end\n");
2086} 1801}
2087 1802
2088void insert_event(object* op, int etype, char *ehook, char *eplug, char *eoptions) 1803void insert_event(object* op, int etype, char *ehook, char *eplug, char *eoptions)
2089{ 1804{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines