--- deliantra/server/common/arch.C 2007/06/04 13:04:00 1.63
+++ deliantra/server/common/arch.C 2007/09/04 18:20:35 1.69
@@ -1,23 +1,22 @@
/*
- * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game.
+ * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
*
* Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
* Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
* Copyright (©) 1992,2007 Frank Tore Johansen
*
- * Crossfire TRT is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
+ * Crossfire TRT is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
- * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*
* The authors can be reached via e-mail to
*/
@@ -39,7 +38,7 @@
* MSW 2003-04-29
*/
-bool loading_arch; // ugly flag to object laoder etc. to suppress/request special processing
+archetype *loading_arch; // ugly flag to object laoder etc. to suppress/request special processing
// the hashtable
typedef std::tr1::unordered_map
@@ -71,7 +70,7 @@
shstr_cmp name_cmp (name);
for_all_archetypes (at)
- if (at->archname == name_cmp)
+ if (at->name == name_cmp)
return at;
return 0;
@@ -88,7 +87,7 @@
shstr_cmp name_cmp (name);
for_all_archetypes (at)
- if (at->archname == name_cmp && at->type == type)
+ if (at->name == name_cmp && at->type == type)
return at;
return 0;
@@ -159,23 +158,23 @@
return create_singularity (name);
}
- /* This is a subset of the parse_id command. Basically, name can be
- * a string seperated lists of things to match, with certain keywords.
- * pl is the player (only needed to set count properly)
- * op is the item we are trying to match. Calling function takes care
- * of what action might need to be done and if it is valid
- * (pickup, drop, etc.) Return NONZERO if we have a match. A higher
- * value means a better match. 0 means no match.
- *
- * Brief outline of the procedure:
- * We take apart the name variable into the individual components.
- * cases for 'all' and unpaid are pretty obvious.
- * Next, we check for a count (either specified in name, or in the
- * player object.)
- * If count is 1, make a quick check on the name.
- * IF count is >1, we need to make plural name. Return if match.
- * Last, make a check on the full name.
- */
+/* This is a subset of the parse_id command. Basically, name can be
+ * a string seperated lists of things to match, with certain keywords.
+ * pl is the player (only needed to set count properly)
+ * op is the item we are trying to match. Calling function takes care
+ * of what action might need to be done and if it is valid
+ * (pickup, drop, etc.) Return NONZERO if we have a match. A higher
+ * value means a better match. 0 means no match.
+ *
+ * Brief outline of the procedure:
+ * We take apart the name variable into the individual components.
+ * cases for 'all' and unpaid are pretty obvious.
+ * Next, we check for a count (either specified in name, or in the
+ * player object.)
+ * If count is 1, make a quick check on the name.
+ * IF count is >1, we need to make plural name. Return if match.
+ * Last, make a check on the full name.
+ */
int
item_matched_string (object *pl, object *op, const char *name)
{
@@ -334,15 +333,12 @@
name = "(null)";
}
- archetype *at = find (name);
+ if (loading_arch && !strcmp (&loading_arch->archname, name))
+ return loading_arch;
- if (loading_arch && at && !at->stub)
- {
- at->unlink ();
- at = 0;
- }
+ archetype *at = find (name);
- if (!at || (!at->stub && loading_arch))
+ if (!at)
{
at = new archetype (name);
at->link ();
@@ -356,8 +352,6 @@
{
assert (f.kw == KW_object);
- loading_arch = true; // hack to tell parse_kv et al. to behave
-
std::vector parts;
coroapi::cede_to_tick_every (10);
@@ -390,10 +384,16 @@
}
#endif
- if (!at->parse_kv (f))
+ loading_arch = at; // hack to tell parse_kv et al. to behave
+ bool parse_ok = at->parse_kv (f);
+ loading_arch = 0;
+
+ if (!parse_ok)
goto fail;
+ loading_arch = at; // hack to tell parse_kv et al. to behave
at->post_load_check ();
+ loading_arch = 0;
parts.push_back (at);
@@ -409,16 +409,18 @@
}
}
- loading_arch = false;
-
{
auto (at, parts.begin ());
archetype *new_head = parts.front ();
archetype *old_head = find (new_head->archname);
- for (auto (at, parts.begin ()); at != parts.end (); ++at)
- fprintf (stderr, "%d: %s\n", at - parts.begin(), &(*at)->archname);//D
+ if (old_head && !old_head->is_head ())
+ {
+ LOG (llevError, "%s: unable to overwrite non-head archetype '%s' with head archetype, skipping.\n",
+ &new_head->archname, &old_head->archname);
+ goto fail;
+ }
// check that all archetypes belong to the same old object or are new
for (auto (at, parts.begin ()); at != parts.end (); ++at)
@@ -428,37 +430,41 @@
if (old_part && old_part->head_ () != old_head)
{
- fprintf (stderr, "nhn %s\n", &new_head->archname);//D
- fprintf (stderr, "old_head %p,%p new_head %p,%p ph %p\n", old_head, old_part, new_head, new_part, old_part->head_());
LOG (llevError, "%s: unable to overwrite archetype '%s' with archetype of different object, skipping.\n",
&new_part->archname, &((archetype *)old_part->head_ ())->archname);
goto fail;
}
}
- fprintf (stderr, "oh %p %s\n", old_head, &new_head->archname);//D
-
// deactivate existing archetype
for (archetype *at = old_head; at; at = (archetype *)at->more)
at->unlink ();
- // reassemble new chain
+ // assemble new chain
new_head->min_x = new_head->max_x = new_head->x;
new_head->min_y = new_head->max_y = new_head->y;
archetype *less = new_head;
- archetype *head = 0;
for (auto (p, parts.begin () + 1); p != parts.end (); ++p)
{
archetype *at = *p;
+ // some flags get inherited formt he head (probably a lot more)
+ // doing it here doesn't feel too cozy, but it allows code
+ // to ignore head checks for these flags, which saves time
+ at->flag [FLAG_ALIVE] = new_head->flag [FLAG_ALIVE];
+ at->flag [FLAG_NO_PICK] = new_head->flag [FLAG_NO_PICK];
+ at->flag [FLAG_MONSTER] = new_head->flag [FLAG_MONSTER];
+ at->flag [FLAG_IS_FLOOR] = new_head->flag [FLAG_IS_FLOOR];
+
if (at->x < new_head->min_x) new_head->min_x = at->x;
if (at->y < new_head->min_y) new_head->min_y = at->y;
if (at->x > new_head->max_x) new_head->max_x = at->x;
if (at->y > new_head->max_y) new_head->max_y = at->y;
- at->head = head; head = new_head;
- less->more = at; less = at;
+ at->head = new_head;
+ less->more = at;
+ less = at;
}
// now activate it
@@ -476,7 +482,6 @@
for (auto (p, parts.begin ()); p != parts.end (); ++p)
(*p)->destroy (true);
- loading_arch = false;
return 0;
}
@@ -522,13 +527,17 @@
object *
create_singularity (const char *name)
{
- object *op;
+ LOG (llevError | logBacktrace, "FATAL: creating singularity for '%s'.\n", name);
+
+ if (!strcmp (name, "bug"))
+ abort ();
+
char buf[MAX_BUF];
+ sprintf (buf, "bug, please report (%s)", name);
- sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name);
- op = object::create ();
+ object *op = get_archetype ("bug");
op->name = op->name_pl = buf;
- SET_FLAG (op, FLAG_NO_PICK);
+
return op;
}