MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // clothing/container_description.c -- clothing_container description handling |
| 4 | // |
| 5 | // $Id: container_description.c 6198 2007-02-13 23:39:43Z Zesstra $ |
| 6 | |
| 7 | #pragma strict_types |
| 8 | #pragma save_types |
| 9 | #pragma no_clone |
| 10 | #pragma pedantic |
| 11 | #pragma range_check |
| 12 | |
| 13 | inherit "/std/thing/description"; |
| 14 | |
| 15 | #define NEED_PROTOTYPES |
| 16 | |
| 17 | #include <thing/properties.h> |
| 18 | #include <thing/description.h> |
| 19 | #include <thing/language.h> |
| 20 | #include <container.h> |
| 21 | #include <combat.h> |
| 22 | #include <thing/material.h> |
| 23 | #include <defines.h> |
| 24 | #include <wizlevels.h> |
| 25 | #include <player/base.h> |
| 26 | |
| 27 | void create() |
| 28 | { |
| 29 | ::create(); |
| 30 | SetProp(P_TRANSPARENT, 1); |
| 31 | AddId("Container"); |
| 32 | } |
| 33 | |
| 34 | string dam_descr() |
| 35 | { string re; |
| 36 | mixed desc; |
| 37 | int maximum,dam,pos; |
| 38 | |
| 39 | if (!QueryProp(P_NAME) || !QueryProp(P_DAMAGED) || !QueryProp(P_SHORT) || |
| 40 | !(desc=QueryProp(P_DAM_DESC)) || (!stringp(desc) && !pointerp(desc))) |
| 41 | return ""; |
| 42 | re = capitalize(name(WER,2))+" "; |
| 43 | maximum = QueryProp(P_AC)+(dam=QueryProp(P_DAMAGED)); |
| 44 | if (stringp(desc)) |
| 45 | return (dam>(maximum/2))?(re+desc+".\n"):""; |
| 46 | pos = (sizeof(desc)*dam/maximum); |
| 47 | if (stringp(desc[pos])) |
| 48 | return (re+desc[pos]+".\n"); |
| 49 | return ""; |
| 50 | } |
| 51 | |
| 52 | string short() |
| 53 | { string s; |
| 54 | if(!(s=process_string(QueryProp(P_SHORT)))) |
| 55 | return 0; |
| 56 | return s+(QueryProp(P_WORN)?" (angezogen).\n":".\n"); |
| 57 | } |
| 58 | |
| 59 | varargs string long(int mode) |
| 60 | { string descr, inv_descr; |
| 61 | |
| 62 | descr=(process_string(QueryProp(P_LONG)||"") + (dam_descr()||"")); |
| 63 | if (!QueryProp(P_TRANSPARENT)) |
| 64 | return descr; |
| 65 | |
| 66 | inv_descr = make_invlist(PL, all_inventory(ME), mode ); |
| 67 | if ( inv_descr != "" ) |
| 68 | descr += capitalize(QueryPronoun(WER)) + " enthaelt:\n" + inv_descr; |
| 69 | return descr; |
| 70 | } |
| 71 | |
| 72 | mapping _query_material() { |
| 73 | mixed res,at; |
| 74 | |
| 75 | if (mappingp(res=Query(P_MATERIAL))) |
| 76 | return res; |
| 77 | at=QueryProp(P_ARMOUR_TYPE); |
| 78 | switch(at) { |
| 79 | case AT_ARMOUR: |
| 80 | case AT_HELMET: |
| 81 | case AT_RING: |
| 82 | case AT_AMULET: |
| 83 | case AT_SHIELD: |
| 84 | return ([MAT_MISC_METAL:100]); |
| 85 | case AT_CLOAK: |
| 86 | case AT_TROUSERS: |
| 87 | return ([MAT_CLOTH:100]); |
| 88 | case AT_GLOVE: |
| 89 | case AT_BOOT: |
| 90 | return ([MAT_CLOTH:100]); |
| 91 | } |
| 92 | return ([MAT_CLOTH:100]); |
| 93 | } |
| 94 | |
| 95 | // flags: 1 - wizard, 2 - don't collect equal objects ' |
| 96 | // flags: 4 - don't append infos for wizards |
| 97 | private void stringenize(mixed obj, int flags, mixed objs, mixed info) |
| 98 | { |
| 99 | string id, tmp; |
| 100 | int idx; |
| 101 | tmp = capitalize(obj->short()||"")[0..<2] |
| 102 | + (!(flags & 4) && (flags & 1) ? " ["+object_name(obj)+"]" : ""); |
| 103 | if(flags & 3 || living(obj)) id = object_name(obj); |
| 104 | else |
| 105 | id = explode(object_name(obj), "#")[0] + tmp; |
| 106 | if((idx = member(objs, id)) == -1) |
| 107 | { |
| 108 | objs += ({ id }); |
| 109 | info += ({ ({ tmp, 1, obj}) }); |
| 110 | } |
| 111 | else |
| 112 | info[idx][1]++; |
| 113 | } |
| 114 | |
| 115 | private string collect(mixed obj) |
| 116 | { |
| 117 | if(!sizeof(obj[0])) return 0; |
| 118 | return obj[0] + (obj[1] > 1 ? " ("+obj[1]+")" : ""); |
| 119 | } |
| 120 | |
| 121 | // flags: 1 - return array, 2 - don't collect equal objects ' |
| 122 | // flags: 4 - don't append infos for wizards |
| 123 | varargs mixed make_invlist(object viewer, mixed inv, int flags) |
| 124 | { |
| 125 | int iswiz; |
| 126 | mixed objs, info; |
| 127 | string descr; |
| 128 | |
| 129 | iswiz = IS_LEARNER( viewer ) && viewer->QueryProp(P_WANTS_TO_LEARN); |
| 130 | descr = ""; objs = ({}); info = ({}); |
| 131 | map(inv, #'stringenize/*'*/, iswiz | (flags & 2) | (flags & 4), &objs, &info); |
| 132 | if(flags & 1) return info; |
| 133 | inv = map(info, #'collect/*'*/) - ({ 0 }); |
| 134 | if(!sizeof(inv)) return ""; |
| 135 | return sprintf("%"+(sizeof(inv) > 6 ? "#" : "=")+"-78s", |
| 136 | implode(inv, "\n")) + "\n"; |
| 137 | } |