Crossfire Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CF: Beware of triggers!



On Wed, Jun 14, 2000 at 10:11:36AM +0200, Jan Echternach wrote:
> On Tue, Jun 13, 2000 at 03:15:47PM -0700, Peter Mardahl wrote:
> > 3)  The whole apparatus would reset and repeat.
> 
> > Given that 3) is more important than 2), can I fix my map so that 
> > it'll work as I intend?  What is the fix?
> 
> Implementing FLAG_LIVESAVING for normal altars.

I thought that this would only be a two line patch, but it turned out
to be much more difficult because push_button() didn't support toggling
the state of connected objects.  There were even some archetypes that
didn't support toggling because they started in an inconsistent state.

The attached patches change push_button() and archetypes to support
toggling of connected objects.  They shouldn't break anything, even
though they slightly change the behaviour of some object types.
Nevertheless, more testing is required.

Peter, would you like to try this patch with a modified HallOfQuests
map?  You only need to replace each arch altar_trigger with an arch
altar that has "lifesave 1".

-- 
Jan
diff -ru orig/crossfire-0.95.5-cvs3-patch34/common/button.c crossfire-0.95.5-cvs3/common/button.c
--- orig/crossfire-0.95.5-cvs3-patch34/common/button.c	Thu Jun  8 17:23:54 2000
+++ crossfire-0.95.5-cvs3/common/button.c	Mon Jun 19 16:16:04 2000
@@ -35,11 +35,15 @@
 /*
  * Push the specified object.  This can affect other buttons/gates/handles
  * altars/pedestals/holes in the whole map.
- * Changed the routine to loop through _all_ objects.
- * Better hurry with that linked list...
+ *
+ * mode:
+ *    0: up
+ *    1: down
+ *    2: toggle
  */
 
-void push_button(object *op) {
+void push_button (object *op, int mode)
+{
   object *tmp;
   objectlink *ol;
 
@@ -62,12 +66,19 @@
     switch(tmp->type) {
     case GATE:
     case HOLE:
-      tmp->value=tmp->stats.maxsp?!op->value:op->value;
-      tmp->speed=0.5;
-      update_ob_speed(tmp);
-      break;
+	if (mode == 2)
+	    tmp->value = ! tmp->value;
+	else
+	    tmp->value = tmp->stats.maxsp ? ! mode : mode;
+	tmp->speed = 0.5;
+	update_ob_speed(tmp);
+	break;
     case HANDLE:
-	SET_ANIMATION(tmp, (tmp->value=tmp->stats.maxsp?!op->value:op->value));
+	if (mode == 2)
+	    tmp->value = ! tmp->value;
+	else
+	    tmp->value = tmp->stats.maxsp ? ! mode : mode;
+	SET_ANIMATION (tmp, tmp->value);
 	update_object(tmp);
 	break;
     case SIGN:
@@ -79,13 +90,15 @@
 	}
 	break;
     case ALTAR:
-	tmp->value = 1;
-	SET_ANIMATION(tmp, tmp->value);
-	update_object(tmp);
+	if ( ! QUERY_FLAG (tmp, FLAG_LIFESAVE)) {
+	    tmp->value = 1;
+	    SET_ANIMATION(tmp, tmp->value);
+	    update_object (tmp);
+	}
 	break;
     case BUTTON:
     case PEDESTAL:
-	tmp->value=op->value;
+	tmp->value = (mode == 2) ? ! tmp->value : mode;
 	SET_ANIMATION(tmp, tmp->value);
 	update_object(tmp);
 	break;
@@ -111,6 +124,18 @@
     case CREATOR:
 	(*move_creator_func)(tmp);
 	break;
+    case DETECTOR:
+	if (mode == 2)
+	    tmp->value = ! tmp->value;
+	else
+	    tmp->value = (tmp->stats.sp == 1) ? mode : ! mode;
+	break;
+    case CHECK_INV:
+	if (mode == 2)
+	    tmp->value = ! tmp->value;
+	else
+	    tmp->value = tmp->last_sp ? mode : ! mode;
+	break;
     }
   }
 }
@@ -161,11 +186,8 @@
 	op->value=1;
 
     /* If this button hasn't changed, don't do anything */
-    if (op->value != old_value) {
-	SET_ANIMATION(op, op->value);
-	update_object(op);
-	push_button(op); /* Make all other buttons the same */
-    }
+    if (op->value != old_value)
+	push_button (op, op->value);
 }
 
 /*
@@ -196,10 +218,7 @@
 
 void use_trigger(object *op) 
 {
-
-    /* Toggle value */
-    op->value = !op->value;
-    push_button(op);
+    push_button (op, ! op->value);
 }
 
 /*
@@ -296,13 +315,12 @@
 void trigger_move (object *op, int state) /* 1 down and 0 up */
 {
     op->stats.wc = state;
+    push_button (op, state);
     if (state) {
-	use_trigger(op);
 	op->speed = 1.0 / op->arch->clone.stats.exp;
 	update_ob_speed(op);
 	op->speed_left = -1;
     } else {
-        use_trigger(op);
 	op->speed = 0;
 	update_ob_speed(op);
     }
@@ -611,10 +629,12 @@
     if (match && trig->last_sp) {
 	if(trig->last_heal) 
 	    decrease_ob(match);
-	use_trigger(trig);
+	if ( ! trig->value)
+            push_button (trig, 1);
     }
     else if (!match && !trig->last_sp)
-	use_trigger(trig);
+	if (trig->value)
+            push_button (trig, 0);
 }
 
 
diff -ru orig/crossfire-0.95.5-cvs3-patch34/doc/crossfire.doc crossfire-0.95.5-cvs3/doc/crossfire.doc
--- orig/crossfire-0.95.5-cvs3-patch34/doc/crossfire.doc	Tue Jun  6 16:55:18 2000
+++ crossfire-0.95.5-cvs3/doc/crossfire.doc	Mon Jun 19 16:08:49 2000
@@ -623,6 +623,8 @@
 
 hp:  If set, use hp to match to that object type.
 
+lifesave:  If unset (default), altar may only be activated once.
+
 Note:  For all sacrifice types, the number to activate the altar must be in
 one object.  Thus, in the above money example, 100 sp and 10 gp would not
 work.  Likewise, if the needed sacrifice was 2 swords, 1 normal sword and 1
diff -ru orig/crossfire-0.95.5-cvs3-patch34/include/libproto.h crossfire-0.95.5-cvs3/include/libproto.h
--- orig/crossfire-0.95.5-cvs3-patch34/include/libproto.h	Fri May 26 11:43:19 2000
+++ crossfire-0.95.5-cvs3/include/libproto.h	Mon Jun 19 15:28:36 2000
@@ -267,7 +267,7 @@
 extern object *present_in_ob ( unsigned char type, object *op );
 extern void print_los ( object *op );
 extern void print_monsters ( void );
-extern void push_button ( object *op );
+extern void push_button ( object *op, int mode );
 extern char *query_base_name ( object *op );
 extern char *query_name ( object *op );
 extern int query_refcount ( const char *str );
diff -ru orig/crossfire-0.95.5-cvs3-patch34/server/apply.c crossfire-0.95.5-cvs3/server/apply.c
--- orig/crossfire-0.95.5-cvs3-patch34/server/apply.c	Mon Jun 19 16:09:49 2000
+++ crossfire-0.95.5-cvs3/server/apply.c	Mon Jun 19 15:22:25 2000
@@ -938,10 +938,9 @@
       /* If it is connected, push the button.  Fixes some problems with
        * old maps.
        */
-      push_button (altar);
+      push_button (altar, 2);
     } else {
-      altar->value = 1;  /* works only once */
-      push_button (altar);
+      push_button (altar, 2);
     }
     return sacrifice == NULL;
   } else {
@@ -1679,10 +1671,7 @@
   case HANDLE:
     new_draw_info(NDI_UNIQUE, 0,op,"You turn the handle.");
     play_sound_map(op->map, op->x, op->y, SOUND_TURN_HANDLE);
-    tmp->value=tmp->value?0:1;
-    SET_ANIMATION(tmp, tmp->value);
-    update_object(tmp);
-    push_button(tmp);
+    push_button (tmp, ! tmp->value);
     return 1;
 
   case TRIGGER:
diff -ru orig/crossfire-0.95.5-cvs3-patch34/server/time.c crossfire-0.95.5-cvs3/server/time.c
--- orig/crossfire-0.95.5-cvs3-patch34/server/time.c	Tue Jun 13 21:29:39 2000
+++ crossfire-0.95.5-cvs3/server/time.c	Mon Jun 19 15:28:04 2000
@@ -373,27 +373,8 @@
 	    detected=1;
     }
 
