Generally use NULL instead of explicitly casting 0 to some pointer type (part2).
[dragonfly.git] / games / hack / hack.wield.c
CommitLineData
984263bc
MD
1/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2/* hack.wield.c - version 1.0.3 */
3/* $FreeBSD: src/games/hack/hack.wield.c,v 1.4 1999/11/16 10:26:38 marcel Exp $ */
c7106d58 4/* $DragonFly: src/games/hack/hack.wield.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */
984263bc
MD
5
6#include "hack.h"
7extern struct obj zeroobj;
8
c7106d58
PA
9void
10setuwep(struct obj *obj)
11{
984263bc
MD
12 setworn(obj, W_WEP);
13}
14
c7106d58
PA
15int
16dowield(void)
984263bc
MD
17{
18 struct obj *wep;
19 int res = 0;
20
21 multi = 0;
22 if(!(wep = getobj("#-)", "wield"))) /* nothing */;
23 else if(uwep == wep)
24 pline("You are already wielding that!");
25 else if(uwep && uwep->cursed)
26 pline("The %s welded to your hand!",
27 aobjnam(uwep, "are"));
28 else if(wep == &zeroobj) {
29 if(uwep == 0){
30 pline("You are already empty handed.");
31 } else {
902ec341 32 setuwep(NULL);
984263bc
MD
33 res++;
34 pline("You are empty handed.");
35 }
36 } else if(uarms && wep->otyp == TWO_HANDED_SWORD)
37 pline("You cannot wield a two-handed sword and wear a shield.");
38 else if(wep->owornmask & (W_ARMOR | W_RING))
39 pline("You cannot wield that!");
40 else {
41 setuwep(wep);
42 res++;
43 if(uwep->cursed)
44 pline("The %s %s to your hand!",
45 aobjnam(uwep, "weld"),
46 (uwep->quan == 1) ? "itself" : "themselves"); /* a3 */
47 else prinv(uwep);
48 }
49 return(res);
50}
51
c7106d58
PA
52void
53corrode_weapon(void)
54{
984263bc
MD
55 if(!uwep || uwep->olet != WEAPON_SYM) return; /* %% */
56 if(uwep->rustfree)
57 pline("Your %s not affected.", aobjnam(uwep, "are"));
58 else {
59 pline("Your %s!", aobjnam(uwep, "corrode"));
60 uwep->spe--;
61 }
62}
63
c7106d58
PA
64bool
65chwepon(struct obj *otmp, int amount)
984263bc 66{
fd2d026f 67 const char *color = (amount < 0) ? "black" : "green";
c7106d58 68 const char *ltime;
fd2d026f 69
984263bc
MD
70 if(!uwep || uwep->olet != WEAPON_SYM) {
71 strange_feeling(otmp,
72 (amount > 0) ? "Your hands twitch."
73 : "Your hands itch.");
74 return(0);
75 }
76
77 if(uwep->otyp == WORM_TOOTH && amount > 0) {
78 uwep->otyp = CRYSKNIFE;
79 pline("Your weapon seems sharper now.");
80 uwep->cursed = 0;
81 return(1);
82 }
83
84 if(uwep->otyp == CRYSKNIFE && amount < 0) {
85 uwep->otyp = WORM_TOOTH;
86 pline("Your weapon looks duller now.");
87 return(1);
88 }
89
90 /* there is a (soft) upper limit to uwep->spe */
91 if(amount > 0 && uwep->spe > 5 && rn2(3)) {
92 pline("Your %s violently green for a while and then evaporate%s.",
93 aobjnam(uwep, "glow"), plur(uwep->quan));
94 while(uwep) /* let all of them disappear */
95 /* note: uwep->quan = 1 is nogood if unpaid */
96 useup(uwep);
97 return(1);
98 }
99 if(!rn2(6)) amount *= 2;
c7106d58 100 ltime = (amount*amount == 1) ? "moment" : "while";
984263bc 101 pline("Your %s %s for a %s.",
c7106d58 102 aobjnam(uwep, "glow"), color, ltime);
984263bc
MD
103 uwep->spe += amount;
104 if(amount > 0) uwep->cursed = 0;
105 return(1);
106}