Another 64 bit issue.
[rogue-pphs.git] / romance.c
1 /*
2 * Functions for dealing with problems of the heart
3 *
4 * @(#)romance.c 3.2 (Berkeley) 6/15/81
5 *
6 * Rogue: Exploring the Cavern of Cuties
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
8 * All rights reserved.
9 *
10 * See the file LICENSE.TXT for full copyright and licensing information.
11 */
12
13 #include "curses.h"
14 #include <ctype.h>
15 #include <string.h>
16 #include "rogue.h"
17
18 count_bits_set(v)
19 unsigned v; // count bits set in this (32-bit value)
20 {
21 unsigned c = v - ((v >> 1) & 0x55555555);
22 c = ((c >> 2) & 0x33333333) + (c & 0x33333333);
23 c = ((c >> 4) + c) & 0x0F0F0F0F;
24 c = ((c >> 8) + c) & 0x00FF00FF;
25 c = ((c >> 16) + c) & 0x0000FFFF;
26 return c;
27 }
28
29 /*
30 * flirt:
31 * Make eyes in the given direction
32 */
33
34 flirt(ydelta, xdelta)
35 int ydelta, xdelta;
36 {
37 register struct linked_list *mob;
38 struct object obj = {};
39
40 obj.o_pos = hero;
41 obj.o_type = '~';
42 do_motion(&obj, ydelta, xdelta);
43 mvwaddch(cw, hero.y, hero.x, PLAYER);
44 if ((mob = find_mons(obj.o_pos.y, obj.o_pos.x)) == NULL)
45 {
46 const char *msgs[] = {
47 "You wink at nothing in particular.",
48 "You smile suggestively at the wall.",
49 "Unprompted, you suddenly blush.",
50 };
51 msg(rndchoice(msgs));
52 }
53 else
54 {
55 register struct thing *tp = (struct thing *) ldata(mob);
56 int attr = count_bits_set(tp->t_stats.s_ont ^ player.t_stats.s_ont);
57 attr += tp->t_stats.s_int - 2;
58 if (rnd(NUM_FEATURES) < attr)
59 {
60 tp->t_stats.s_int++;
61 const char *msgs[] = {
62 "The %s smiles back at you.",
63 "You catch the %s staring at you out of the corner of eir eye.",
64 "The %s blushes and waves cautiously.",
65 };
66 msg(rndchoice(msgs), killname(tp->t_type));
67 }
68 else if (attr <= 0)
69 {
70 tp->t_stats.s_int--;
71 const char *msgs[] = {
72 "The %s scowls at you.",
73 "The %s tells you to stop it.",
74 "The %s is sick of your crap.",
75 };
76 msg(rndchoice(msgs), killname(tp->t_type));
77 }
78 else
79 {
80 const char *msgs[] = {
81 "The %s ignores you.",
82 "The %s is completely uninterested in you.",
83 "The %s acts like it can't hear you.",
84 "The %s doesn't care.",
85 };
86 msg(rndchoice(msgs), killname(tp->t_type));
87 }
88 }
89 }
90
91 gift(ydelta, xdelta)
92 int ydelta, xdelta;
93 {
94 register struct linked_list *obj, *nobj;
95 register struct linked_list *mob;
96 register struct object *op;
97 register struct thing *tp;
98 register int liking;
99
100 if ((mob = find_mons(hero.y + ydelta, hero.x + xdelta)) == NULL)
101 {
102 msg("There's no-one around here.");
103 return(0);
104 }
105 tp = (struct thing *) ldata(mob);
106
107 if ((obj = get_item("give", 0)) == NULL)
108 return;
109 op = (struct object *) ldata(obj);
110 if (!dropcheck(op))
111 return;
112
113 liking = count_bits_set(
114 hash((op->o_type << 4) ^ op->o_which) & tp->t_stats.s_ont) - 1;
115 if (liking == 0
116 || liking > 0 && tp->t_stats.s_int <= MAYBE_INTERESTED)
117 {
118 const char *msgs[] = {
119 "The %s ignores %s",
120 "The %s isn't interested in %s",
121 };
122 msg(rndchoice(msgs), killname(tp->t_type), inv_name(op, TRUE));
123 return;
124 }
125 else if (liking > 0)
126 {
127 const char *msgs[] = {
128 "The %s accepts %s.",
129 "The %s takes %s.",
130 };
131 msg(rndchoice(msgs), killname(tp->t_type), inv_name(op, TRUE));
132 tp->t_stats.s_int += liking * 10;
133 }
134 else if (liking < 0)
135 {
136 const char *msgs[] = {
137 "The %s throws away %s.",
138 "The %s breaks %s.",
139 "The %s hates %s.",
140 };
141 msg(rndchoice(msgs), killname(tp->t_type), inv_name(op, TRUE));
142 tp->t_stats.s_int -= liking * 2;
143 }
144
145 /*
146 * Take it out of the pack
147 */
148 if (op->o_count >= 2 && op->o_type != WEAPON)
149 {
150 nobj = new_item(sizeof *op);
151 op->o_count--;
152 op = (struct object *) ldata(nobj);
153 *op = *((struct object *) ldata(obj));
154 op->o_count = 1;
155 obj = nobj;
156 if (op->o_group != 0)
157 inpack++;
158 }
159 else
160 detach(pack, obj);
161 inpack--;
162 }
163
164 embrace()
165 {
166 register struct thing *tp = NULL;
167 register int liking;
168 register int dx, dy;
169
170 for (dx = -1; dx <= 1; ++dx)
171 {
172 for (dy = -1; dy <= 1; ++dy)
173 {
174 register struct linked_list *mob;
175 if ((mob = find_mons(hero.y + dy, hero.x + dx)))
176 {
177 register struct thing *atp = (struct thing *)ldata(mob);
178 if (!tp || atp->t_stats.s_int > tp->t_stats.s_int)
179 tp = atp;
180 }
181 }
182 }
183
184
185 if (tp == NULL)
186 {
187 msg("You wrap your arms around yourself.");
188 return;
189 }
190 else if (tp->t_stats.s_int < INTERESTED)
191 {
192 if (tp->t_stats.s_int > 0)
193 tp->t_stats.s_int /= 2;
194 else
195 tp->t_stats.s_int--;
196 msg("The %s dodges out of the way.", killname(tp->t_type));
197 return;
198 }
199
200 if (amulet)
201 {
202 total_winner(tp->t_type);
203 }
204 else
205 {
206 mostly_winner(tp->t_type);
207 }
208 }