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 */ |
… | |
… | |
253 | |
266 | |
254 | sint8 ACC (RW, item_power); /* power rating of the object */ |
267 | sint8 ACC (RW, item_power); /* power rating of the object */ |
255 | // 8 free bits |
268 | // 8 free bits |
256 | |
269 | |
257 | float ACC (RW, move_slow_penalty); /* How much this slows down the object */ |
270 | float ACC (RW, move_slow_penalty); /* How much this slows down the object */ |
258 | char *ACC (RW, spellarg); |
271 | shstr ACC (RW, spellarg); /* only used in arrows - get rid of it? */ |
259 | |
272 | |
260 | /* Following are values used by any object */ |
273 | /* Following are values used by any object */ |
261 | /* this objects turns into or what this object creates */ |
274 | /* this objects turns into or what this object creates */ |
262 | treasurelist *ACC (RW, randomitems); /* Items to be generated */ |
275 | treasurelist *ACC (RW, randomitems); /* Items to be generated */ |
263 | |
276 | |
… | |
… | |
277 | shstr ACC (RW, msg); /* If this is a book/sign/magic mouth/etc */ |
290 | shstr ACC (RW, msg); /* If this is a book/sign/magic mouth/etc */ |
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 | }; |
|
|
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); |
282 | |
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 */ |
… | |
… | |
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]) |
… | |
… | |
403 | && can_merge_slow (op1, op2); |
422 | && can_merge_slow (op1, op2); |
404 | } |
423 | } |
405 | |
424 | |
406 | MTH void set_owner (object *owner); |
425 | MTH void set_owner (object *owner); |
407 | MTH void set_speed (float speed); |
426 | MTH void set_speed (float speed); |
|
|
427 | MTH void set_glow_radius (sint8 rad); |
408 | MTH bool change_weapon (object *ob); |
428 | MTH bool change_weapon (object *ob); |
409 | MTH bool change_skill (object *ob); |
429 | MTH bool change_skill (object *ob); |
410 | |
430 | |
411 | MTH void open_container (object *new_container); |
431 | MTH void open_container (object *new_container); |
412 | MTH void close_container () |
432 | MTH void close_container () |
… | |
… | |
414 | open_container (0); |
434 | open_container (0); |
415 | } |
435 | } |
416 | |
436 | |
417 | MTH object *force_find (shstr_tmp name); |
437 | MTH object *force_find (shstr_tmp name); |
418 | MTH object *force_add (shstr_tmp name, int duration = 0); |
438 | MTH object *force_add (shstr_tmp name, int duration = 0); |
|
|
439 | |
|
|
440 | oblinkpt *find_link () const; |
|
|
441 | MTH void add_link (maptile *map, shstr_tmp id); |
|
|
442 | MTH void remove_link (); |
419 | |
443 | |
420 | // overwrite the attachable should_invoke function with a version that also checks ev_want_type |
444 | // overwrite the attachable should_invoke function with a version that also checks ev_want_type |
421 | bool should_invoke (event_type event) |
445 | bool should_invoke (event_type event) |
422 | { |
446 | { |
423 | return ev_want_event [event] || ev_want_type [type] || cb; |
447 | return ev_want_event [event] || ev_want_type [type] || cb; |
… | |
… | |
506 | |
530 | |
507 | return op; |
531 | return op; |
508 | } |
532 | } |
509 | |
533 | |
510 | // returns the outermost environment, never returns 0 |
534 | // returns the outermost environment, never returns 0 |
511 | MTH object *outer_env () |
535 | MTH object *outer_env () const |
512 | { |
536 | { |
513 | object *op; |
537 | const object *op; |
514 | |
538 | |
515 | for (op = this; op->env; op = op->env) |
539 | for (op = this; op->env; op = op->env) |
516 | ; |
540 | ; |
517 | |
541 | |
518 | return op; |
542 | return const_cast<object *>(op); |
519 | } |
543 | } |
520 | |
544 | |
521 | // returns the player that has this object in his inventory, or 0 |
545 | // returns the player that has this object in his inventory, or 0 |
522 | // we assume the player is always the outer env |
546 | // we assume the player is always the outer env |
523 | MTH object *in_player () |
547 | MTH object *in_player () const |
524 | { |
548 | { |
525 | object *op = outer_env (); |
549 | object *op = outer_env (); |
526 | |
550 | |
527 | return op->type == PLAYER ? op : 0; |
551 | return op->type == PLAYER ? op : 0; |
528 | } |
552 | } |
529 | |
553 | |
530 | // "temporary" helper function |
554 | // "temporary" helper function |
531 | MTH object *head_ () |
555 | MTH object *head_ () const |
532 | { |
556 | { |
533 | return head ? head : this; |
557 | return head ? head : const_cast<object *>(this); |
534 | } |
558 | } |
535 | |
559 | |
536 | MTH bool is_head () |
560 | MTH bool is_head () const |
537 | { |
561 | { |
538 | return head_ () == this; |
562 | return head_ () == this; |
539 | } |
563 | } |
540 | |
564 | |
541 | MTH bool is_on_map () const |
565 | MTH bool is_on_map () const |
… | |
… | |
568 | |
592 | |
569 | MTH std::string long_desc (object *who = 0); |
593 | MTH std::string long_desc (object *who = 0); |
570 | MTH std::string describe_monster (object *who = 0); |
594 | MTH std::string describe_monster (object *who = 0); |
571 | MTH std::string describe_item (object *who = 0); |
595 | MTH std::string describe_item (object *who = 0); |
572 | MTH std::string describe (object *who = 0); |
596 | MTH std::string describe (object *who = 0); |
|
|
597 | |
|
|
598 | MTH const char *query_weight () { return ::query_weight (this); } |
|
|
599 | MTH const char *query_name () { return ::query_name (this); } |
|
|
600 | MTH const char *query_short_name () { return ::query_short_name (this); } |
|
|
601 | MTH const char *query_base_name (bool plural) { return ::query_base_name (this, plural); } |
573 | |
602 | |
574 | // If this object has no extra parts but should have them, |
603 | // If this object has no extra parts but should have them, |
575 | // add them, effectively expanding heads into multipart |
604 | // add them, effectively expanding heads into multipart |
576 | // objects. This method only works on objects not inserted |
605 | // objects. This method only works on objects not inserted |
577 | // anywhere. |
606 | // anywhere. |
… | |
… | |
666 | // make some noise with given item into direction dir, |
695 | // make some noise with given item into direction dir, |
667 | // currently only used for players to make them temporarily visible |
696 | // currently only used for players to make them temporarily visible |
668 | // when they are invisible. |
697 | // when they are invisible. |
669 | MTH void make_noise (); |
698 | MTH void make_noise (); |
670 | |
699 | |
|
|
700 | /* animation */ |
|
|
701 | bool has_anim () { return animation_id; } |
|
|
702 | const animation &anim () const { return animations [animation_id]; } |
|
|
703 | faceidx get_anim_frame (int frame) const { return anim ().faces [frame]; } |
|
|
704 | void set_anim_frame (int frame) { face = get_anim_frame (frame); } |
|
|
705 | /* anim_frames () returns the number of animations allocated. The last |
|
|
706 | * usuable animation will be anim_frames () - 1 (for example, if an object |
|
|
707 | * has 8 animations, anim_frames () will return 8, but the values will |
|
|
708 | * range from 0 through 7. |
|
|
709 | */ |
|
|
710 | int anim_frames () const { return anim ().num_animations; } |
|
|
711 | int anim_facings () const { return anim ().facings; } |
|
|
712 | |
671 | protected: |
713 | protected: |
672 | void link (); |
714 | void link (); |
673 | void unlink (); |
715 | void unlink (); |
674 | |
716 | |
675 | object (); |
717 | object (); |
… | |
… | |
696 | ob->env->inv = ob; |
738 | ob->env->inv = ob; |
697 | } |
739 | } |
698 | |
740 | |
699 | return ob; |
741 | return ob; |
700 | } |
742 | } |
701 | |
|
|
702 | typedef struct oblnk |
|
|
703 | { /* Used to link together several objects */ |
|
|
704 | object_ptr ob; |
|
|
705 | struct oblnk *next; |
|
|
706 | } objectlink; |
|
|
707 | |
|
|
708 | typedef struct oblinkpt |
|
|
709 | { /* Used to link together several object links */ |
|
|
710 | struct oblnk *link; |
|
|
711 | sint32 value; /* Used as connected value in buttons/gates */ |
|
|
712 | struct oblinkpt *next; |
|
|
713 | } oblinkpt; |
|
|
714 | |
743 | |
715 | object *find_skill_by_name_fuzzy (object *who, const char *name); |
744 | object *find_skill_by_name_fuzzy (object *who, const char *name); |
716 | object *find_skill_by_name (object *who, shstr_cmp sh); |
745 | object *find_skill_by_name (object *who, shstr_cmp sh); |
717 | object *find_skill_by_number (object *who, int skillno); |
746 | object *find_skill_by_number (object *who, int skillno); |
718 | |
747 | |