1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
136 | { |
136 | { |
137 | signed char info:4; /* body info as loaded from the file */ |
137 | signed char info:4; /* body info as loaded from the file */ |
138 | signed char used:4; /* Calculated value based on items equipped */ |
138 | signed char used:4; /* Calculated value based on items equipped */ |
139 | }; |
139 | }; |
140 | |
140 | |
|
|
141 | typedef struct oblnk |
|
|
142 | { /* Used to link together several objects */ |
|
|
143 | object_ptr ob; |
|
|
144 | struct oblnk *next; |
|
|
145 | } objectlink; |
|
|
146 | |
|
|
147 | typedef struct oblinkpt |
|
|
148 | { /* Used to link together several object links */ |
|
|
149 | struct oblnk *link; |
|
|
150 | struct oblinkpt *next; |
|
|
151 | shstr id; /* Used as connected value in buttons/gates */ |
|
|
152 | } oblinkpt; |
|
|
153 | |
141 | INTERFACE_CLASS (object) |
154 | INTERFACE_CLASS (object) |
142 | // these are being copied |
155 | // these are being copied |
143 | struct object_copy : attachable |
156 | struct object_copy : attachable |
144 | { |
157 | { |
145 | sint16 ACC (RW, x), ACC (RW, y); /* Position in the map for this object */ |
158 | sint16 ACC (RW, x), ACC (RW, y); /* Position in the map for this object */ |
… | |
… | |
278 | shstr ACC (RW, lore); /* Obscure information about this object, */ |
291 | shstr ACC (RW, lore); /* Obscure information about this object, */ |
279 | /* To get put into books and the like. */ |
292 | /* To get put into books and the like. */ |
280 | shstr ACC (RW, custom_name); /* Custom name assigned by player */ |
293 | shstr ACC (RW, custom_name); /* Custom name assigned by player */ |
281 | }; |
294 | }; |
282 | |
295 | |
|
|
296 | const char *query_weight (const object *op); |
|
|
297 | const char *query_short_name (const object *op); |
|
|
298 | const char *query_name (const object *op); |
|
|
299 | const char *query_base_name (const object *op, int plural); |
|
|
300 | |
283 | struct object : zero_initialised, object_copy |
301 | struct object : zero_initialised, object_copy |
284 | { |
302 | { |
285 | // These variables are not changed by ->copy_to |
303 | // These variables are not changed by ->copy_to |
286 | maptile *ACC (RW, map); /* Pointer to the map in which this object is present */ |
304 | maptile *ACC (RW, map); /* Pointer to the map in which this object is present */ |
287 | |
305 | |
… | |
… | |
308 | object *head; /* Points to the main object of a large body */ // NO ACC, perl semantics are different |
326 | object *head; /* Points to the main object of a large body */ // NO ACC, perl semantics are different |
309 | client_container *seen_by; // seen by which player/container currently? |
327 | client_container *seen_by; // seen by which player/container currently? |
310 | key_value *key_values; /* Fields not explictly known by the loader. */ |
328 | key_value *key_values; /* Fields not explictly known by the loader. */ |
311 | |
329 | |
312 | // privates / perl |
330 | // privates / perl |
313 | const shstr &kv_get (const shstr &key) const; |
331 | shstr_tmp kv_get (shstr_tmp key) const; |
314 | void kv_del (const shstr &key); |
332 | void kv_del (shstr_tmp key); |
315 | void kv_set (const shstr &key, const shstr &value); |
333 | void kv_set (shstr_tmp key, shstr_tmp value); |
316 | |
334 | |
317 | // custom extra fields management |
335 | // custom extra fields management |
318 | struct key_value_access_proxy |
336 | struct key_value_access_proxy |
319 | { |
337 | { |
320 | object &ob; |
338 | object &ob; |
321 | shstr key; |
339 | shstr_tmp key; |
322 | |
340 | |
323 | key_value_access_proxy (object &ob, const shstr &key) |
341 | key_value_access_proxy (object &ob, shstr_tmp key) |
324 | : ob (ob), key (key) |
342 | : ob (ob), key (key) |
325 | { |
343 | { |
326 | } |
344 | } |
327 | |
345 | |
328 | const key_value_access_proxy &operator =(const shstr &value) const |
346 | const key_value_access_proxy &operator =(shstr_tmp value) const |
329 | { |
347 | { |
330 | ob.kv_set (key, value); |
348 | ob.kv_set (key, value); |
331 | return *this; |
349 | return *this; |
332 | } |
350 | } |
333 | |
351 | |
334 | operator const shstr &() const { return ob.kv_get (key); } |
352 | operator const shstr_tmp () const { return ob.kv_get (key); } |
335 | operator const char *() const { return ob.kv_get (key); } |
353 | operator const char *() const { return ob.kv_get (key); } |
336 | |
354 | |
337 | private: |
355 | private: |
338 | void operator =(int); |
356 | void operator =(int); |
339 | }; |
357 | }; |
340 | |
358 | |
341 | // operator [] is too annoying to use |
359 | // operator [] is too annoying to use |
342 | const key_value_access_proxy kv (const shstr &key) |
360 | const key_value_access_proxy kv (shstr_tmp key) |
343 | { |
361 | { |
344 | return key_value_access_proxy (*this, key); |
362 | return key_value_access_proxy (*this, key); |
345 | } |
363 | } |
346 | |
364 | |
347 | bool parse_kv (object_thawer &f); // parse kv pairs, (ab-)used by archetypes, which should not exist at all |
365 | bool parse_kv (object_thawer &f); // parse kv pairs, (ab-)used by archetypes, which should not exist at all |
… | |
… | |
365 | } |
383 | } |
366 | |
384 | |
367 | // recursively destroy all objects in inventory, optionally dropping them to the ground instead |
385 | // recursively destroy all objects in inventory, optionally dropping them to the ground instead |
368 | MTH void destroy_inv (bool drop_to_ground = false); |
386 | MTH void destroy_inv (bool drop_to_ground = false); |
369 | MTH object *insert (object *item); // insert into inventory |
387 | MTH object *insert (object *item); // insert into inventory |
370 | MTH void play_sound (faceidx sound); |
388 | MTH void play_sound (faceidx sound) const; |
|
|
389 | MTH void say_msg (const char *msg) const; |
371 | |
390 | |
372 | void do_remove (); |
391 | void do_remove (); |
373 | MTH void remove () |
392 | MTH void remove () |
374 | { |
393 | { |
375 | if (!flag [FLAG_REMOVED]) |
394 | if (!flag [FLAG_REMOVED]) |
… | |
… | |
381 | void move_to (const mapxy &pos) |
400 | void move_to (const mapxy &pos) |
382 | { |
401 | { |
383 | remove (); |
402 | remove (); |
384 | *this = pos; |
403 | *this = pos; |
385 | insert_at (this, this); |
404 | insert_at (this, this); |
|
|
405 | } |
|
|
406 | |
|
|
407 | // high-level move functions, return true if successful |
|
|
408 | int move (int dir, object *originator); |
|
|
409 | |
|
|
410 | int move (int dir) |
|
|
411 | { |
|
|
412 | return move (dir, this); |
386 | } |
413 | } |
387 | |
414 | |
388 | static bool can_merge_slow (object *op1, object *op2); |
415 | static bool can_merge_slow (object *op1, object *op2); |
389 | |
416 | |
390 | // this is often used in time-critical code, so optimise |
417 | // this is often used in time-critical code, so optimise |
… | |
… | |
404 | MTH void close_container () |
431 | MTH void close_container () |
405 | { |
432 | { |
406 | open_container (0); |
433 | open_container (0); |
407 | } |
434 | } |
408 | |
435 | |
409 | MTH object *force_find (const shstr name); |
436 | MTH object *force_find (shstr_tmp name); |
410 | MTH object *force_add (const shstr name, int duration = 0); |
437 | MTH object *force_add (shstr_tmp name, int duration = 0); |
|
|
438 | |
|
|
439 | oblinkpt *find_link () const; |
|
|
440 | MTH void add_link (maptile *map, shstr_tmp id); |
|
|
441 | MTH void remove_link (); |
411 | |
442 | |
412 | // overwrite the attachable should_invoke function with a version that also checks ev_want_type |
443 | // overwrite the attachable should_invoke function with a version that also checks ev_want_type |
413 | bool should_invoke (event_type event) |
444 | bool should_invoke (event_type event) |
414 | { |
445 | { |
415 | return ev_want_event [event] || ev_want_type [type] || cb; |
446 | return ev_want_event [event] || ev_want_type [type] || cb; |
… | |
… | |
451 | const materialtype_t *dominant_material () const; |
482 | const materialtype_t *dominant_material () const; |
452 | |
483 | |
453 | // return the volume of this object in cm³ |
484 | // return the volume of this object in cm³ |
454 | MTH uint64 volume () const |
485 | MTH uint64 volume () const |
455 | { |
486 | { |
456 | return total_weight () |
487 | return (uint64)total_weight () |
457 | * 1000 |
488 | * 1000 |
458 | * (type == CONTAINER ? 1000 : 1) |
489 | * (type == CONTAINER ? 1000 : 1) |
459 | / dominant_material ()->density; |
490 | / dominant_material ()->density; |
460 | } |
491 | } |
461 | |
492 | |
… | |
… | |
498 | |
529 | |
499 | return op; |
530 | return op; |
500 | } |
531 | } |
501 | |
532 | |
502 | // returns the outermost environment, never returns 0 |
533 | // returns the outermost environment, never returns 0 |
503 | MTH object *outer_env () |
534 | MTH object *outer_env () const |
504 | { |
535 | { |
505 | object *op; |
536 | const object *op; |
506 | |
537 | |
507 | for (op = this; op->env; op = op->env) |
538 | for (op = this; op->env; op = op->env) |
508 | ; |
539 | ; |
509 | |
540 | |
510 | return op; |
541 | return const_cast<object *>(op); |
511 | } |
542 | } |
512 | |
543 | |
513 | // returns the player that has this object in his inventory, or 0 |
544 | // returns the player that has this object in his inventory, or 0 |
514 | // we assume the player is always the outer env |
545 | // we assume the player is always the outer env |
515 | MTH object *in_player () |
546 | MTH object *in_player () const |
516 | { |
547 | { |
517 | object *op = outer_env (); |
548 | object *op = outer_env (); |
518 | |
549 | |
519 | return op->type == PLAYER ? op : 0; |
550 | return op->type == PLAYER ? op : 0; |
520 | } |
551 | } |
521 | |
552 | |
522 | // "temporary" helper function |
553 | // "temporary" helper function |
523 | MTH object *head_ () |
554 | MTH object *head_ () const |
524 | { |
555 | { |
525 | return head ? head : this; |
556 | return head ? head : const_cast<object *>(this); |
526 | } |
557 | } |
527 | |
558 | |
528 | MTH bool is_head () |
559 | MTH bool is_head () const |
529 | { |
560 | { |
530 | return head_ () == this; |
561 | return head_ () == this; |
531 | } |
562 | } |
532 | |
563 | |
533 | MTH bool is_on_map () const |
564 | MTH bool is_on_map () const |
… | |
… | |
538 | MTH bool is_inserted () const |
569 | MTH bool is_inserted () const |
539 | { |
570 | { |
540 | return !flag [FLAG_REMOVED]; |
571 | return !flag [FLAG_REMOVED]; |
541 | } |
572 | } |
542 | |
573 | |
|
|
574 | MTH bool is_player () const |
|
|
575 | { |
|
|
576 | return !!contr; |
|
|
577 | } |
|
|
578 | |
543 | MTH bool affects_los () const |
579 | MTH bool affects_los () const |
544 | { |
580 | { |
545 | return glow_radius || flag [FLAG_BLOCKSVIEW]; |
581 | return glow_radius || flag [FLAG_BLOCKSVIEW]; |
|
|
582 | } |
|
|
583 | |
|
|
584 | MTH bool has_carried_lights () const |
|
|
585 | { |
|
|
586 | return glow_radius; |
546 | } |
587 | } |
547 | |
588 | |
548 | // returns the player that cna see this object, if any |
589 | // returns the player that cna see this object, if any |
549 | MTH object *visible_to () const; |
590 | MTH object *visible_to () const; |
550 | |
591 | |
551 | MTH std::string long_desc (object *who = 0); |
592 | MTH std::string long_desc (object *who = 0); |
552 | MTH std::string describe_monster (object *who = 0); |
593 | MTH std::string describe_monster (object *who = 0); |
553 | MTH std::string describe_item (object *who = 0); |
594 | MTH std::string describe_item (object *who = 0); |
554 | MTH std::string describe (object *who = 0); |
595 | MTH std::string describe (object *who = 0); |
|
|
596 | |
|
|
597 | MTH const char *query_weight () { return ::query_weight (this); } |
|
|
598 | MTH const char *query_name () { return ::query_name (this); } |
|
|
599 | MTH const char *query_short_name () { return ::query_short_name (this); } |
|
|
600 | MTH const char *query_base_name (bool plural) { return ::query_base_name (this, plural); } |
555 | |
601 | |
556 | // If this object has no extra parts but should have them, |
602 | // If this object has no extra parts but should have them, |
557 | // add them, effectively expanding heads into multipart |
603 | // add them, effectively expanding heads into multipart |
558 | // objects. This method only works on objects not inserted |
604 | // objects. This method only works on objects not inserted |
559 | // anywhere. |
605 | // anywhere. |
… | |
… | |
679 | } |
725 | } |
680 | |
726 | |
681 | return ob; |
727 | return ob; |
682 | } |
728 | } |
683 | |
729 | |
684 | typedef struct oblnk |
|
|
685 | { /* Used to link together several objects */ |
|
|
686 | object_ptr ob; |
|
|
687 | struct oblnk *next; |
|
|
688 | } objectlink; |
|
|
689 | |
|
|
690 | typedef struct oblinkpt |
|
|
691 | { /* Used to link together several object links */ |
|
|
692 | struct oblnk *link; |
|
|
693 | sint32 value; /* Used as connected value in buttons/gates */ |
|
|
694 | struct oblinkpt *next; |
|
|
695 | } oblinkpt; |
|
|
696 | |
|
|
697 | object *find_skill_by_name (object *who, const char *name); |
730 | object *find_skill_by_name_fuzzy (object *who, const char *name); |
698 | object *find_skill_by_name (object *who, const shstr &sh); |
731 | object *find_skill_by_name (object *who, shstr_cmp sh); |
699 | object *find_skill_by_number (object *who, int skillno); |
732 | object *find_skill_by_number (object *who, int skillno); |
700 | |
733 | |
701 | /* |
734 | /* |
702 | * The archetype structure is a set of rules on how to generate and manipulate |
735 | * The archetype structure is a set of rules on how to generate and manipulate |
703 | * objects which point to archetypes. |
736 | * objects which point to archetypes. |
… | |
… | |
757 | extern objectvec objects; |
790 | extern objectvec objects; |
758 | extern activevec actives; |
791 | extern activevec actives; |
759 | extern archvec archetypes; |
792 | extern archvec archetypes; |
760 | |
793 | |
761 | // "safely" iterate over inv in a way such that the current item is removable |
794 | // "safely" iterate over inv in a way such that the current item is removable |
762 | // quite horrible, thats why its hidden in some macro |
795 | // quite horrible, that's why its hidden in some macro |
763 | #define for_inv_removable(op,var) \ |
796 | #define for_inv_removable(op,var) \ |
764 | for (object *var, *next_ = (op)->inv; (var = next_), var && (next_ = var->below), var; ) |
797 | for (object *var, *next_ = (op)->inv; (var = next_), var && (next_ = var->below), var; ) |
765 | |
798 | |
766 | #define for_all_objects(var) \ |
799 | #define for_all_objects(var) \ |
767 | for (unsigned _i = 0; _i < objects.size (); ++_i) \ |
800 | for (unsigned _i = 0; _i < objects.size (); ++_i) \ |