1 | /* |
1 | /* |
2 | * static char *rcsid_object_c = |
2 | * static char *rcsid_object_c = |
3 | * "$Id: object.C,v 1.8 2006/08/29 08:01:35 root Exp $"; |
3 | * "$Id: object.C,v 1.10 2006/08/31 17:54:14 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
281 | * Some error messages. |
281 | * Some error messages. |
282 | * The result of the dump is stored in the static global errmsg array. |
282 | * The result of the dump is stored in the static global errmsg array. |
283 | */ |
283 | */ |
284 | |
284 | |
285 | void dump_object2(object *op) { |
285 | void dump_object2(object *op) { |
|
|
286 | errmsg[0] = 0; |
|
|
287 | return; |
|
|
288 | //TODO//D#d# |
|
|
289 | #if 0 |
286 | char *cp; |
290 | char *cp; |
287 | /* object *tmp;*/ |
291 | /* object *tmp;*/ |
288 | |
292 | |
289 | if(op->arch!=NULL) { |
293 | if(op->arch!=NULL) { |
290 | strcat(errmsg,"arch "); |
294 | strcat(errmsg,"arch "); |
… | |
… | |
315 | for (tmp=op->inv; tmp; tmp=tmp->below) |
319 | for (tmp=op->inv; tmp; tmp=tmp->below) |
316 | dump_object2(tmp); |
320 | dump_object2(tmp); |
317 | #endif |
321 | #endif |
318 | strcat(errmsg,"end\n"); |
322 | strcat(errmsg,"end\n"); |
319 | } |
323 | } |
|
|
324 | #endif |
320 | } |
325 | } |
321 | |
326 | |
322 | /* |
327 | /* |
323 | * Dumps an object. Returns output in the static global errmsg array. |
328 | * Dumps an object. Returns output in the static global errmsg array. |
324 | */ |
329 | */ |
… | |
… | |
329 | return; |
334 | return; |
330 | } |
335 | } |
331 | errmsg[0]='\0'; |
336 | errmsg[0]='\0'; |
332 | dump_object2(op); |
337 | dump_object2(op); |
333 | } |
338 | } |
334 | |
|
|
335 | /* GROS - Dumps an object. Return the result into a string */ |
|
|
336 | /* Note that no checking is done for the validity of the target string, so */ |
|
|
337 | /* you need to be sure that you allocated enough space for it. */ |
|
|
338 | void dump_me(object *op, char *outstr) |
|
|
339 | { |
|
|
340 | char *cp; |
|
|
341 | |
|
|
342 | if(op==NULL) |
|
|
343 | { |
|
|
344 | strcpy(outstr,"[NULL pointer]"); |
|
|
345 | return; |
|
|
346 | } |
|
|
347 | outstr[0]='\0'; |
|
|
348 | |
|
|
349 | if(op->arch!=NULL) |
|
|
350 | { |
|
|
351 | strcat(outstr,"arch "); |
|
|
352 | strcat(outstr,op->arch->name?op->arch->name:"(null)"); |
|
|
353 | strcat(outstr,"\n"); |
|
|
354 | if((cp=get_ob_diff(op,&empty_archetype->clone))!=NULL) |
|
|
355 | strcat(outstr,cp); |
|
|
356 | strcat(outstr,"end\n"); |
|
|
357 | } |
|
|
358 | else |
|
|
359 | { |
|
|
360 | strcat(outstr,"Object "); |
|
|
361 | if (op->name==NULL) |
|
|
362 | strcat(outstr, "(null)"); |
|
|
363 | else |
|
|
364 | strcat(outstr,op->name); |
|
|
365 | strcat(outstr,"\n"); |
|
|
366 | strcat(outstr,"end\n"); |
|
|
367 | } |
|
|
368 | } |
|
|
369 | |
|
|
370 | /* |
|
|
371 | * This is really verbose...Can be triggered by the P key while in DM mode. |
|
|
372 | * All objects are dumped to stderr (or alternate logfile, if in server-mode) |
|
|
373 | */ |
|
|
374 | |
339 | |
375 | void dump_all_objects(void) { |
340 | void dump_all_objects(void) { |
376 | object *op; |
341 | object *op; |
377 | for(op=objects;op!=NULL;op=op->next) { |
342 | for(op=objects;op!=NULL;op=op->next) { |
378 | dump_object(op); |
343 | dump_object(op); |
… | |
… | |
2618 | /* Also remember that multiparts objects are not supported for now. */ |
2583 | /* Also remember that multiparts objects are not supported for now. */ |
2619 | |
2584 | |
2620 | object* load_object_str(const char *obstr) |
2585 | object* load_object_str(const char *obstr) |
2621 | { |
2586 | { |
2622 | object *op; |
2587 | object *op; |
2623 | FILE *tempfile; |
|
|
2624 | char filename[MAX_BUF]; |
2588 | char filename[MAX_BUF]; |
2625 | sprintf(filename,"%s/cfloadobstr2044",settings.tmpdir); |
2589 | sprintf(filename,"%s/cfloadobstr2044",settings.tmpdir); |
|
|
2590 | |
2626 | tempfile=fopen(filename,"w"); |
2591 | FILE *tempfile=fopen(filename,"w"); |
2627 | if (tempfile == NULL) |
2592 | if (tempfile == NULL) |
2628 | { |
2593 | { |
2629 | LOG(llevError,"Error - Unable to access load object temp file\n"); |
2594 | LOG(llevError,"Error - Unable to access load object temp file\n"); |
2630 | return NULL; |
2595 | return NULL; |
2631 | }; |
2596 | }; |
2632 | fprintf(tempfile,obstr); |
2597 | fprintf(tempfile,obstr); |
2633 | fclose(tempfile); |
2598 | fclose(tempfile); |
2634 | |
2599 | |
2635 | op=get_object(); |
2600 | op=get_object(); |
2636 | |
2601 | |
2637 | tempfile=fopen(filename,"r"); |
|
|
2638 | if (tempfile == NULL) |
|
|
2639 | { |
|
|
2640 | LOG(llevError,"Error - Unable to read object temp file\n"); |
|
|
2641 | return NULL; |
|
|
2642 | }; |
|
|
2643 | object_thawer thawer (tempfile); |
2602 | object_thawer thawer (filename); |
|
|
2603 | if (thawer) |
2644 | load_object(thawer,op,LO_NEWFILE,0); |
2604 | load_object(thawer,op,LO_NEWFILE,0); |
2645 | LOG(llevDebug," load str completed, object=%s\n",op->name); |
2605 | LOG(llevDebug," load str completed, object=%s\n",op->name); |
2646 | CLEAR_FLAG(op,FLAG_REMOVED); |
2606 | CLEAR_FLAG(op,FLAG_REMOVED); |
2647 | fclose(tempfile); |
2607 | |
2648 | return op; |
2608 | return op; |
2649 | } |
2609 | } |
2650 | |
2610 | |
2651 | /* This returns the first object in who's inventory that |
2611 | /* This returns the first object in who's inventory that |
2652 | * has the same type and subtype match. |
2612 | * has the same type and subtype match. |