-    /* the detector sets the button if detection is found */
-    if(op->stats.sp == 1)  {
-	if(detected && last == 0) {
-	    op->value = 1;
-	    push_button(op);
-	}
-	if(!detected && last == 1) {
-	    op->value = 0;
-	    push_button(op);
-	}
-    }
-    else { /* in this case, we unset buttons */
-	if(detected && last == 1) {
-	    op->value = 0;
-	    push_button(op);
-	}
-	if(!detected && last == 0) {
-	    op->value = 1;
-	    push_button(op);
-	}
-    }
+    if (detected != last)
+        push_button (op, (op->stats.sp == 1) ? detected : ! detected);
 }
 
 
diff -ru orig/arch-0.95.5-cvs1/connect/Garden_gate/gard_gate.arc arch-0.95.5-cvs1/connect/Garden_gate/gard_gate.arc
--- orig/arch-0.95.5-cvs1/connect/Garden_gate/gard_gate.arc	Mon Mar 29 06:47:49 1999
+++ arch-0.95.5-cvs1/connect/Garden_gate/gard_gate.arc	Mon Jun 19 15:58:57 2000
@@ -13,6 +13,7 @@
 hp 0
 dam 0
 maxsp 1
+value 1
 editable 16
 visibility 100
 ac 1
diff -ru orig/arch-0.95.5-cvs1/connect/Gates/gate.arc arch-0.95.5-cvs1/connect/Gates/gate.arc
--- orig/arch-0.95.5-cvs1/connect/Gates/gate.arc	Mon Mar 29 06:47:38 1999
+++ arch-0.95.5-cvs1/connect/Gates/gate.arc	Mon Jun 19 15:59:14 2000
@@ -16,6 +16,7 @@
 wc 0
 dam 1
 maxsp 1
+value 1
 editable 16
 visibility 50
 color_fg black
@@ -63,6 +64,7 @@
 hp 0
 dam 1
 maxsp 1
+value 1
 editable 16
 visibility 50
 color_fg black
diff -ru orig/arch-0.95.5-cvs1/connect/Gates/grate.arc arch-0.95.5-cvs1/connect/Gates/grate.arc
--- orig/arch-0.95.5-cvs1/connect/Gates/grate.arc	Mon Mar 29 06:47:38 1999
+++ arch-0.95.5-cvs1/connect/Gates/grate.arc	Mon Jun 19 15:59:24 2000
@@ -17,6 +17,7 @@
 wc 0
 dam 5
 maxsp 1
+value 1
 ac 1
 editable 16
 visibility 50
@@ -67,6 +68,7 @@
 hp 0
 dam 5
 maxsp 1
+value 1
 ac 1
 editable 16
 visibility 50
diff -ru orig/arch-0.95.5-cvs1/connect/Gates/iron_gate.arc arch-0.95.5-cvs1/connect/Gates/iron_gate.arc
--- orig/arch-0.95.5-cvs1/connect/Gates/iron_gate.arc	Mon Mar 29 06:47:34 1999
+++ arch-0.95.5-cvs1/connect/Gates/iron_gate.arc	Mon Jun 19 15:59:37 2000
@@ -71,6 +71,7 @@
 wc 0
 dam 6
 maxsp 1
+value 1
 editable 16
 visibility 50
 color_fg black
@@ -94,6 +95,7 @@
 hp 0
 dam 6
 maxsp 1
+value 1
 editable 16
 visibility 50
 color_fg black
diff -ru orig/arch-0.95.5-cvs1/connect/Gates/spikes.arc arch-0.95.5-cvs1/connect/Gates/spikes.arc
--- orig/arch-0.95.5-cvs1/connect/Gates/spikes.arc	Mon Mar 29 06:47:38 1999
+++ arch-0.95.5-cvs1/connect/Gates/spikes.arc	Mon Jun 19 15:59:56 2000
@@ -45,6 +45,7 @@
 wc 0
 dam 8
 maxsp 1
+value 1
 ac 1
 editable 16
 visibility 50
diff -ru orig/arch-0.95.5-cvs1/connect/stwallsec.arc arch-0.95.5-cvs1/connect/stwallsec.arc
--- orig/arch-0.95.5-cvs1/connect/stwallsec.arc	Mon Mar 29 06:47:28 1999
+++ arch-0.95.5-cvs1/connect/stwallsec.arc	Mon Jun 19 15:58:45 2000
@@ -46,6 +46,7 @@
 wc 0
 dam 6
 maxsp 1
+value 1
 editable 16
 visibility 50
 color_fg black