File: stats-extract

package info (click to toggle)
crossfire 1.11.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 24,456 kB
  • ctags: 7,800
  • sloc: ansic: 80,483; sh: 11,825; perl: 2,327; lex: 1,946; makefile: 1,149
file content (111 lines) | stat: -rw-r--r-- 2,884 bytes parent folder | download | duplicates (8)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# stats-extract - parse the archetypes-file and output the
# player's stats in a structured format.

# Variables passed when invoked:
#   living_c - filename where the array attacks is defined.

BEGIN {
	# These stats will be added to the "magik" string according
	# to the pattern. "%s" should be "%+d", but that isn't 
	# portable.
	magic["luck"] = "luck %s";
	magic["exp"] = "speed %s";
	magic["sp"] = "spell-point regeneration %s";
	magic["hp"] = "hit-point regeneration %s";
	magic["dam"] = "damage %s";
	magic["ac"] = "ac %d";
	magic["armour"] = "armour %s";

	magic["reflect_spell"] = "reflect spells";
	magic["xrays"] = "X-ray vision";
	magic["stealth"] = "stealth";
	magic["flying"] = "flying";

	# Read the attack-types (and immune/protection)
	while ((getline buff < living_c) == 1) {
		if (buff ~ /attacks\[/) {
			att = 0;
			while (1) {
				getline buff < living_c;
				if (buff ~ "^}")
					break;
				gsub("[ \t]*\"", "", buff);
				nr = split(buff, arr, ",");
				for (i = 1; i <= nr && arr[i]; i++)
					attack[++att] = arr[i];
			}
			break;
		}
	}
	close(living_c);
}

/^Object/ {
	slay = magik = "";
	name = obj = $2;
	type = weight = last_sp = 0;
	att = prot = immune = 0;
	stat["Str"] = stat["Dex"] = stat["Con"] = 0;
	stat["Int"] = stat["Wis"] = stat["Cha"] = 0;
	stat["Pow"] = 0;
	
}

/^Str|^Dex|^Con|^Int|^Wis|^Cha|^Pow/	{ stat[$1] = $2; next }

$1 in magic	{ add_magik(magic[$1], $2) }

/^type/		{ type = $2 }
/^last_sp/	{ last_sp = $2 }
/^weight/	{ weight = $2 }
/^attacktype/	{ att = $2 }
/^protected/	{ prot = $2 }
/^immune/	{ immune = $2 }
/^slaying/	{ slay = $2; }
/^name/		{ name = substr($0, 6) }

/^end/ {
	if (type == 1) {	# Players
		if (att % 2) --att;	# Skip physical attack
		magik = magik attacktype(att , "Attacks:");
		magik = magik attacktype(prot, "Protected:");
		magik = magik attacktype(immune, "Immune:");
		if (slay)
			magik = magik "<br> " capitalize(slay=="wall" ? "excavation" : slay "-slaying");

#		sub("^\\\\newline ", "", magik); 
		magik = capitalize(magik);
		name = capitalize(name);
		sub("_", " ", name);
		printf("<tr><th>%s</th><td>~~%s~~</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%s</td></tr>\n",
		       name, obj,
		       20+stat["Str"], 20+stat["Dex"], 20+stat["Con"], 
		       20+stat["Int"], 20+stat["Wis"], 20+stat["Cha"],
		       20+stat["Pow"], magik);
	}
}

END {
	close("items");
}


# Given a bitmask, give a string enumerating the meaning of the bits.
function attacktype(at, type,   i, str) {
	for (i = 1; i in attack; i++) {
		if (at % 2)
			str = (str ? str ", " : "") attack[i];
		at = int(at/2);
	}
	return str ? "<br> " type " " str : "";
}

function add_magik(str, val) {
	str = sprintf(str, val < 0 ? val : "+" val);	
	if (str)
		magik = magik ? magik ", " str : str;
}

function capitalize(str) {
	return toupper(substr(str, 1, 1)) substr(str, 2);
}