This is the mail archive of the xconq7@sources.redhat.com mailing list for the Xconq project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

side_controls_unit vs. tk interface


Here's the latest in the saga which started with 
http://sources.redhat.com/ml/xconq7/2000/msg00105.html - which is
basically trying to clean up the side_sees_unit vs. side_controls_unit
in tkcmd.c.  The enclosed code is similar in spirit to existing
side_controls_unit calls in tkcmd.c; it just goes more places.

I hope we can get this fixed; after the game is over my first instinct
is to start poking around the enemy units, looking at their plans and
such, and I'm getting frustrated at being thwarted.  Even enough to
write some code :-).

2000-10-05  Jim Kingdon  <http://sourceforge.net/users/kingdon>

	* tkcmd.c: Call side_controls_unit a bunch more places.

Index: tcltk/tkcmd.c
===================================================================
RCS file: /cvs/xconq/xconq/tcltk/tkcmd.c,v
retrieving revision 1.39
diff -u -r1.39 tkcmd.c
--- tkcmd.c	2000/08/24 12:21:18	1.39
+++ tkcmd.c	2000/10/06 07:05:47
@@ -88,6 +88,11 @@
 
     DURING_GAME_ONLY();
     REQUIRE_UNIT(map);
+    if (!(in_play (unit) && side_controls_unit (side, unit))) {
+	cmd_error(side, "%s cannot control %s",
+		  side_name(side), unit_handle(side, unit));
+	return;
+    }
     u = unit->type;
     numtypes = 0;
     for_all_terrain_types(t) {
@@ -241,6 +246,11 @@
 
     DURING_GAME_ONLY();
     REQUIRE_UNIT(map);
+    if (!(in_play (unit) && side_controls_unit (side, unit))) {
+	cmd_error(side, "%s cannot control %s",
+		  side_name(side), unit_handle(side, unit));
+	return;
+    }
     u = unit->type;
     if (!can_build(unit)) {
 	cmd_error(side, "%s can't build anything!", unit_handle(side, unit));
@@ -342,6 +352,9 @@
 	unit = find_unit(map->argunitid);
 	if (unit == NULL) {
 	    cmd_error(side, "Unit (#%d) disappeared!", map->argunitid);
+	} else if (!(in_play (unit) && side_controls_unit (side, unit))) {
+	    cmd_error(side, "%s cannot control %s",
+		      side_name(side), unit_handle(side, unit));
 	} else if (!inside_area(x, y)) {
 	    cmd_error(side, "%s cannot build on the edge of the world.",
 		      unit_handle(side, unit));
@@ -381,6 +394,11 @@
 
     DURING_GAME_ONLY();
     REQUIRE_UNIT(map);
+    if (!side_controls_unit (side, unit)) {
+	cmd_error(side, "%s cannot control %s",
+		  side_name(side), unit_handle(side, unit));
+	return;
+    }
     mtocollect = NONMTYPE;
     if (nummtypes == 0) {
 	cmd_error(side, "No materials to collect");
@@ -440,6 +458,11 @@
 	/* ??? can't act ??? */
 	return;
     }
+    if (!(in_play(unit) && side_controls_unit(side, unit))) {
+	cmd_error(side, "%s cannot control %s",
+		  side_name(side), unit_handle(side, unit));
+	return;
+    }
     ndirs = char_to_dir(tmpkey, &dir, NULL, NULL);
     if (ndirs < 1) {
 	cmd_error(side, "what direction is that?!?");
@@ -522,6 +545,12 @@
 	return;
     }
 
+    if (!(in_play(unit) && side_controls_unit(side, unit))) {
+	cmd_error(side, "%s cannot control %s",
+		  side_name(side), unit_handle(side, unit));
+	return;
+    }
+
     sx = map->inpsx;  sy = map->inpsy;
 
     if (nearest_cell(widget_vp(map), sx, sy, &x, &y, NULL, NULL)) {
@@ -562,6 +591,13 @@
       return;
     if (grok_position(side, map, &x, &y, NULL)) {
 	unit = find_unit(map->argunitid);
+
+	if (!(in_play(unit) && side_controls_unit(side, unit))) {
+	    cmd_error(side, "%s cannot control %s",
+		      side_name(side), unit_handle(side, unit));
+	    return;
+	}
+
 	if (x != unit->x || y != unit->y) {
 	    if (unit->act && unit->plan) { /* (should be more sophisticated?) */
 		other = unit_at(x, y);
@@ -592,6 +628,12 @@
     DURING_GAME_ONLY();
     REQUIRE_UNIT(map);
 
+    if (!side_controls_unit(side, unit)) {
+	cmd_error(side, "%s cannot control %s",
+		  side_name(side), unit_handle(side, unit));
+	return;
+    }
+
     if (inside_area(x, y)) {
 	if (x != unit->x || y != unit->y) {
 	    rslt = check_fire_into_action(unit, unit, x, y, 0, -1);
@@ -643,6 +685,11 @@
     DURING_GAME_ONLY();
     REQUIRE_UNIT(map);
     if (between(0, map->prefixarg, numsides)) {
+	if (!side_controls_unit (side, map->curunit)) {
+	    cmd_error(side, "%s cannot control %s",
+		      side_name(side), unit_handle(side, map->curunit));
+	    return;
+	}
 	side2 = side_n(map->prefixarg);
 	really_do_give_unit(map->curunit, side2);
     } else {
@@ -658,6 +705,13 @@
 
     if (cancel)
       return;
+
+    if (!side_controls_unit (side, map->curunit)) {
+	cmd_error(side, "%s cannot control %s",
+		  side_name(side), unit_handle(side, map->curunit));
+	return;
+    }
+
     if (grok_side(side, map, &side2)) {
 	really_do_give_unit(map->curunit, side2);
     } else {
@@ -823,12 +877,19 @@
       return;
     if (grok_position(side, map, &x, &y, NULL)) {
 	unit = find_unit(map->argunitid);
+
 #ifdef DESIGNERS
 	if (is_designer(side)) {
 	    net_designer_teleport(unit, x, y, NULL);
 	} else
 #endif /* DESIGNERS */
 	if (in_play(unit)) {
+	    if (!side_controls_unit (side, unit)) {
+		cmd_error(side, "%s cannot control %s",
+			  side_name(side), unit_handle(side, unit));
+		return;
+	    }
+
 	    net_set_move_to_task(unit, x, y, 0);
 	} else {
 	    beep(side);
@@ -1129,6 +1190,11 @@
 
     DURING_GAME_ONLY();
     REQUIRE_UNIT(map);
+    if (!side_controls_unit (side, unit)) {
+	cmd_error(side, "%s cannot control %s",
+		  side_name(side), unit_handle(side, unit));
+	return;
+    }
     u = unit->type;
     numtypes = 0;
     for_all_terrain_types(t) {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]