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

Comparing deliantra/server/common/object.C (file contents):
Revision 1.204 by root, Fri Apr 11 17:01:52 2008 UTC vs.
Revision 1.206 by root, Tue Apr 15 14:21:04 2008 UTC

140{ 140{
141 read_uuid (); 141 read_uuid ();
142} 142}
143 143
144/* Returns TRUE if every key_values in wants has a partner with the same value in has. */ 144/* Returns TRUE if every key_values in wants has a partner with the same value in has. */
145static int 145static bool
146compare_ob_value_lists_one (const object *wants, const object *has) 146compare_ob_value_lists_one (const object *wants, const object *has)
147{ 147{
148 key_value *wants_field; 148 key_value *wants_field;
149 149
150 /* n-squared behaviour (see get_ob_key_link()), but I'm hoping both 150 /* n-squared behaviour (see get_ob_key_link()), but I'm hoping both
158 key_value *has_field; 158 key_value *has_field;
159 159
160 /* Look for a field in has with the same key. */ 160 /* Look for a field in has with the same key. */
161 has_field = get_ob_key_link (has, wants_field->key); 161 has_field = get_ob_key_link (has, wants_field->key);
162 162
163 if (has_field == NULL) 163 if (!has_field)
164 {
165 /* No field with that name. */ 164 return 0; /* No field with that name. */
166 return FALSE;
167 }
168 165
169 /* Found the matching field. */ 166 /* Found the matching field. */
170 if (has_field->value != wants_field->value) 167 if (has_field->value != wants_field->value)
171 {
172 /* Values don't match, so this half of the comparison is false. */ 168 return 0; /* Values don't match, so this half of the comparison is false. */
173 return FALSE;
174 }
175 169
176 /* If we get here, we found a match. Now for the next field in wants. */ 170 /* If we get here, we found a match. Now for the next field in wants. */
177 } 171 }
178 172
179 /* If we get here, every field in wants has a matching field in has. */ 173 /* If we get here, every field in wants has a matching field in has. */
180 return TRUE; 174 return 1;
181} 175}
182 176
183/* Returns TRUE if ob1 has the same key_values as ob2. */ 177/* Returns TRUE if ob1 has the same key_values as ob2. */
184static int 178static bool
185compare_ob_value_lists (const object *ob1, const object *ob2) 179compare_ob_value_lists (const object *ob1, const object *ob2)
186{ 180{
187 /* However, there may be fields in has which aren't partnered in wants, 181 /* However, there may be fields in has which aren't partnered in wants,
188 * so we need to run the comparison *twice*. :( 182 * so we need to run the comparison *twice*. :(
189 */ 183 */
210 || ob1->speed != ob2->speed 204 || ob1->speed != ob2->speed
211 || ob1->value != ob2->value 205 || ob1->value != ob2->value
212 || ob1->name != ob2->name) 206 || ob1->name != ob2->name)
213 return 0; 207 return 0;
214 208
215 //TODO: this ain't working well, use nicer and correct overflow check 209 /* Do not merge objects if nrof would overflow. First part checks
216 /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that 210 * for unsigned overflow (2c), second part checks wether the result
217 * value could not be stored in a sint32 (which unfortunately sometimes is 211 * would fit into a 32 bit signed int, which is often used to hold
218 * used to store nrof). 212 * nrof values.
219 */ 213 */
220 if (ob1->nrof + ob2->nrof >= 1UL << 31) 214 if (~ob1->nrof < ob2->nrof || ob1->nrof + ob2->nrof > (1UL << 31))
221 return 0; 215 return 0;
222 216
223 /* If the objects have been identified, set the BEEN_APPLIED flag. 217 /* If the objects have been identified, set the BEEN_APPLIED flag.
224 * This is to the comparison of the flags below will be OK. We 218 * This is to the comparison of the flags below will be OK. We
225 * just can't ignore the been applied or identified flags, as they 219 * just can't ignore the been applied or identified flags, as they
226 * are not equal - just if it has been identified, the been_applied 220 * are not equal - just if it has been identified, the been_applied
227 * flags lose any meaning. 221 * flags lose any meaning.
228 */ 222 */
229 if (QUERY_FLAG (ob1, FLAG_IDENTIFIED)) 223 if (QUERY_FLAG (ob1, FLAG_IDENTIFIED))
257 || ob1->move_off != ob2->move_off 251 || ob1->move_off != ob2->move_off
258 || ob1->move_slow != ob2->move_slow 252 || ob1->move_slow != ob2->move_slow
259 || ob1->move_slow_penalty != ob2->move_slow_penalty) 253 || ob1->move_slow_penalty != ob2->move_slow_penalty)
260 return 0; 254 return 0;
261 255
262 /* This is really a spellbook check - really, we should 256 /* This is really a spellbook check - we should in general
263 * check all objects in the inventory. 257 * not merge objects with real inventories, as splitting them
258 * is hard.
264 */ 259 */
265 if (ob1->inv || ob2->inv) 260 if (ob1->inv || ob2->inv)
266 { 261 {
267 if (!(ob1->inv && ob2->inv)) 262 if (!(ob1->inv && ob2->inv))
268 return 0; /* inventories differ in length */ 263 return 0; /* inventories differ in length */
269 264
270 if (ob1->inv->below || ob2->inv->below) 265 if (ob1->inv->below || ob2->inv->below)
271 return 0; /* more than one object in inv */ 266 return 0; /* more than one object in inv */
272 267
273 if (!object::can_merge (ob1->inv, ob2->inv)) 268 if (!object::can_merge (ob1->inv, ob2->inv))
274 return 0; /* inventory objexts differ */ 269 return 0; /* inventory objects differ */
275 270
276 /* inventory ok - still need to check rest of this object to see 271 /* inventory ok - still need to check rest of this object to see
277 * if it is valid. 272 * if it is valid.
278 */ 273 */
279 } 274 }
298 if (ob1->level != ob2->level) 293 if (ob1->level != ob2->level)
299 return 0; 294 return 0;
300 break; 295 break;
301 } 296 }
302 297
303 if (ob1->key_values != NULL || ob2->key_values != NULL) 298 if (ob1->key_values || ob2->key_values)
304 { 299 {
305 /* At least one of these has key_values. */ 300 /* At least one of these has key_values. */
306 if ((ob1->key_values == NULL) != (ob2->key_values == NULL)) 301 if ((!ob1->key_values) != (!ob2->key_values))
307 /* One has fields, but the other one doesn't. */ 302 /* One has fields, but the other one doesn't. */
308 return 0; 303 return 0;
309 else if (!compare_ob_value_lists (ob1, ob2)) 304 else if (!compare_ob_value_lists (ob1, ob2))
310 return 0; 305 return 0;
311 } 306 }
868 * if some form of movement is allowed, let objects 863 * if some form of movement is allowed, let objects
869 * drop on that space. 864 * drop on that space.
870 */ 865 */
871 if (!drop_to_ground 866 if (!drop_to_ground
872 || !map 867 || !map
873 || map->in_memory != MAP_IN_MEMORY 868 || map->in_memory != MAP_ACTIVE
874 || map->nodrop 869 || map->nodrop
875 || ms ().move_block == MOVE_ALL) 870 || ms ().move_block == MOVE_ALL)
876 { 871 {
877 while (inv) 872 while (inv)
878 { 873 {
940 freed_map->width = 3; 935 freed_map->width = 3;
941 freed_map->height = 3; 936 freed_map->height = 3;
942 freed_map->nodrop = 1; 937 freed_map->nodrop = 1;
943 938
944 freed_map->alloc (); 939 freed_map->alloc ();
945 freed_map->in_memory = MAP_IN_MEMORY; 940 freed_map->in_memory = MAP_ACTIVE;
946 } 941 }
947 942
948 map = freed_map; 943 map = freed_map;
949 x = 1; 944 x = 1;
950 y = 1; 945 y = 1;
1484} 1479}
1485 1480
1486object * 1481object *
1487object::insert_at (object *where, object *originator, int flags) 1482object::insert_at (object *where, object *originator, int flags)
1488{ 1483{
1484 if (where->env)
1485 return where->env->insert (this);
1486 else
1489 return where->map->insert (this, where->x, where->y, originator, flags); 1487 return where->map->insert (this, where->x, where->y, originator, flags);
1490} 1488}
1491 1489
1492/* 1490/*
1493 * get_split_ob(ob,nr) splits up ob into two parts. The part which 1491 * get_split_ob(ob,nr) splits up ob into two parts. The part which
1494 * is returned contains nr objects, and the remaining parts contains 1492 * is returned contains nr objects, and the remaining parts contains
1514 orig_ob->destroy (1); 1512 orig_ob->destroy (1);
1515 else if (!is_removed) 1513 else if (!is_removed)
1516 { 1514 {
1517 if (orig_ob->env != NULL) 1515 if (orig_ob->env != NULL)
1518 sub_weight (orig_ob->env, orig_ob->weight * nr); 1516 sub_weight (orig_ob->env, orig_ob->weight * nr);
1519 if (orig_ob->env == NULL && orig_ob->map->in_memory != MAP_IN_MEMORY) 1517 if (orig_ob->env == NULL && orig_ob->map->in_memory != MAP_ACTIVE)
1520 { 1518 {
1521 strcpy (errmsg, "Tried to split object whose map is not in memory."); 1519 strcpy (errmsg, "Tried to split object whose map is not in memory.");
1522 LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n"); 1520 LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n");
1523 return NULL; 1521 return NULL;
1524 } 1522 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines