-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathattribute.c
73 lines (54 loc) · 1.71 KB
/
attribute.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* attribute.c
Copyright (C) 1994-2000 Annihilator <annihilator@muds.net>
This program is a part of ES2 mudlib. Permission is granted to use,
modify, copy or distribute this program provided this copyright notice
remains intact and subject to the restriction that this program MAY
NOT be used in any way for monetary gain.
Details of terms and conditions is available in the Copyright.ES2 file.
If you don't receive this file along with this program, write to the
primary author of ES2 mudlib: Annihilator <annihilator@muds.net>
*/
#include <dbase.h>
#include <attribute.h>
mapping attribute = ([]);
mapping query_attribute() { return attribute; }
// query_attr()
//
// returns the value of a character's attribute.
varargs int
query_attr(string what, int raw)
{
int a;
if( !mapp(attribute) || undefinedp(a=attribute[what]) ) return 0;
if( raw ) return a;
return a + (int)query_temp("apply/" + what);
}
int
set_attr(string what, int value)
{
if( !mapp(attribute) ) return 0;
if( userp(this_object())
&&( undefinedp(attribute[what])
|| value < ATTRVAL_MIN
|| value > ATTRVAL_MAX ) )
return 0;
return (attribute[what] = value);
}
varargs void
init_attribute(mapping base)
{
mapping attr;
string name;
int value;
/* 如果有設定 attribute 欄位,用其中的值作為屬性值 */
if( mapp(attr=query("attribute")) ) {
attribute = attr;
delete("attribute");
}
if( !mapp(attribute) ) attribute = allocate_mapping(NUM_ATTRIBUTES);
if( !mapp(base) || !sizeof(base) ) return;
/* 根據所給的預設值「補齊」未設定的屬性 */
foreach(name, value in base)
if( undefinedp(attribute[name]) )
attribute[name] = value;
}