[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus contrib/msvc.zip doc/ChangeLog.html d...
From: |
Crestez Leonard |
Subject: |
[Stratagus-CVS] stratagus contrib/msvc.zip doc/ChangeLog.html d... |
Date: |
Wed, 10 Sep 2003 04:44:38 -0400 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Crestez Leonard <address@hidden> 03/09/10 04:44:37
Modified files:
contrib : msvc.zip
doc : ChangeLog.html
doc/ccl : unittype.html
src/action : action_resource.c actions.c
src/ai : ai_building.c ai_resource.c
src/clone : unit.c
src/include : unit.h unittype.h
src/ui : mouse.c
Log message:
Resource code mostly. and docs. and a patch from jim4.
Patches:
Index: stratagus/contrib/msvc.zip
Index: stratagus/doc/ChangeLog.html
diff -u stratagus/doc/ChangeLog.html:1.522 stratagus/doc/ChangeLog.html:1.523
--- stratagus/doc/ChangeLog.html:1.522 Fri Sep 5 14:10:55 2003
+++ stratagus/doc/ChangeLog.html Wed Sep 10 04:44:36 2003
@@ -2,7 +2,7 @@
<html>
<head>
<!--
----- $Id: ChangeLog.html,v 1.522 2003/09/05 18:10:55 n0body Exp $
+---- $Id: ChangeLog.html,v 1.523 2003/09/10 08:44:36 n0body Exp $
---- (c) Copyright 1998-2003 by Lutz Sammer
@@ -36,6 +36,9 @@
<li>Future 1.19 Release<p>
<ul>
<li>++
+ <li>Fixed bug #5116 on lose-resource option (from Crestez Leonard).
+ <li>Fixed Ai resource gathering (and bug #5180) (from Crestez Leonard).
+ <li>Applied patch #1885, updated msvc project files (from Jimmy Salmon).
<li>New resource harvesting, no hardcoded unit types (from Crestez
Leonard).
<li>NEW_UI: Fixed save/load (from Martin Renold).
<li>Pathfinder fixes for when the goal moves (EXPERIMENTAL) (from Russell
Smith).
Index: stratagus/doc/ccl/unittype.html
diff -u stratagus/doc/ccl/unittype.html:1.24
stratagus/doc/ccl/unittype.html:1.25
--- stratagus/doc/ccl/unittype.html:1.24 Wed Sep 3 05:27:51 2003
+++ stratagus/doc/ccl/unittype.html Wed Sep 10 04:44:36 2003
@@ -186,7 +186,7 @@
<dl>
<dt>name</dt>
<dd>The unit-type name shown in the game. F.E: "Knight", "Gold Mine".
-If the name is too long, it is split at space.
+If the name is too long, it is split at space.<p>
</dd>
<dd></dd>
<dt>graphics</dt>
@@ -212,16 +212,16 @@
</dd>
<dt>pixel_size</dt>
<dd>Size of the unit-type graphic in pixeln. A list of X (width) and Y (height)
-sizes. F.E. '( 72 72 ), '( 96 96 ).</dd>
+sizes. F.E. '( 72 72 ), '( 96 96 ).<p></dd>
<dt>animations</dt>
<dd>Identifier to reference the animation sequences (scripts) for the
-unit-type. F.E. "animations-knight", "animations-gold-mine".</dd>
+unit-type. F.E. "animations-knight", "animations-gold-mine".<p></dd>
<dt>icon</dt>
<dd>Identifier to reference the icon shown in game for this unit-type.
-F.E. "icon-knight", "icon-gold-mine".</dd>
+F.E. "icon-knight", "icon-gold-mine".<p></dd>
<dt>speed</dt>
<dd>The speed shown for this unit-type in game. (NOTE: this is
-only shown and *not* used). F.E. 10, 13.</dd>
+only shown and *not* used). F.E. 10, 13.<p></dd>
<dt>overlay</dt>
<dd>Define the overlay shown if this unit is constructed (build).
Currently are available:
@@ -238,14 +238,15 @@
<li>15 wall construction site
</ul>
NOTE: this will be changed to identifiers sometime.
-</dd>
+<p></dd>
<dt>sight_range</dt>
-<dd>Sight range (in tiles) of this unit. F.E. 6, 14.</dd>
+<dd>Sight range (in tiles) of this unit. F.E. 6, 14.<p></dd>
<dt>hitpoints</dt>
-<dd>Hitpoints for this Unit. F.E. 90, 1000</dd>
+<dd>Hitpoints for this Unit. F.E. 90, 1000<p></dd>
<dt>magic</dt>
<dd>Flag to determine whether this unit is a spell user. 0 = false (not a magic
-user), 1 = true (magic user). F.E. 1, 0</dd>
+user), 1 = true (magic user). F.E. 1, 0<p>
+</dd>
<dt>costs</dt>
<dd>Define the costs to build (or aquire) this unit. It is an array of '(
resource-name amount) pairs. Time is in frames to build this unit.
@@ -254,11 +255,12 @@
F.E.: '( time 200 gold 2000 wood 1000 oil 200 ).<p>
</dd>
<dt>improve_production</dt>
-<dd>Define the production increase from defaults that this unit adds. It is an
array of '(
-resource-name amount) pairs.
-Gold is the amount it increase the default gold by. All other defined
resources are
-treated the same way.
-F.E.: 'improve-production '( gold 20 wood 5 ).<p>
+<dd>Define the production increase from defaults that this unit adds. It is an
+array of '(resource-name amount) pairs. Gold is the amount it increase the
+default gold by. All other defined resources are treated the same way. The
+values are treated like percents. Improvement from multiple buildings do
+not stack, but the maximum is what matters.
+F.E.: 'improve-production '( gold 20 wood 5 ) will give 120% gold and 105%
wood.<p>
</dd>
<dt>repair_hp</dt>
<dd>Defines the amount of hp a unit gain for each repair animation. Units can
only be
@@ -272,10 +274,56 @@
Wood and Oil are the same.
F.E.: '( gold 2 wood 1 oil 1 ).<p>
</dd>
+<dt>can-gather-resource</dt>
+<dd>This will begin a block of resoure gathering information. The folowing
tags are available in this section:<p></dd>
+<!-- Indent this whole block, it pertains to can-gather resource -->
+ <dt>resource-id</dt>
+ <dd>The resource identification. Has to be a resource-name defined
before.<p></dd>
+
+ <dt>final-resource</dt>
+ <dd>The resource is converted to this at the depot. Usefull for a
fisherman who harvests fish,
+ but it all turns to food at the depot. Warning: curently ignored by the
Ai.<p></dd>
+
+ <dt>wait-at-resource</dt>
+ <dd>Cycles the unit waits while inside at a resource to get one resource
step
+ (see below). This is completely independent of animation length and
such.<p></dd>
+
+ <dt>wait-at-depot</dt>
+ <dd>Cycles the unit waits while inside the depot to unload.<p></dd>
+
+ <dt>resource-step</dt>
+ <dd>The unit makes so-caled mining cycles. Each mining cycle it does some
sort
+ of animation and gains resource-step resources. You can stop after any
number of
+ steps. When the quantity in the harvester reaches the maximum
(resource-capacity)
+ it will return home. I this is not included then it's considered infinity,
and
+ resource-capacity will be the limit.<p></dd>
+
+ <dt>resource-capacity</dt>
+ <dd>Maximum amount of resources a harvester can carry. The actual amount
can be
+ modified while unloading, with improve_incomes.<p></dd>
+
+ <dt>file-when-loaded</dt>
+ <dd>The harvester's animation file will change when it's loaded.<p></dd>
+
+ <dt>file-when-empty</dt>
+ <dd>The harvester's animation file will change when it's empty.The
standard animation
+ is used only when building/repairing.<p></dd>
+
+ <dt>harvest-from-outside</dt>
+ <dd>Unit will harvest from the outside. The unit will use it's attack
animation
+ (seems it turned into a generic Action anim.)<p></dd>
+
+ <dt>lose-resources</dt>
+ <dd>Special lossy behaviour for loaded harvesters. Harvesters with loads
other
+ than 0 and ResourceCapacity will lose their cargo on any new order.<p></dd>
+
+ <dt>terrain-harvester</dt>
+ <dd>The unit will harvest terrain. For now this only works for
wood.<p></dd>
+
<dt>tile_size</dt>
<dd>Define the unit-type size in tiles. NOTE: currently only buildings could
be bigger than one tile. A list of X (width) and Y (height) sizes.
-F.E. '( 1 1 ), '( 2 2 ).
+F.E. '( 1 1 ), '( 2 2 ).<p>
</dd>
<dt>box_size</dt>
<dd></dd>
@@ -569,7 +617,7 @@
<h4>Not Used</h4>
<hr>
-Last changed: $Id: unittype.html,v 1.24 2003/09/03 09:27:51 mr-russ Exp $<br>
+Last changed: $Id: unittype.html,v 1.25 2003/09/10 08:44:36 n0body Exp $<br>
All trademarks and copyrights on this page are owned by their respective
owners.
<address>(c) 2002-2003 by <a href="http://stratagus.org">
The Stratagus Project</a></address></body></html>
Index: stratagus/src/action/action_resource.c
diff -u stratagus/src/action/action_resource.c:1.51
stratagus/src/action/action_resource.c:1.52
--- stratagus/src/action/action_resource.c:1.51 Fri Sep 5 14:10:55 2003
+++ stratagus/src/action/action_resource.c Wed Sep 10 04:44:36 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_resource.c,v 1.51 2003/09/05 18:10:55 n0body Exp $
+// $Id: action_resource.c,v 1.52 2003/09/10 08:44:36 n0body Exp $
//@{
@@ -176,7 +176,7 @@
}
// Find an alternative, but don't look too far.
unit->Orders[0].X=unit->Orders[0].Y=-1;
- if ((goal=FindResource(unit,unit->X,unit->Y,10))) {
+ if ((goal=FindResource(unit,unit->X,unit->Y,10,unit->CurrentResource)))
{
unit->SubAction=SUB_START_RESOURCE;
unit->Orders[0].Goal=goal;
RefsDebugCheck( !goal->Refs );
@@ -391,7 +391,7 @@
DropOutOnSide(uins,LookingW
,source->Type->TileWidth,source->Type->TileHeight);
uins->Orders[0].X=uins->Orders[0].Y=-1;
- if
((uins->Orders[0].Goal=FindResource(uins,uins->X,uins->Y,10))) {
+ if
((uins->Orders[0].Goal=FindResource(uins,uins->X,uins->Y,10,unit->CurrentResource)))
{
DebugLevel0Fn("Unit %d found another resource.\n" _C_
uins->Slot);
uins->SubAction=SUB_START_RESOURCE;
uins->Wait=1;
@@ -646,7 +646,7 @@
unit->SubAction=0;
}
} else {
- if ((goal=FindResource(unit,x,y,10))) {
+ if ((goal=FindResource(unit,x,y,10,unit->CurrentResource))) {
DropOutNearest(unit,goal->X+goal->Type->TileWidth/2
,goal->Y+goal->Type->TileHeight/2
,depot->Type->TileWidth,depot->Type->TileHeight);
@@ -680,7 +680,8 @@
unit->Reset=1;
unit->Orders[0].X=unit->Orders[0].Y=-1;
unit->SubAction=0;
- if( unit->Type->ResInfo[unit->CurrentResource]->LoseResources ) {
+ if( unit->Type->ResInfo[unit->CurrentResource]->LoseResources &&
+
unit->Value<unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity) {
unit->Value=0;
unit->CurrentResource=0;
}
Index: stratagus/src/action/actions.c
diff -u stratagus/src/action/actions.c:1.92 stratagus/src/action/actions.c:1.93
--- stratagus/src/action/actions.c:1.92 Fri Sep 5 14:10:55 2003
+++ stratagus/src/action/actions.c Wed Sep 10 04:44:36 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: actions.c,v 1.92 2003/09/05 18:10:55 n0body Exp $
+// $Id: actions.c,v 1.93 2003/09/10 08:44:36 n0body Exp $
//@{
@@ -307,7 +307,8 @@
}
}
if (unit->CurrentResource) {
- if (unit->Type->ResInfo[unit->CurrentResource]->LoseResources) {
+ if (unit->Type->ResInfo[unit->CurrentResource]->LoseResources&&
+
unit->Value<unit->Type->ResInfo[unit->CurrentResource]->ResourceCapacity) {
unit->Value=0;
}
}
Index: stratagus/src/ai/ai_building.c
diff -u stratagus/src/ai/ai_building.c:1.37 stratagus/src/ai/ai_building.c:1.38
--- stratagus/src/ai/ai_building.c:1.37 Thu Aug 28 18:51:41 2003
+++ stratagus/src/ai/ai_building.c Wed Sep 10 04:44:36 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_building.c,v 1.37 2003/08/28 22:51:41 n0body Exp $
+// $Id: ai_building.c,v 1.38 2003/09/10 08:44:36 n0body Exp $
#ifdef NEW_AI // {
@@ -630,7 +630,7 @@
//
// Find a good place for a new hall
//
- DebugLevel0Fn("Wanty to build a %s(%s)\n" _C_ type->Ident _C_ type->Name);
+ DebugLevel0Fn("Want to build a %s(%s)\n" _C_ type->Ident _C_ type->Name);
if( type->CanStore[GoldCost] && AiFindHallPlace(worker,type,dx,dy) ) {
DebugLevel0Fn("Found place for town hall (%s,%s)\n" _C_ type->Ident _C_
type->Name);
return 1;
Index: stratagus/src/ai/ai_resource.c
diff -u stratagus/src/ai/ai_resource.c:1.66 stratagus/src/ai/ai_resource.c:1.67
--- stratagus/src/ai/ai_resource.c:1.66 Fri Sep 5 14:10:55 2003
+++ stratagus/src/ai/ai_resource.c Wed Sep 10 04:44:36 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_resource.c,v 1.66 2003/09/05 18:10:55 n0body Exp $
+// $Id: ai_resource.c,v 1.67 2003/09/10 08:44:36 n0body Exp $
#ifdef NEW_AI // {
@@ -737,210 +737,48 @@
-- WORKERS/RESOURCES
----------------------------------------------------------------------------*/
-/**
-** Find the nearest gold mine for unit.
-**
-** @param unit Pointer for source unit.
+/*
+** Assign worker to gather a certain resource.
**
-** @return Pointer to the nearest reachable gold mine.
+** @param unit pointer to the unit.
+** @param resource resource identification.
**
-** @see FindGoldMine
+** @return 1 if the worker was assigned, 0 otherwise.
*/
-local Unit* AiFindGoldMine(const Unit* unit)
-{
- // FIXME: explored tiles?
- return FindResource(unit,unit->X,unit->Y,100);
-}
-
-/**
-** Assign worker to mine gold.
-**
-** @todo FIXME: JOHNS: docu What does used_mine do, for what is it good?
-**
-** IDEA: If no way to goldmine, we must dig the way.
-** IDEA: If goldmine is on an other island, we must transport the workers.
-*/
-local int AiMineGold(Unit* unit)
+local int AiAssignHarvester(Unit * unit,int resource)
{
+ ResourceInfo * resinfo;
+ // These will hold the coordinates of the forest.
+ int forestx;
+ int foresty;
+ // This will hold the resulting gather destination.
Unit* dest;
-
- DebugLevel3Fn("%d\n" _C_ UnitNumber(unit));
- dest = AiFindGoldMine(unit);
- if (!dest) {
- DebugLevel3Fn("goldmine not reachable by %s(%d,%d)\n"
- _C_ unit->Type->Ident _C_ unit->X _C_ unit->Y);
- return 0;
- }
-
- CommandResource(unit, dest, FlushCommands);
-
- return 1;
-}
-
-/**
-** Assign worker to harvest.
-**
-** @param unit Find wood for this worker.
-**
-** @return True if the work is going harvest.
-*/
-local int AiHarvest(Unit * unit)
-{
- static const int xoffset[]={ 0,-1,+1, 0, -1,+1,-1,+1 };
- static const int yoffset[]={ -1, 0, 0,+1, -1,-1,+1,+1 };
- struct {
- unsigned short X;
- unsigned short Y;
- } * points;
- int size;
- int x;
- int y;
- int rx;
- int ry;
- int mask;
- int wp;
- int rp;
- int ep;
- int i;
- int w;
- int n;
- unsigned char* m;
- unsigned char* matrix;
- const Unit* destu;
- int destx;
- int desty;
- int bestx;
- int besty;
- int bestd;
-
- x=unit->X;
- y=unit->Y;
- size=TheMap.Width*TheMap.Height/4;
- points=malloc(size*sizeof(*points));
-
- //
- // Find the nearest wood depot
- //
- if( (destu=FindDeposit(unit,x,y,100)) ) {
- NearestOfUnit(destu,x,y,&destx,&desty);
- }
- bestd=99999;
- bestx=besty=0; // keep the compiler happy
-
- //
- // Make movement matrix.
- //
- matrix=CreateMatrix();
- w=TheMap.Width+2;
- matrix+=w+w+2;
-
- points[0].X=x;
- points[0].Y=y;
- rp=0;
- matrix[x+y*w]=1; // mark start point
- ep=wp=1; // start with one point
-
- mask=UnitMovementMask(unit);
-
- //
- // Pop a point from stack, push all neightbors which could be entered.
- //
- for( ;; ) {
- while( rp!=ep ) {
- rx=points[rp].X;
- ry=points[rp].Y;
- for( i=0; i<8; ++i ) { // mark all neighbors
- x=rx+xoffset[i];
- y=ry+yoffset[i];
- m=matrix+x+y*w;
- if( *m ) { // already checked
- continue;
- }
-
- //
- // Look if there is wood
- //
- if ( CheckedForestOnMap(x,y) ) {
- if( destu ) {
- n=max(abs(destx-x),abs(desty-y));
- if( n<bestd ) {
- bestd=n;
- bestx=x;
- besty=y;
- }
- *m=22;
- } else { // no goal take the first
- CommandResourceLoc(unit,x,y,FlushCommands);
- free(points);
- return 1;
- }
- }
-
- if( CanMoveToMask(x,y,mask) ) { // reachable
- *m=1;
- points[wp].X=x; // push the point
- points[wp].Y=y;
- if( ++wp>=size ) { // round about
- wp=0;
- }
- } else { // unreachable
- *m=99;
- }
- }
- if( ++rp>=size ) { // round about
- rp=0;
- }
- }
-
- //
- // Take best of this frame, if any.
- //
- if( bestd!=99999 ) {
- CommandResourceLoc(unit, bestx, besty,FlushCommands);
- free(points);
+
+ resinfo=unit->Type->ResInfo[resource];
+ DebugCheck(!resinfo);
+ if (resinfo->TerrainHarvester) {
+ //
+ // Code for terrain harvesters. Search for piece of terrain to
mine.
+ //
+ if (FindTerrainType(UnitMovementMask(unit),MapFieldForest,0,1000,
+ unit->Player,unit->X,unit->Y,&forestx,&foresty)) {
+ CommandResourceLoc(unit, forestx, foresty,FlushCommands);
return 1;
}
-
+ } else {
//
- // Continue with next frame.
+ // Find a resource to ravest from.
//
- if( rp==wp ) { // unreachable, no more points available
- break;
+ if ((dest=FindResource(unit,unit->X,unit->Y,1000,resource))) {
+ CommandResource(unit,dest,FlushCommands);
+ return 1;
}
- ep=wp;
}
-
- DebugLevel3Fn("no wood in range by %s(%d,%d)\n"
- _C_ unit->Type->Ident _C_ unit->X _C_ unit->Y);
-
- free(points);
+ // Failed.
return 0;
}
/**
-** Assign worker to haul oil.
-*/
-local int AiHaulOil(Unit * unit)
-{
- Unit *dest;
-
- DebugLevel3Fn("%d\n" _C_ UnitNumber(unit));
- // Range hardcoded. search the whole map!!!
- dest = FindResource(unit, unit->X, unit->Y,1000);
- if (!dest) {
- DebugLevel3Fn("oil platform not reachable by %s(%d,%d)\n"
- _C_ unit->Type->Ident _C_ unit->X _C_ unit->Y);
- return 0;
- }
-
- DebugCheck( !unit->Type->Harvester );
-
- CommandResource(unit, dest,FlushCommands);
-
- return 1;
-}
-
-/**
** Assign workers to collect resources.
**
** If we have a shortage of a resource, let many workers collecting this.
@@ -957,9 +795,8 @@
int total; // Total of workers
int c;
int i;
- int j;
- int o;
int n;
+ int o;
Unit** units;
Unit* unit;
int percent[MaxCosts];
@@ -984,27 +821,33 @@
units=AiPlayer->Player->Units;
for( i=0; i<n; i++ ) {
unit=units[i];
- if( !unit->Type->Harvester ) {
+ if( (!unit->Type->Harvester) || (unit->Removed )) {
continue;
}
+ c=unit->CurrentResource;
//
// See if it's assigned already
//
- if (unit->Orders[0].Action==UnitActionResource) {
- c=unit->CurrentResource;
+ if (unit->Orders[0].Action==UnitActionResource&&c) {
units_assigned[num_units_assigned[c]++][c]=unit;
+ continue;
+ }
+
+ //
+ // Ignore busy units.
+ //
+ if (unit->Orders->Action != UnitActionStill || unit->OrderCount!=1 ) {
+ continue;
}
//
- // Send workers with resources back home.
+ // Send workers with resources back home.
//
- if (unit->Value) {
+ if (unit->Value&&c) {
units_with_resource[num_units_with_resource[c]++][c]=unit;
- if (unit->Orders[0].Action == UnitActionStill
- && unit->OrderCount==1 ) {
- CommandReturnGoods(unit,0,FlushCommands);
- }
+ CommandReturnGoods(unit,0,FlushCommands);
+ continue;
}
//
@@ -1014,56 +857,31 @@
if (unit->Type->ResInfo[c]) {
units_unassigned[num_units_unassigned[c]++][c]=unit;
}
-#if 0
- UnitType** types;
-
- //
- // Look if it is a worker
- //
- if( c>=AiHelpers.CollectCount || !AiHelpers.Collect[c] ) {
- continue; // Nothing known about the resource
- }
- types=AiHelpers.Collect[c]->Table;
- tn=AiHelpers.Collect[c]->Count;
- for( j=0; j<tn; ++j ) {
- if( unit->Type==types[j] ) {
- if (unit->Orders[0].Action == UnitActionStill
- && unit->OrderCount==1 && !unit->Removed ) {
- for( c=0; c<MaxCosts; ++c ) {
- int tn;
- UnitType** types;
- if( c>=AiHelpers.CollectCount ||
!AiHelpers.Collect[c] ) {
- continue;
- }
- types=AiHelpers.Collect[c]->Table;
- tn=AiHelpers.Collect[c]->Count;
- for( j=0; j<tn; ++j ) {
- if( unit->Type==types[j] ) {
-
units_unassigned[num_units_unassigned[c]++][c]=unit;
- }
- }
- }
- break;
- }
- }
- }
- if( j<tn ) {
- break;
- }
-#endif
}
}
+#ifdef DEBUG
total=0;
for( c=0; c<MaxCosts; ++c ) {
total+=num_units_assigned[c]+num_units_with_resource[c];
DebugLevel3Fn("Assigned %d = %d\n" _C_ c _C_ num_units_assigned[c]);
DebugLevel3Fn("Resource %d = %d\n" _C_ c _C_
num_units_with_resource[c]);
- DebugLevel3Fn("Unassigned %d of total %d\n" _C_ num_units_unassigned[c]
_C_ total);
}
+ DebugLevel3Fn("Unassigned %d of total %d\n" _C_ num_units_unassigned[c]
_C_ total);
+ if (AiPlayer->Player==ThisPlayer) {
+ DebugLevel3Fn("Percent Assignment:");
+ for( c=0; c<MaxCosts; ++c ) {
+ if (percent[c]) {
+ DebugLevel3(" %s:%d%%" _C_ DefaultResourceNames[c] _C_
percent[c]);
+ }
+ }
+ DebugLevel3("\n");
+ }
+
+#endif
//
- // Reassign workers
+ // Reassign free workers
//
for( c=0; c<MaxCosts; ++c ) {
if( num_units_unassigned[c]==0 ) {
@@ -1074,14 +892,16 @@
if( i==c ) {
continue;
}
+ // FIXME: Shouldn't this turn into a while? currently max one
worker is transfered.
if( (percent[i] < percent[c] &&
((num_units_assigned[c]+num_units_with_resource[c]-1)*percent_total >
total*percent[c] ||
num_units_assigned[c]+num_units_with_resource[c]==0)) ||
(num_units_assigned[i]+num_units_with_resource[i]-1)*percent_total >
total*percent[i] ) {
+ // We take workers from resource i and move them to
resource c
int j;
for( j=num_units_assigned[i]-1; j>=0; --j ) {
unit=units_assigned[j][i];
- if( unit && unit->SubAction < 64 ) {
+ if( unit && unit->SubAction < 50 ) {
units_assigned[j][i] =
units_assigned[--num_units_assigned[i]][i];
--total;
units_unassigned[num_units_unassigned[c]++][c]=unit;
@@ -1092,7 +912,7 @@
}
}
}
-
+
//
// Now assign the free workers.
//
@@ -1101,8 +921,14 @@
int t;
int max;
+ //
+ // Loop through all of the workers.
+ //
unit=units_unassigned[i][n];
+ //
+ // Here we determine what to assign the worker to first.
+ //
for( max=o=c=0; c<MaxCosts; ++c ) {
DebugLevel3Fn("%d, %d, %d\n" _C_
(num_units_assigned[c]+num_units_with_resource[c])*percent_total _C_
@@ -1121,76 +947,32 @@
// Look what the unit can do
//
for( t=0; t<MaxCosts; ++t ) {
- int tn;
- UnitType** types;
-
+ //
+ // Now we have to assign it to resource c
+ //
c=(t+o)%MaxCosts;
-
+ if (!unit->Type->ResInfo[c]) {
+ continue; // Alas, we can't mine c
+ }
//
- // Look if it is a worker for this resource
+ // Look if it is a worker for this resource
//
- if( c>=AiHelpers.CollectCount || !AiHelpers.Collect[c] ) {
- continue; // Nothing known about the resource
- }
- types=AiHelpers.Collect[c]->Table;
- tn=AiHelpers.Collect[c]->Count;
- for( j=0; j<tn; ++j ) {
- if( unit->Type==types[j] && unit->OrderCount==1 ) {
- switch( c ) {
- int n1;
- int n2;
- case GoldCost:
- if(
(unit->Orders[0].Action==UnitActionResource&&unit->CurrentResource==GoldCost)
|| AiMineGold(unit) ) {
- DebugLevel3Fn("Assigned to gold\n");
-
units_assigned[num_units_assigned[c]++][c]=unit;
- units_unassigned[i][c] =
units_unassigned[--num_units_unassigned[c]][c];
- for( n1=0; n1<MaxCosts; ++n1 ) {
- for( n2=0; n2<num_units_unassigned[n1];
++n2 ) {
- if( units_unassigned[n2][n1]==unit
) {
-
units_unassigned[n2][n1]=units_unassigned[--num_units_unassigned[n1]][n1];
- break;
- }
- }
- }
- ++total;
- }
- break;
- case WoodCost:
- if(
(unit->Orders[0].Action==UnitActionResource&&unit->CurrentResource==WoodCost)
|| AiHarvest(unit) ) {
- DebugLevel3Fn("Assigned to harvest\n");
-
units_assigned[num_units_assigned[c]++][c]=unit;
- units_unassigned[i][c] =
units_unassigned[--num_units_unassigned[c]][c];
- for( n1=0; n1<MaxCosts; ++n1 ) {
- for( n2=0; n2<num_units_unassigned[n1];
++n2 ) {
- if( units_unassigned[n2][n1]==unit
) {
-
units_unassigned[n2][n1]=units_unassigned[--num_units_unassigned[n1]][n1];
- break;
- }
- }
- }
- ++total;
- }
- break;
- case OilCost:
- if(
(unit->Orders[0].Action==UnitActionResource&&unit->CurrentResource==OilCost) ||
AiHaulOil(unit) ) {
- DebugLevel3Fn("Assigned to oil\n");
-
units_assigned[num_units_assigned[c]++][c]=unit;
- units_unassigned[i][c] =
units_unassigned[--num_units_unassigned[c]][c];
- for( n1=0; n1<MaxCosts; ++n1 ) {
- for( n2=0; n2<num_units_unassigned[n1];
++n2 ) {
- if( units_unassigned[n2][n1]==unit
) {
-
units_unassigned[n2][n1]=units_unassigned[--num_units_unassigned[n1]][n1];
- break;
- }
- }
- }
- ++total;
- }
- break;
- default:
+ if( AiAssignHarvester(unit,c) ) {
+ int n1,n2;
+ DebugLevel0Fn("Assigned %d to %s\n" _C_ unit->Slot _C_
DefaultResourceNames[c]);
+ units_assigned[num_units_assigned[c]++][c]=unit;
+ units_unassigned[i][c] =
units_unassigned[--num_units_unassigned[c]][c];
+ for( n1=0; n1<MaxCosts; ++n1 ) {
+ for( n2=0; n2<num_units_unassigned[n1]; ++n2 ) {
+ if( units_unassigned[n2][n1]==unit ) {
+
units_unassigned[n2][n1]=units_unassigned[--num_units_unassigned[n1]][n1];
break;
+ }
}
}
+ ++total;
+ // We assigned this worker to something already.
+ break;
}
}
}
Index: stratagus/src/clone/unit.c
diff -u stratagus/src/clone/unit.c:1.291 stratagus/src/clone/unit.c:1.292
--- stratagus/src/clone/unit.c:1.291 Fri Sep 5 14:10:55 2003
+++ stratagus/src/clone/unit.c Wed Sep 10 04:44:36 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.c,v 1.291 2003/09/05 18:10:55 n0body Exp $
+// $Id: unit.c,v 1.292 2003/09/10 08:44:36 n0body Exp $
//@{
@@ -2601,13 +2601,14 @@
** @param x Closest to x
** @param x Closest to y
** @param range Maximum distance to the resource.
+ ** @param resource The resource id.
**
** @notes This will return an usable resource building that
** belongs to "player" or is neutral.
**
** @return NoUnitP or resource unit
*/
-global Unit* FindResource(const Unit * unit,int x,int y,int range)
+global Unit* FindResource(const Unit * unit,int x,int y,int range,int resource)
{
static const int xoffset[]={ 0,-1,+1, 0, -1,+1,-1,+1 };
static const int yoffset[]={ -1, 0, 0,+1, -1,-1,+1,+1 };
@@ -2634,9 +2635,6 @@
int desty;
int bestd;
int cdist;
- int resource;
-
- resource=unit->CurrentResource;
destx=x;
desty=y;
@@ -3977,7 +3975,7 @@
int InRun, RunStart;
CLprintf(file,"\n;;; -----------------------------------------\n");
- CLprintf(file,";;; MODULE: units $Id: unit.c,v 1.291 2003/09/05 18:10:55
n0body Exp $\n\n");
+ CLprintf(file,";;; MODULE: units $Id: unit.c,v 1.292 2003/09/10 08:44:36
n0body Exp $\n\n");
//
// Local variables
Index: stratagus/src/include/unit.h
diff -u stratagus/src/include/unit.h:1.211 stratagus/src/include/unit.h:1.212
--- stratagus/src/include/unit.h:1.211 Fri Sep 5 14:10:55 2003
+++ stratagus/src/include/unit.h Wed Sep 10 04:44:36 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit.h,v 1.211 2003/09/05 18:10:55 n0body Exp $
+// $Id: unit.h,v 1.212 2003/09/10 08:44:36 n0body Exp $
#ifndef __UNIT_H__
#define __UNIT_H__
@@ -820,7 +820,7 @@
extern int CanBuildUnitType(const Unit* unit,const UnitType* type,int x,int y);
/// Find resource
-extern Unit* FindResource(const Unit* unit,int x,int y,int range);
+extern Unit* FindResource(const Unit* unit,int x,int y,int range,int resource);
/// Find nearest deposit
extern Unit* FindDeposit(const Unit* unit,int x,int y,int range);
/// Find the next idle worker
Index: stratagus/src/include/unittype.h
diff -u stratagus/src/include/unittype.h:1.103
stratagus/src/include/unittype.h:1.104
--- stratagus/src/include/unittype.h:1.103 Fri Sep 5 14:10:55 2003
+++ stratagus/src/include/unittype.h Wed Sep 10 04:44:36 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unittype.h,v 1.103 2003/09/05 18:10:55 n0body Exp $
+// $Id: unittype.h,v 1.104 2003/09/10 08:44:36 n0body Exp $
#ifndef __UNITTYPE_H__
#define __UNITTYPE_H__
@@ -538,6 +538,12 @@
**
** Maximum amount of resources a harvester can carry. The
** actual amount can be modified while unloading.
+**
+** ResourceInfo::LoseResources
+**
+** Special lossy behaviour for loaded harvesters. Harvesters
+** with loads other than 0 and ResourceCapacity will lose their
+** cargo on any new order.
**
** ResourceInfo::WaitAtDepot
**
Index: stratagus/src/ui/mouse.c
diff -u stratagus/src/ui/mouse.c:1.144 stratagus/src/ui/mouse.c:1.145
--- stratagus/src/ui/mouse.c:1.144 Fri Sep 5 14:10:56 2003
+++ stratagus/src/ui/mouse.c Wed Sep 10 04:44:36 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: mouse.c,v 1.144 2003/09/05 18:10:56 n0body Exp $
+// $Id: mouse.c,v 1.145 2003/09/10 08:44:36 n0body Exp $
//@{
@@ -970,6 +970,8 @@
if( Selected[i]->Type->Harvester &&
Selected[i]->Type->ResInfo[res] &&
Selected[i]->Type->ResInfo[res]->TerrainHarvester &&
+ // Full harvesters don't act.
+
Selected[i]->Value<Selected[i]->Type->ResInfo[res]->ResourceCapacity &&
IsMapFieldExplored(Selected[i]->Player,sx/TileSizeX,sy/TileSizeY) &&
ForestOnMap(sx/TileSizeX,sy/TileSizeY) ) {
DebugLevel3("RESOURCE\n");
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus contrib/msvc.zip doc/ChangeLog.html d...,
Crestez Leonard <=