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

Comparing deliantra/server/common/arch.C (file contents):
Revision 1.42 by root, Fri Feb 9 01:52:10 2007 UTC vs.
Revision 1.43 by root, Fri Feb 16 19:43:40 2007 UTC

300 * An alternative way to init the hashtable which is slower, but _works_... 300 * An alternative way to init the hashtable which is slower, but _works_...
301 */ 301 */
302void 302void
303init_archetable (void) 303init_archetable (void)
304{ 304{
305 archetype *at;
306
307 LOG (llevDebug, " Setting up archetable...\n"); 305 LOG (llevDebug, " Setting up archetable...\n");
308 306
309 for (at = first_archetype; at; at = at->more ? at->more : at->next) 307 for (archetype *at = first_archetype; at; at = at->next)
308 for (archetype *bt = at; bt; bt = bt->more)
310 at->hash_add (); 309 bt->hash_add ();
311 310
312 LOG (llevDebug, "done\n"); 311 LOG (llevDebug, "done\n");
313} 312}
314 313
315void 314void
334 LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f); 333 LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f);
335} 334}
336 335
337archetype::archetype () 336archetype::archetype ()
338{ 337{
338 clone.arch = this;
339
339 CLEAR_FLAG (&clone, FLAG_FREED); /* This shouldn't matter, since copy_to */ 340 CLEAR_FLAG (&clone, FLAG_FREED); /* This shouldn't matter, since copy_to */
340 SET_FLAG (&clone, FLAG_REMOVED); /* doesn't copy these flags... */ 341 SET_FLAG (&clone, FLAG_REMOVED); /* doesn't copy these flags... */
341} 342}
342 343
343archetype::~archetype () 344archetype::~archetype ()
344{ 345{
346 //TODO: nuke ->more's
347}
348
349archetype *
350archetype::read (object_thawer &f)
351{
352 assert (f.kw == KW_object);
353
354 archetype *head = new archetype;
355 f.get (head->name);
356
357 if (!head->clone.parse_kv (f))
358 {
359 delete head;
360 return 0;
361 }
362
363 for (archetype *prev = head; f.kw == KW_more; )
364 {
365 f.next ();
366
367 assert (f.kw == KW_object);
368
369 archetype *more = new archetype;
370 f.get (more->name);
371
372 if (!more->clone.parse_kv (f))
373 {
374 delete head;
375 return 0;
376 }
377
378 assert (("pippijn sagt es gibt keine tiles mehr", head->clone.face == more->clone.face));
379
380 if (more->clone.x > head->tail_x) head->tail_x = more->clone.x;
381 if (more->clone.y > head->tail_y) head->tail_y = more->clone.y;
382
383 more->head = head;
384 more->clone.head = &head->clone;
385 prev->more = more;
386 prev->clone.more = &more->clone;
387
388 prev = more;
389 }
390
391 head->next = first_archetype;
392 first_archetype = head;
393
394 return head;
345} 395}
346 396
347/* 397/*
348 * Reads/parses the archetype-file, and copies into a linked list 398 * Reads/parses the archetype-file, and copies into a linked list
349 * of archetype-structures. 399 * of archetype-structures.
350 */ 400 */
351void 401static bool
352first_arch_pass (object_thawer & fp) 402first_arch_pass (object_thawer &f)
353{ 403{
354 archetype *head = 0, *last_more = 0; 404 for (;;)
355
356 archetype *at = new archetype;
357 at->clone.arch = first_archetype = at;
358
359 while (int i = load_object (fp, &at->clone, 0))
360 { 405 {
361 at->clone.speed_left = (float) (-0.1);
362 /* copy the body_info to the body_used - this is only really
363 * need for monsters, but doesn't hurt to do it for everything.
364 * by doing so, when a monster is created, it has good starting
365 * values for the body_used info, so when items are created
366 * for it, they can be properly equipped.
367 */
368 memcpy (&at->clone.body_used, &at->clone.body_info, sizeof (at->clone.body_info));
369
370 switch (i) 406 switch (f.kw)
371 {
372 case LL_NORMAL: /* A new archetype, just link it with the previous */
373 if (last_more != NULL)
374 last_more->next = at;
375 if (head != NULL)
376 head->next = at;
377 head = last_more = at;
378#if 0
379 if (!op->type)
380 LOG (llevDebug, " WARNING: Archetype %s has no type info!\n", op->arch->name);
381#endif
382 at->tail_x = 0;
383 at->tail_y = 0;
384 break;
385
386 case LL_MORE: /* Another part of the previous archetype, link it correctly */
387
388 at->head = head;
389 at->clone.head = &head->clone;
390 if (last_more != NULL)
391 {
392 last_more->more = at;
393 last_more->clone.more = &at->clone;
394 }
395 last_more = at;
396
397 /* If this multipart image is still composed of individual small
398 * images, don't set the tail_.. values. We can't use them anyways,
399 * and setting these to zero makes the map sending to the client much
400 * easier as just looking at the head, we know what to do.
401 */
402 if (at->clone.face != head->clone.face)
403 {
404 head->tail_x = 0;
405 head->tail_y = 0;
406 }
407 else
408 {
409 if (at->clone.x > head->tail_x)
410 head->tail_x = at->clone.x;
411 if (at->clone.y > head->tail_y)
412 head->tail_y = at->clone.y;
413 }
414 break;
415
416 } 407 {
408 case KW_object:
409 if (!archetype::read (f))
410 return false;
411 continue;
417 412
418 at = new archetype; 413 case KW_EOF:
414 return true;
419 415
420 at->clone.arch = at; 416 default:
421 } 417 if (!f.parse_error ("archetypes file"))
418 return false;
419 }
422 420
423 delete at; 421 f.next ();
422 }
424} 423}
425 424
426/* 425/*
427 * Reads the archetype file once more, and links all pointers between 426 * Reads the archetype file once more, and links all pointers between
428 * archetypes. 427 * archetypes.
429 */ 428 */
430
431void 429void
432second_arch_pass (object_thawer & thawer) 430second_arch_pass (object_thawer & thawer)
433{ 431{
434 char buf[MAX_BUF], *variable = buf, *argument, *cp; 432 char buf[MAX_BUF], *variable = buf, *argument, *cp;
435 archetype *at = NULL, *other; 433 archetype *at = NULL, *other;
506 504
507 sprintf (filename, "%s/%s", settings.datadir, settings.archetypes); 505 sprintf (filename, "%s/%s", settings.datadir, settings.archetypes);
508 LOG (llevDebug, "Reading archetypes from %s:\n", filename); 506 LOG (llevDebug, "Reading archetypes from %s:\n", filename);
509 507
510 { 508 {
511 object_thawer
512 thawer (filename); 509 object_thawer f (filename);
510
511 f.next ();
513 512
514 LOG (llevDebug, " arch-pass 1...\n"); 513 LOG (llevDebug, " arch-pass 1...\n");
515 first_arch_pass (thawer); 514 if (!first_arch_pass (f))
515 cleanup ("errors during first arch pass are fatal");
516 LOG (llevDebug, " done\n"); 516 LOG (llevDebug, " done\n");
517 } 517 }
518 518
519 init_archetable (); 519 init_archetable ();
520 warn_archetypes = 1; 520 warn_archetypes = 1;
521 521
522 { 522 {
523 object_thawer
524 thawer (filename); 523 object_thawer f (filename);
525 524
526 LOG (llevDebug, " loading treasure...\n"); 525 LOG (llevDebug, " loading treasure...\n");
527 load_treasures (); 526 load_treasures ();
528 LOG (llevDebug, " done\n"); 527 LOG (llevDebug, " done\n");
529 LOG (llevDebug, " arch-pass 2...\n"); 528 LOG (llevDebug, " arch-pass 2...\n");
530 second_arch_pass (thawer); 529 second_arch_pass (f);
531 LOG (llevDebug, " done\n"); 530 LOG (llevDebug, " done\n");
532#ifdef DEBUG 531#ifdef DEBUG
533 check_generators (); 532 check_generators ();
534#endif 533#endif
535 } 534 }
541 * This function returns NULL on failure. 540 * This function returns NULL on failure.
542 */ 541 */
543object * 542object *
544arch_to_object (archetype *at) 543arch_to_object (archetype *at)
545{ 544{
546 object *op; 545 if (!at)
547
548 if (at == NULL)
549 { 546 {
550 if (warn_archetypes) 547 if (warn_archetypes)
551 LOG (llevError, "Couldn't find archetype.\n"); 548 LOG (llevError, "Couldn't find archetype.\n");
552 549
553 return NULL; 550 return NULL;
554 } 551 }
555 552
556 op = at->clone.clone (); 553 object *op = at->clone.clone ();
557 op->arch = at; 554 op->arch = at;
558 op->instantiate (); 555 op->instantiate ();
559 return op; 556 return op;
560} 557}
561 558

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines