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