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]

Fix "p" command in tcl


I've been playing with empire.g (I know, masochistic, and there is a
somewhat longer list of known issues at
http://www.panix.com/~kingdon/xconq.html).  Anyway, the first thing I
needed to fix to get anywhere is explicit production of material.  The
enclosed patch fixes various problems which show up in explicit
production as well as just the obvious enabling of the feature.

2000-12-28  Jim Kingdon  <kingdon@localhost.localdomain>

	* actions.c (distribute_material): Also transfer to any units
	within out-length/in-length range.
	* unit.c (unit_trusts_unit): Add comment.
	* tkcmd.c (do_produce): Add implementation.
	* nlang.c (task_desc): Handle TASK_PRODUCE.
	
Index: kernel/actions.c
===================================================================
RCS file: /cvs/xconq/xconq/kernel/actions.c,v
retrieving revision 1.33
diff -u -r1.33 actions.c
--- actions.c	2000/11/24 02:49:21	1.33
+++ actions.c	2000/12/29 05:25:41
@@ -1325,6 +1325,35 @@
 	      break;
 	}
     }
+    /* Then to any unit within range.  This in addition to the above
+       code for adjacent cells because the latter does not check in-length
+       and out-length.  Question: why not?  FIXME in general: why is
+       the algorithm here so different from run_economy?  Should
+       perhaps merge some of the code or at least ideas.  But I'm not
+       sure run_economy is quite right either in terms of making sure
+       that it transfers supplies rather than losing them due to
+       being full.  */
+    if (amt > 0) {
+	int dist;
+	for_all_cells_within_range(unit->x, unit->y, 
+				   um_outlength (unit->type, m), x1, y1) {
+	    if (!inside_area(x1, y1))
+		continue;
+	    if (!terrain_visible(unit->side, x1, y1))
+		continue;
+	    dist = distance(unit->x, unit->y, x1, y1);
+	    for_all_stack(x1, y1, unit2) {
+		if (is_active(unit2)
+		    && unit_trusts_unit(unit, unit2)
+		    && um_inlength (unit2->type, m) >= dist) {
+		    amt = give_away (unit2, m, amt);
+		    if (amt == 0)
+			goto done;
+		    }
+	    }
+	}
+    }
+ done:;
 }
 
 /* Give as much as possible of the given material to the unit,
Index: kernel/nlang.c
===================================================================
RCS file: /cvs/xconq/xconq/kernel/nlang.c,v
retrieving revision 1.40
diff -u -r1.40 nlang.c
--- nlang.c	2000/12/18 16:50:48	1.40
+++ nlang.c	2000/12/29 05:26:27
@@ -2163,6 +2163,10 @@
 	/* (should display as calendar time) */
 	tprintf(buf, "for %d turns", arg0);
 	break;
+      case TASK_PRODUCE:
+	tprintf(buf, "%s (%d/%d)", mtypes[task->args[0]].name, task->args[2],
+		task->args[1]);
+	break;
       default:
 	/* Default is just to dump out the raw data about the task. */
 	tprintf(buf, "raw");
Index: kernel/unit.c
===================================================================
RCS file: /cvs/xconq/xconq/kernel/unit.c,v
retrieving revision 1.37
diff -u -r1.37 unit.c
--- unit.c	2000/12/18 16:50:49	1.37
+++ unit.c	2000/12/29 05:27:24
@@ -1495,6 +1495,7 @@
     return rslt;
 }
 
+/* Return true if unit1 trusts unit2.  */
 int
 unit_trusts_unit(Unit *unit1, Unit *unit2)
 {
Index: tcltk/tkcmd.c
===================================================================
RCS file: /cvs/xconq/xconq/tcltk/tkcmd.c,v
retrieving revision 1.44
diff -u -r1.44 tkcmd.c
--- tkcmd.c	2000/12/18 16:50:50	1.44
+++ tkcmd.c	2000/12/29 05:28:45
@@ -1029,7 +1029,26 @@
 void
 do_produce(Side *side)
 {
-    cmd_error(side, "Not implemented.");
+    int m, n;
+    Map *map = side->ui->curmap;
+    Unit *unit = map->curunit;
+
+    if (!require_unit(map))
+	return;
+
+    if (!can_produce(unit)) {
+	cmd_error(side, "cannot do active production");
+    }
+    n = 9999;
+    if (map->prefixarg > 0)
+	n = map->prefixarg;
+    /* Find the first produceable type and set up to produce it. */
+    for_all_material_types(m) {
+	if (um_acp_to_produce(unit->type, m) > 0) {
+	    net_push_produce_task(unit, m, n);
+	    return;
+	}
+    }
 }
 
 void

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