blob: d71e14cd2d4dde2b21c9ef22ebdcbbf21c4a1d9a [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// player/restrictions.c -- container aspect of players
4//
5// $Id: restrictions.c 9020 2015-01-10 21:49:41Z Zesstra $
6
7// This is a simple container to put objects in. It defines all functions
8// which are necessary to describe an object which can be filled with
9// other things.
10//
11// It will support restrictions for volume, weight etc.
12//
13// The following properties are defined:
14// P_MAX_WEIGHT - maximum weight which container can carry
15// P_WEIGHT_CONTENTS - current contents
16// P_WEIGHT - builtin property: read->total weight, write->own weight
17//
18// Functions for manipulation of weight
19// MayAddWeight(weight) - Can <weight> be inserted?
20// AddWeight(weight) - Add an amount of <weight>
21//
22// IMPORTANT: unit should be interpreted as grams (g).
23#pragma strong_types
24#pragma save_types
25#pragma range_check
26#pragma no_clone
27#pragma pedantic
28
29inherit "/std/container/restrictions";
30
31#define NEED_PROTOTYPES
32#include <thing/properties.h>
33#include <hook.h>
34#include <living/skills.h>
35#include <attributes.h>
36#undef NEED_PROTOTYPES
37#include <properties.h>
38#include <wizlevels.h>
39#include <container.h>
40#include <defines.h>
41#include <new_skills.h>
42
43//Liste von Objekten, in denen InsertNotify() gerufen wird, wenn etwas in den
44//Spieler bewegt wurde.
45nosave object *InsertHooks=({});
46
47// local properties prototypes
48static int _query_max_weight();
49static mixed _set_frog(mixed arg);
50
51void create()
52{
53 ::create();
54
55 Set(P_MAX_WEIGHT, NOSETMETHOD, F_SET_METHOD);
56 Set(P_MAX_WEIGHT, SECURED, F_MODE);
57 offerHook(H_HOOK_INSERT, 1);
58}
59
60// **** local property methods
61static int _query_max_weight() {
62 int str,val;
63 mixed ski;
64
65 if (QueryProp(P_GHOST) && !IS_WIZARD(ME))
66 return 0;
67 str=QueryAttribute(A_STR);
68 ski = UseSkill(SK_CARRY, ([SI_SKILLARG : str ]));
69
70 if (!intp(ski))
71 ski = 0;
72
73 if (str<0) {
74 val=9200+str*160+(int)ski;
75 if (val<3000) val=3000;
76 return val;
77 }
78 val = 9200+str*800+(int)ski;
79 if (val<3000)
80 val = 3000;
81 return val;
82}
83
84static mixed _set_frog(mixed arg) {
85 mixed res;
86
87 res=Set(P_FROG,arg);
88 if (res)
89 SetProp(P_ATTRIBUTES_MODIFIER,({"#frosch",([A_STR:-30])}));
90 else
91 SetProp(P_ATTRIBUTES_MODIFIER,({"#frosch",0 }));
92 return res;
93}
94
95public void NotifyInsert(object ob, object oldenv)
96{
97 ::NotifyInsert(ob, oldenv);
98 // Alle Listener im neuen Hooksystem vom InsertHook informieren
99 HookFlow(H_HOOK_INSERT, ob);
100 // Alle Listener im alten InsertHook informieren
101 if (sizeof(InsertHooks))
102 {
103 foreach(object h: &InsertHooks)
104 {
105 if (h && environment(h) == ME)
106 h->InsertNotify(ob);
107 else
108 h=0;
109 }
110 InsertHooks-=({0}); // genullte Elemente loeschen
111 }
112}
113
114void AddInsertHook(object ob)
115{
116 if (member(InsertHooks,ob)!=-1 || environment(ob)!=this_object())
117 return;
118 InsertHooks+=({ob});
119}
120
121void RemoveInsertHook(object ob)
122{
123 InsertHooks-=({ob});
124}
125
126object *QueryInsertHooks()
127{
128 return InsertHooks;
129}
130