File: treas2-extract

package info (click to toggle)
crossfire 1.75.0-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,168 kB
  • sloc: ansic: 83,169; sh: 4,659; perl: 1,736; lex: 1,443; makefile: 1,199; python: 43
file content (97 lines) | stat: -rw-r--r-- 2,753 bytes parent folder | download | duplicates (6)
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
# treas-extract - parse the treasures-file and output the
# player's stats in a structured format.

# read in the list of player randomitems from randitem
BEGIN {
	# yeah, its kludgey, but hey, I've been programming awk for
	# all of 1 day!

	ignoreitem["ability_fire"] = 1;
	ignoreitem["magic"] = 1;
	ignoreitem["more"] = 1;
	ignoreitem["basic_skills"] = 1;
	ignoreitem["wizard_skills"] = 1;
	ignoreitem["spell_skills"] = 1;
	ignoreitem["priest_skills"] = 1;
	ignoreitem["fighter_skills"] = 1;
	ignoreitem["random_knowledge"] = 1;
	ignoreitem["player_force"] = 1;
	ignoreitem["nrof"] = 1;
	ignoreitem["no_class_face_change"] = 1;

	plural["arrow"] = 1;

	newname["mage_skills"] = "talisman";
	newname["nunchacu_1"] = "nunchacu";
	newname["r_sack"] = "ruck sack";
	newname["cleric_book"] = "prayer book";
	newname["book"] = "spell book";

       # Read the player treasure types
	pl = 0;
        while ((getline buff < eqitems) == 1) {
		nr = split(buff, line, ",");
                player[pl] = line[1];
                list[pl] = line[2];
		pl++;
        }
        close(playerlist);

}

$1 == "treasure" {
       	for ( i=0; i < pl ; i++ ) {
	    	  if ($2 == list[i]) {  # matched players list
			nrloop=0;
			do {
			  getline;
			  if($1 in ignoreitem) continue;
			  if($1 == ("yes"||"no")) {
				nrloop++;
				continue;
			  } else if($1 == "end") {
				if(nrloop==0) { break; } else { nrloop--; }
				continue;
			  }
			  if($2 ~ "^skill") continue;
			  if($2 ~ "^abil") continue;
			  if($2 ~ "force$") continue;
			  if($2 in ignoreitem) continue;
			  equip = $2;
			  if(equip in plural) equip = sprintf("%ss",equip);
			  if(equip in newname) equip = newname[equip];
			  equiplist[i] = sprintf("%s,%s",equiplist[i],equip);
		        } while ( $1 != ("treasure" || "treasureone" || "list" ) )
	    	  }
	}
}

END {
	close("trease");
	# now print this stuff out in correct order!
        for(i=0;i<pl;i++) {
                printf("%s & ",capitalize(player[i]));
                nr = split(equiplist[i], eq, ",");
		if(nr==0) {
	      # hmm. This can happen if 2 or more character classes
	      # share the same treaure list. Lets find it.
		   for(j=0;j<pl;j++)
			if(list[i]==list[j]) break;
                   nr = split(equiplist[j], eq, ",");
		}
                gsub("_", " ", eq[nr]);
                printf("%s",capitalize(eq[nr--]));
                do {
                        printf(", ");
                        gsub("_", " ", eq[nr]);
                        # printf("& %s\\\\\n",capitalize(eq[nr]));
                        printf("%s",capitalize(eq[nr]));
                } while (--nr>1);
                printf(" \\\\\n");
        }
}

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