Monsters will only accept gifts if they are slightly interested in you. Monster inter...
[rogue-pphs.git] / romance.c
index a47b897..7f5da0c 100644 (file)
--- a/romance.c
+++ b/romance.c
 #include <string.h>
 #include "rogue.h"
 
+count_bits_set(v)
+unsigned v; // count bits set in this (32-bit value)
+{
+    unsigned c = v - ((v >> 1) & 0x55555555);
+    c = ((c >> 2) & 0x33333333) + (c & 0x33333333);
+    c = ((c >> 4) + c) & 0x0F0F0F0F;
+    c = ((c >> 8) + c) & 0x00FF00FF;
+    c = ((c >> 16) + c) & 0x0000FFFF;
+    return c;
+}
+
 /*
  * flirt:
  *     Make eyes in the given direction
 flirt(ydelta, xdelta)
 int ydelta, xdelta;
 {
-    register struct linked_list *item;
+    register struct linked_list *mob;
     struct object obj = {};
 
     obj.o_pos = hero;
     obj.o_type = '~';
     do_motion(&obj, ydelta, xdelta);
     mvwaddch(cw, hero.y, hero.x, PLAYER);
-    if ((item = find_mons(obj.o_pos.y, obj.o_pos.x)) == NULL)
+    if ((mob = find_mons(obj.o_pos.y, obj.o_pos.x)) == NULL)
     {
         const char *msgs[] = {
             "You wink at nothing in particular.",
@@ -38,7 +49,42 @@ int ydelta, xdelta;
             "Unprompted, you suddenly blush.",
         };
         msg(rndchoice(msgs));
-        return;
+    }
+    else
+    {
+        register struct thing *tp = (struct thing *) ldata(mob);
+        int attr = count_bits_set(tp->t_stats.s_ont ^ player.t_stats.s_ont);
+        attr += tp->t_stats.s_int - 2;
+        if (rnd(NUM_FEATURES) < attr)
+        {
+            tp->t_stats.s_int++;
+            const char *msgs[] = {
+                "The %s smiles back at you.",
+                "You catch the %s staring at you out of the corner of eir eye.",
+                "The %s blushes and waves cautiously.",
+            };
+            msg(rndchoice(msgs), monsters[tp->t_type - 'A'].m_name);
+        }
+        else if (attr <= 0)
+        {
+            tp->t_stats.s_int--;
+            const char *msgs[] = {
+                "The %s scowls at you.",
+                "The %s tells you to stop it.",
+                "The %s is sick of your crap.",
+            };
+            msg(rndchoice(msgs), monsters[tp->t_type - 'A'].m_name);
+        }
+        else
+        {
+            const char *msgs[] = {
+                "The %s ignores you.",
+                "The %s is completely uninterested in you.",
+                "The %s acts like it can't hear you.",
+                "The %s doesn't care.",
+            };
+            msg(rndchoice(msgs), monsters[tp->t_type - 'A'].m_name);
+        }
     }
 }
 
@@ -49,7 +95,7 @@ int ydelta, xdelta;
     register struct linked_list *mob;
     register struct object *op;
     register struct thing *tp;
-    register bool did_hit = TRUE;
+    register int liking;
 
     if ((mob = find_mons(hero.y + ydelta, hero.x + xdelta)) == NULL)
     {
@@ -63,6 +109,42 @@ int ydelta, xdelta;
     op = (struct object *) ldata(obj);
     if (!dropcheck(op))
        return;
+
+    liking = count_bits_set(
+        hash((op->o_type << 4) ^ op->o_which) & tp->t_stats.s_ont) - 1;
+    if (liking == 0
+        || liking > 0 && tp->t_stats.s_int <= MAYBE_INTERESTED)
+    {
+        const char *msgs[] = {
+            "The %s ignores %s",
+            "The %s isn't interested in %s",
+        };
+        msg(rndchoice(msgs), monsters[tp->t_type - 'A'].m_name,
+            inv_name(op, TRUE));
+        return;
+    }    
+    else if (liking > 0)
+    {
+        const char *msgs[] = {
+            "The %s accepts %s.",
+            "The %s takes %s.",
+        };
+        msg(rndchoice(msgs), monsters[tp->t_type - 'A'].m_name,
+            inv_name(op, TRUE));
+        tp->t_stats.s_int += liking * 10;
+    }
+    else if (liking < 0)
+    {
+        const char *msgs[] = {
+            "The %s throws away %s.",
+            "The %s breaks %s.",
+            "The %s hates %s.",
+        };
+        msg(rndchoice(msgs), monsters[tp->t_type - 'A'].m_name,
+            inv_name(op, TRUE));
+        tp->t_stats.s_int -= liking * 2;
+    }
+    
     /*
      * Take it out of the pack
      */