MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // container/description.c -- standard description for containers |
| 4 | // |
| 5 | // $Id: description.c 8755 2014-04-26 13:13:40Z Zesstra $ |
| 6 | |
| 7 | inherit "/std/thing/description"; |
| 8 | |
| 9 | #pragma strict_types |
| 10 | #pragma save_types |
| 11 | #pragma range_check |
| 12 | #pragma no_clone |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 13 | |
| 14 | #define NEED_PROTOTYPES |
| 15 | |
| 16 | #include <container.h> |
| 17 | #include <properties.h> |
| 18 | #include <defines.h> |
| 19 | #include <wizlevels.h> |
| 20 | |
| 21 | |
Zesstra | 52d4093 | 2018-11-28 22:05:15 +0100 | [diff] [blame] | 22 | protected void create() |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 23 | { |
| 24 | ::create(); |
| 25 | SetProp(P_TRANSPARENT, 1); |
| 26 | AddId("Container"); |
| 27 | } |
| 28 | |
Zesstra | 4925393 | 2018-11-28 21:42:59 +0100 | [diff] [blame] | 29 | public varargs string long(int mode) { |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 30 | string descr, inv_descr; |
| 31 | |
| 32 | descr = process_string(QueryProp(P_LONG)); |
| 33 | if(!QueryProp(P_TRANSPARENT)) return descr; |
| 34 | |
| 35 | inv_descr = make_invlist(PL, all_inventory(ME), mode ); |
| 36 | if ( inv_descr != "" ) |
| 37 | descr += capitalize(QueryPronoun(WER)) + " enthaelt:\n" + inv_descr; |
| 38 | return descr; |
| 39 | } |
| 40 | |
| 41 | // flags: 1 - wizard, 2 - don't collect equal objects ' |
| 42 | // flags: 4 - don't append infos for wizards |
| 43 | private void stringenize(mixed obj, int flags, mixed objs, mixed info) |
| 44 | { |
| 45 | string id, tmp; |
| 46 | int idx; |
| 47 | |
| 48 | if ( (!(flags & 4) && (flags & 1))) { |
| 49 | //wenn Magier und Magierinfos angehaengt werden sollen: |
| 50 | tmp = capitalize(obj->short()||"")[0..<2] |
| 51 | + " ["+object_name(obj)+"]"; |
| 52 | } |
| 53 | else if (obj->QueryProp(P_INVIS)) { |
| 54 | //keine Ausgabe bzw. leerer String, wird dann von collect rausgeschmissen |
| 55 | tmp=""; |
| 56 | } |
| 57 | else { |
| 58 | //Spieler, Magier ohne P_WANTS_TO_LEARN etc. |
| 59 | tmp = capitalize(obj->short()||"")[0..<2]; |
| 60 | } |
| 61 | //wenn wizard und 'dont collect equal objects': id ist object_name() |
| 62 | if(flags & 3 || living(obj)) |
| 63 | id = object_name(obj); |
| 64 | //sonst nehmen wir den Namen der Blueprint ->zusammenfassen der Objekte |
| 65 | else |
| 66 | id = BLUE_NAME(obj) + tmp; |
| 67 | // Anzahl des jeweiligen Objekts (anhand von id) zaehlen. |
| 68 | if((idx = member(objs, id)) == -1) |
| 69 | { |
| 70 | objs += ({ id }); |
| 71 | info += ({ ({ tmp, 1, obj}) }); |
| 72 | } |
| 73 | else |
| 74 | info[idx][1]++; |
| 75 | } |
| 76 | |
| 77 | private string collect(mixed obj) |
| 78 | { |
| 79 | //bekommt ein Array ({name,anzahl,objekt}) |
| 80 | //Objekte ohne Namen (P_SHORT==0 oder P_INVIS) wegwerfen |
| 81 | if(!sizeof(obj[0])) return 0; |
| 82 | // Objektname + (Anzahl) zurueckgeben. |
| 83 | return obj[0] + (obj[1] > 1 ? " ("+obj[1]+")" : ""); |
| 84 | } |
| 85 | |
| 86 | // flags: 1 - return array, 2 - don't collect equal objects ' |
| 87 | // flags: 4 - don't append infos for wizards |
Zesstra | 52d4093 | 2018-11-28 22:05:15 +0100 | [diff] [blame] | 88 | visible varargs mixed make_invlist(object viewer, mixed inv, int flags) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 89 | { |
| 90 | int iswiz; |
| 91 | mixed objs, info; |
| 92 | |
| 93 | iswiz = IS_LEARNER( viewer ) && viewer->QueryProp(P_WANTS_TO_LEARN); |
| 94 | objs = ({}); info = ({}); |
| 95 | map(inv, #'stringenize/*'*/, iswiz | (flags & 2) | (flags & 4), &objs, &info); |
| 96 | if(flags & 1) return info; |
| 97 | inv = map(info, #'collect/*'*/) - ({ 0 }); |
| 98 | if(!sizeof(inv)) return ""; |
| 99 | return sprintf("%"+(sizeof(inv) > 6 ? "#" : "=")+"-78s", |
| 100 | implode(inv, "\n")) + "\n"; |
| 101 | } |
| 102 | |