1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
9 | * under the terms of the GNU General Public License as published by the Free |
9 | * it under the terms of the GNU General Public License as published by |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, but |
13 | * This program is distributed in the hope that it will be useful, |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License along |
18 | * You should have received a copy of the GNU General Public License |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <cassert> |
24 | #include <cassert> |
… | |
… | |
69 | find_archetype_by_object_name (const char *name) |
68 | find_archetype_by_object_name (const char *name) |
70 | { |
69 | { |
71 | shstr_cmp name_cmp (name); |
70 | shstr_cmp name_cmp (name); |
72 | |
71 | |
73 | for_all_archetypes (at) |
72 | for_all_archetypes (at) |
74 | if (at->archname == name_cmp) |
73 | if (at->name == name_cmp) |
75 | return at; |
74 | return at; |
76 | |
75 | |
77 | return 0; |
76 | return 0; |
78 | } |
77 | } |
79 | |
78 | |
… | |
… | |
86 | find_archetype_by_object_type_name (int type, const char *name) |
85 | find_archetype_by_object_type_name (int type, const char *name) |
87 | { |
86 | { |
88 | shstr_cmp name_cmp (name); |
87 | shstr_cmp name_cmp (name); |
89 | |
88 | |
90 | for_all_archetypes (at) |
89 | for_all_archetypes (at) |
91 | if (at->archname == name_cmp && at->type == type) |
90 | if (at->name == name_cmp && at->type == type) |
92 | return at; |
91 | return at; |
93 | |
92 | |
94 | return 0; |
93 | return 0; |
95 | } |
94 | } |
96 | |
95 | |
… | |
… | |
157 | } |
156 | } |
158 | |
157 | |
159 | return create_singularity (name); |
158 | return create_singularity (name); |
160 | } |
159 | } |
161 | |
160 | |
162 | /* This is a subset of the parse_id command. Basically, name can be |
161 | /* This is a subset of the parse_id command. Basically, name can be |
163 | * a string seperated lists of things to match, with certain keywords. |
162 | * a string seperated lists of things to match, with certain keywords. |
164 | * pl is the player (only needed to set count properly) |
163 | * pl is the player (only needed to set count properly) |
165 | * op is the item we are trying to match. Calling function takes care |
164 | * op is the item we are trying to match. Calling function takes care |
166 | * of what action might need to be done and if it is valid |
165 | * of what action might need to be done and if it is valid |
167 | * (pickup, drop, etc.) Return NONZERO if we have a match. A higher |
166 | * (pickup, drop, etc.) Return NONZERO if we have a match. A higher |
168 | * value means a better match. 0 means no match. |
167 | * value means a better match. 0 means no match. |
169 | * |
168 | * |
170 | * Brief outline of the procedure: |
169 | * Brief outline of the procedure: |
171 | * We take apart the name variable into the individual components. |
170 | * We take apart the name variable into the individual components. |
172 | * cases for 'all' and unpaid are pretty obvious. |
171 | * cases for 'all' and unpaid are pretty obvious. |
173 | * Next, we check for a count (either specified in name, or in the |
172 | * Next, we check for a count (either specified in name, or in the |
174 | * player object.) |
173 | * player object.) |
175 | * If count is 1, make a quick check on the name. |
174 | * If count is 1, make a quick check on the name. |
176 | * IF count is >1, we need to make plural name. Return if match. |
175 | * IF count is >1, we need to make plural name. Return if match. |
177 | * Last, make a check on the full name. |
176 | * Last, make a check on the full name. |
178 | */ |
177 | */ |
179 | int |
178 | int |
180 | item_matched_string (object *pl, object *op, const char *name) |
179 | item_matched_string (object *pl, object *op, const char *name) |
181 | { |
180 | { |
182 | char *cp, local_name[MAX_BUF]; |
181 | char *cp, local_name[MAX_BUF]; |
183 | int count, retval = 0; |
182 | int count, retval = 0; |
… | |
… | |
300 | |
299 | |
301 | void |
300 | void |
302 | archetype::unlink () |
301 | archetype::unlink () |
303 | { |
302 | { |
304 | ht.erase (archname); |
303 | ht.erase (archname); |
305 | |
304 | if (!strcmp (&archname, "Gaea")) fprintf (stderr, "oI\n");//D |
306 | if (archetypes.contains (this)) |
305 | if (archetypes.contains (this)) |
307 | archetypes.erase (this); |
306 | archetypes.erase (this); |
308 | } |
307 | } |
309 | |
308 | |
310 | /* |
309 | /* |
… | |
… | |
334 | name = "(null)"; |
333 | name = "(null)"; |
335 | } |
334 | } |
336 | |
335 | |
337 | archetype *at = find (name); |
336 | archetype *at = find (name); |
338 | |
337 | |
339 | if (loading_arch && at && !at->stub) |
338 | if (!at) |
340 | { |
|
|
341 | at->unlink (); |
|
|
342 | at = 0; |
|
|
343 | } |
|
|
344 | |
|
|
345 | if (!at || (!at->stub && loading_arch)) |
|
|
346 | { |
339 | { |
347 | at = new archetype (name); |
340 | at = new archetype (name); |
348 | at->link (); |
341 | at->link (); |
349 | } |
342 | } |
350 | |
343 | |
… | |
… | |
415 | auto (at, parts.begin ()); |
408 | auto (at, parts.begin ()); |
416 | |
409 | |
417 | archetype *new_head = parts.front (); |
410 | archetype *new_head = parts.front (); |
418 | archetype *old_head = find (new_head->archname); |
411 | archetype *old_head = find (new_head->archname); |
419 | |
412 | |
420 | for (auto (at, parts.begin ()); at != parts.end (); ++at) |
413 | if (old_head && !old_head->is_head ()) |
421 | fprintf (stderr, "%d: %s\n", at - parts.begin(), &(*at)->archname);//D |
414 | { |
|
|
415 | LOG (llevError, "%s: unable to overwrite non-head archetype '%s' with head archetype, skipping.\n", |
|
|
416 | &new_head->archname, &old_head->archname); |
|
|
417 | goto fail; |
|
|
418 | } |
422 | |
419 | |
423 | // check that all archetypes belong to the same old object or are new |
420 | // check that all archetypes belong to the same old object or are new |
424 | for (auto (at, parts.begin ()); at != parts.end (); ++at) |
421 | for (auto (at, parts.begin ()); at != parts.end (); ++at) |
425 | { |
422 | { |
426 | archetype *new_part = *at; |
423 | archetype *new_part = *at; |
427 | archetype *old_part = find (new_part->archname); |
424 | archetype *old_part = find (new_part->archname); |
428 | |
425 | |
429 | if (old_part && old_part->head_ () != old_head) |
426 | if (old_part && old_part->head_ () != old_head) |
430 | { |
427 | { |
431 | fprintf (stderr, "nhn %s\n", &new_head->archname);//D |
|
|
432 | fprintf (stderr, "old_head %p,%p new_head %p,%p ph %p\n", old_head, old_part, new_head, new_part, old_part->head_()); |
|
|
433 | LOG (llevError, "%s: unable to overwrite archetype '%s' with archetype of different object, skipping.\n", |
428 | LOG (llevError, "%s: unable to overwrite archetype '%s' with archetype of different object, skipping.\n", |
434 | &new_part->archname, &((archetype *)old_part->head_ ())->archname); |
429 | &new_part->archname, &((archetype *)old_part->head_ ())->archname); |
435 | goto fail; |
430 | goto fail; |
436 | } |
431 | } |
437 | } |
432 | } |
438 | |
433 | |
439 | fprintf (stderr, "oh %p %s\n", old_head, &new_head->archname);//D |
|
|
440 | |
|
|
441 | // deactivate existing archetype |
434 | // deactivate existing archetype |
442 | for (archetype *at = old_head; at; at = (archetype *)at->more) |
435 | for (archetype *at = old_head; at; at = (archetype *)at->more) |
443 | at->unlink (); |
436 | at->unlink (); |
444 | |
437 | |
445 | // reassemble new chain |
438 | // assemble new chain |
446 | new_head->min_x = new_head->max_x = new_head->x; |
439 | new_head->min_x = new_head->max_x = new_head->x; |
447 | new_head->min_y = new_head->max_y = new_head->y; |
440 | new_head->min_y = new_head->max_y = new_head->y; |
448 | |
441 | |
449 | archetype *less = new_head; |
442 | archetype *less = new_head; |
450 | archetype *head = 0; |
|
|
451 | for (auto (p, parts.begin () + 1); p != parts.end (); ++p) |
443 | for (auto (p, parts.begin () + 1); p != parts.end (); ++p) |
452 | { |
444 | { |
453 | archetype *at = *p; |
445 | archetype *at = *p; |
|
|
446 | |
|
|
447 | // some flags get inherited formt he head (probably a lot more) |
|
|
448 | // doing it here doesn't feel too cozy, but it allows code |
|
|
449 | // to ignore head checks for these flags, which saves time |
|
|
450 | at->flag [FLAG_ALIVE] = new_head->flag [FLAG_ALIVE]; |
|
|
451 | at->flag [FLAG_NO_PICK] = new_head->flag [FLAG_NO_PICK]; |
|
|
452 | at->flag [FLAG_MONSTER] = new_head->flag [FLAG_MONSTER]; |
|
|
453 | at->flag [FLAG_IS_FLOOR] = new_head->flag [FLAG_IS_FLOOR]; |
454 | |
454 | |
455 | if (at->x < new_head->min_x) new_head->min_x = at->x; |
455 | if (at->x < new_head->min_x) new_head->min_x = at->x; |
456 | if (at->y < new_head->min_y) new_head->min_y = at->y; |
456 | if (at->y < new_head->min_y) new_head->min_y = at->y; |
457 | if (at->x > new_head->max_x) new_head->max_x = at->x; |
457 | if (at->x > new_head->max_x) new_head->max_x = at->x; |
458 | if (at->y > new_head->max_y) new_head->max_y = at->y; |
458 | if (at->y > new_head->max_y) new_head->max_y = at->y; |
459 | |
459 | |
460 | at->head = head; head = new_head; |
460 | at->head = new_head; |
461 | less->more = at; less = at; |
461 | less->more = at; |
|
|
462 | less = at; |
462 | } |
463 | } |
463 | |
464 | |
464 | // now activate it |
465 | // now activate it |
465 | for (auto (p, parts.begin ()); p != parts.end (); ++p) |
466 | for (auto (p, parts.begin ()); p != parts.end (); ++p) |
466 | { |
467 | { |
… | |
… | |
520 | * an object, and never NULL. |
521 | * an object, and never NULL. |
521 | */ |
522 | */ |
522 | object * |
523 | object * |
523 | create_singularity (const char *name) |
524 | create_singularity (const char *name) |
524 | { |
525 | { |
525 | object *op; |
526 | LOG (llevError | logBacktrace, "FATAL: creating singularity for '%s'.\n", name); |
|
|
527 | |
|
|
528 | if (!strcmp (name, "bug")) |
|
|
529 | abort (); |
|
|
530 | |
526 | char buf[MAX_BUF]; |
531 | char buf[MAX_BUF]; |
|
|
532 | sprintf (buf, "bug, please report (%s)", name); |
527 | |
533 | |
528 | sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name); |
534 | object *op = get_archetype ("bug"); |
529 | op = object::create (); |
|
|
530 | op->name = op->name_pl = buf; |
535 | op->name = op->name_pl = buf; |
531 | SET_FLAG (op, FLAG_NO_PICK); |
536 | |
532 | return op; |
537 | return op; |
533 | } |
538 | } |
534 | |
539 | |
535 | /* |
540 | /* |
536 | * Finds which archetype matches the given name, and returns a new |
541 | * Finds which archetype matches the given name, and returns a new |