stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus data/ccl/units.ccl src/action/action_...


From: Crestez Leonard
Subject: [Stratagus-CVS] stratagus data/ccl/units.ccl src/action/action_...
Date: Sun, 24 Aug 2003 14:48:05 -0400

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Crestez Leonard <address@hidden>        03/08/24 14:48:04

Modified files:
        data/ccl       : units.ccl 
        src/action     : action_build.c action_repair.c 
                         action_resource.c actions.c 
        src/ai         : ai.c ai_building.c ai_resource.c ccl_ai.c 
                         new_ai.c 
        src/clone      : unit.c unit_draw.c 
        src/include    : unit.h unittype.h 
        src/pathfinder : pathfinder.c 
        src/ui         : mainscr.c 
        src/unit       : ccl_unit.c ccl_unittype.c unittype.c 

Log message:
        Fixed gcc-2.95 bugs.
        Building from the outside works perfectly.
        Changed time to build handling.
        Revamped resource code a bit.

Patches:
Index: stratagus/data/ccl/units.ccl
diff -u stratagus/data/ccl/units.ccl:1.41 stratagus/data/ccl/units.ccl:1.42
--- stratagus/data/ccl/units.ccl:1.41   Thu Aug 21 17:55:44 2003
+++ stratagus/data/ccl/units.ccl        Sun Aug 24 14:48:02 2003
@@ -26,7 +26,7 @@
 ;;      along with this program; if not, write to the Free Software
 ;;      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  
USA
 ;;
-;;     $Id: units.ccl,v 1.41 2003/08/21 21:55:44 n0body Exp $
+;;     $Id: units.ccl,v 1.42 2003/08/24 18:48:02 n0body Exp $
 
 ;; Load the animations for the units.
 (ccl:load "ccl/anim.ccl")
@@ -199,7 +199,6 @@
   'type-land
   'building
   'gives-resource 'gold 'can-harvest
-  'max-workers 2
   'sounds '(
     selected "gold-mine-selected"
     acknowledge "gold-mine-acknowledge"
Index: stratagus/src/action/action_build.c
diff -u stratagus/src/action/action_build.c:1.89 
stratagus/src/action/action_build.c:1.90
--- stratagus/src/action/action_build.c:1.89    Thu Aug 21 17:55:44 2003
+++ stratagus/src/action/action_build.c Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_build.c,v 1.89 2003/08/21 21:55:44 n0body Exp $
+//     $Id: action_build.c,v 1.90 2003/08/24 18:48:03 n0body Exp $
 
 //@{
 
@@ -55,7 +55,7 @@
 /**
 **     Update construction frame
 **
-**     @param unit     Unit
+**     @param unit     the building under construction.
 */
 local void UpdateConstructionFrame(Unit* unit)
 {
@@ -63,7 +63,8 @@
     ConstructionFrame* tmp;
     int percent;
 
-    percent=unit->Data.Builded.Sum*100/unit->Stats->HitPoints;
+//    
percent=unit->Data.Builded.Progress*100/(unit->Type->Stats->Costs[TimeCost]*600);
+    percent=unit->Data.Builded.Progress/(unit->Type->Stats->Costs[TimeCost]*6);
     cframe=tmp=unit->Type->Construction->Frames;
     while( tmp ) {
        if( percent<tmp->Percent ) {
@@ -75,6 +76,7 @@
     if( cframe!=unit->Data.Builded.Frame ) {
        unit->Data.Builded.Frame=cframe;
        unit->Frame=cframe->Frame;
+       CheckUnitToBeDrawn(unit);
        UnitMarkSeen(unit);
     }
 }
@@ -88,7 +90,7 @@
 {
     int x;
     int y;
-    int n;
+    //int n;
     UnitType* type;
     const UnitStats* stats;
     Unit* build;
@@ -250,26 +252,18 @@
 
     // HACK: the building is not ready yet
     build->Player->UnitTypesCount[type->Type]--;
-    build->HP=0;
 
     stats=build->Stats;
 
+    build->Wait=1;
+    //  Make sure the bulding doesn't cancel itself out right away.
+    build->Data.Builded.Progress=100;
     build->Orders[0].Action=UnitActionBuilded;
-    build->Data.Builded.Sum=0;  // FIXME: Is it necessary?
-    build->Data.Builded.Cancel=0; // FIXME: Is it necessary?
-    build->Data.Builded.Val=stats->HitPoints;
-    n=(stats->Costs[TimeCost]*CYCLES_PER_SECOND/6)/(SpeedBuild*5);
-    if( n ) {
-       build->Data.Builded.Add=stats->HitPoints/n;
-    } else {                           // No build time pops-up?
-       build->Data.Builded.Add=stats->HitPoints;
-       // This checks if the value fits in the data type
-       DebugCheck( build->Data.Builded.Add!=stats->HitPoints );
-    }
-    build->Data.Builded.Sub=n;
-    build->Wait=CYCLES_PER_SECOND/6;
+    build->HP=1;
     UpdateConstructionFrame(build);
 
+    // We need somebody to work on it.
+    build->HP=1;
     if (!type->BuilderOutside) {
        //  Place the builder inside the building
        build->Data.Builded.Worker=unit;
@@ -292,12 +286,7 @@
        UnitMarkSeen(unit);
        //  Mark the new building seen.
        
MapMarkSight(build->Player,x+build->Type->TileWidth/2,y+build->Type->TileHeight/2,build->CurrentSightRange);
-       
-       // We need somebody to work on it.
-       build->Data.Builded.Sub=build->Data.Builded.Add=0;
-       build->HP=1;
     }
-    build->Wait=CYCLES_PER_SECOND/6;
     UpdateConstructionFrame(build);
     UnitMarkSeen(build);
 }
@@ -314,11 +303,30 @@
     int n;
 
     type=unit->Type;
+    
+    //  n is the current damage taken by the unit.
+    n=(unit->Data.Builded.Progress*unit->Stats->HitPoints)/
+           (type->Stats->Costs[TimeCost]*600)-unit->HP;
+    //  This below is most often 0
+    if (type->BuilderOutside) {
+       unit->Data.Builded.Progress+=unit->Type->AutoBuildRate;
+    } else {
+       unit->Data.Builded.Progress+=100;
+           // FIXME: implement this below:
+           //unit->Data.Builded.Worker->Type->BuilderSpeedFactor;
+    }
+    //  Keep the same level of damage while increasing HP.
+    unit->HP=(unit->Data.Builded.Progress*unit->Stats->HitPoints)/
+           (type->Stats->Costs[TimeCost]*600)-n;
+    if (unit->HP>unit->Stats->HitPoints) {
+       unit->HP=unit->Stats->HitPoints;
+    }
 
     //
     // Check if construction should be canceled...
     //
-    if( unit->Data.Builded.Cancel ) {
+    if( unit->Data.Builded.Cancel || unit->Data.Builded.Progress<0 ) {
+       DebugLevel0Fn("%s canceled.\n" _C_ unit->Type->Name);
        // Drop out unit
        if ((worker=unit->Data.Builded.Worker)) {
            worker->Orders[0].Action=UnitActionStill;
@@ -336,32 +344,12 @@
        return;
     }
 
-    if (!type->BuilderOutside) {
-       //
-       //      Fixed point HP calculation
-       //
-       unit->Data.Builded.Val-=unit->Data.Builded.Sub;
-       if( unit->Data.Builded.Val<0 ) {
-           unit->Data.Builded.Val+=unit->Stats->HitPoints;
-           unit->HP++;
-           unit->Data.Builded.Sum++;
-       }
-
-       
-       n=(unit->Stats->Costs[TimeCost]*CYCLES_PER_SECOND/6)/(SpeedBuild*5);
-       if( unit->Data.Builded.Add!=unit->Stats->HitPoints/(n?n:1) ) {
-           unit->Data.Builded.Add=unit->Stats->HitPoints/(n?n:1);
-       }
-
-       unit->HP+=unit->Data.Builded.Add;
-       unit->Data.Builded.Sum+=unit->Data.Builded.Add;
-    }
-
     //
-    // Check if building ready. Note we can build and repair.
+    // Check if building ready. Note we can both build and repair.
     //
-    if( unit->Data.Builded.Sum>=unit->Stats->HitPoints
-               || unit->HP>=unit->Stats->HitPoints ) {
+    if( unit->Data.Builded.Progress>=unit->Stats->Costs[TimeCost]*600 ||
+           unit->HP>=unit->Stats->HitPoints) {
+       DebugLevel0Fn("Building ready.\n");
        if( unit->HP>unit->Stats->HitPoints ) {
            unit->HP=unit->Stats->HitPoints;
        }
@@ -389,13 +377,6 @@
                if 
(worker->Type->Harvester&&worker->Type->ResourceHarvested==type->GivesResource) 
{
                    CommandResource(worker,unit,0);
                }
-               //
-               //      Building lumber mill, let worker automatic chopping 
wood.
-               //
-               if( type->CanStore[WoodCost] ) {
-                   CommandHarvest(worker,unit->X+unit->Type->TileWidth/2,
-                           unit->Y+unit->Type->TileHeight/2,0);
-               }
            }
        }
        
@@ -414,7 +395,8 @@
            } else {
                PlayUnitSound(unit,VoiceBuilding);
            }
-       } else if( unit->Player->Ai ) {
+       }
+       if( unit->Player->Ai ) {
            AiWorkComplete(worker,unit);
        }
 
@@ -448,9 +430,8 @@
     }
 
     UpdateConstructionFrame(unit);
-    CheckUnitToBeDrawn(unit);
 
-    unit->Wait=5;
+    unit->Wait=1;
     if( IsOnlySelected(unit) ) {
         MustRedraw|=RedrawInfoPanel;
     }
Index: stratagus/src/action/action_repair.c
diff -u stratagus/src/action/action_repair.c:1.48 
stratagus/src/action/action_repair.c:1.49
--- stratagus/src/action/action_repair.c:1.48   Fri Aug  8 06:16:43 2003
+++ stratagus/src/action/action_repair.c        Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_repair.c,v 1.48 2003/08/08 10:16:43 martinxyz Exp $
+//     $Id: action_repair.c,v 1.49 2003/08/24 18:48:03 n0body Exp $
 
 //@{
 
@@ -84,92 +84,117 @@
     Player* player;
     int costs[MaxCosts];
     int i;
+    int animlength;
+    Animation* anim;
     int hp;
     int lrr;
+    char buf[100];
 
 #define GIVES_HP       4
 #define COSTS          1
 
-    player = unit->Player;
-
     //
     //  Calculate the repair points
     //          original per 100 hit points only 25 gold 25 wood
     //
     hp = GIVES_HP;
 
-    //
-    //  Calculate the repair costs.
-    //
-    DebugCheck(!goal->Stats->HitPoints);
+    player = unit->Player;
 
-    for (i = 1; i < MaxCosts; ++i) {
-       if (goal->Stats->Costs[i]) {
-           costs[i] = COSTS;
-       } else {                        // Prepare for repair cycles
-           costs[i] = 0;
-       }
-    }
+    if 
(goal->Orders[0].Action!=UnitActionBuilded||(!goal->Type->BuilderOutside)) {
+       //
+       //  Calculate the repair costs.
+       //
+       DebugCheck(!goal->Stats->HitPoints);
 
-    //
-    //  Check if enough resources are available
-    //
-    for (i = 1; i < MaxCosts; ++i) {
-       if (player->Resources[i] < costs[i]) {
-           // FIXME: we should say what resource
-           NotifyPlayer(player, NotifyYellow, unit->X, unit->Y,
-                   "We need resources for repair!");
-           if( player->Ai ) {
-               // FIXME: call back to AI?
-
-               RefsDebugCheck(!goal->Refs);
-               if (!--goal->Refs) {
-                   ReleaseUnit(goal);
-               }
-               unit->Orders[0].Goal = NULL;
-               unit->Orders[0].Action = UnitActionStill;
-               unit->State = unit->SubAction = 0;
-               if (unit->Selected) {   // update display for new action
-                   SelectedUnitChanged();
-               }
+       for (i = 1; i < MaxCosts; ++i) {
+           if (goal->Stats->Costs[i]) {
+               costs[i] = COSTS;
+           } else {                    // Prepare for repair cycles
+               costs[i] = 0;
            }
-           // FIXME: We shouldn't animate if no resources are available.
-           return;
        }
-    }
-
-    lrr = player->LastRepairResource;
-    for (i = player->LastRepairResource; i < MaxCosts; ++i) {
-       if (costs[i] && lrr == player->LastRepairResource) {
-           lrr = i;
-       }                               // Find next higher resource or...
-    }
-    if (lrr == player->LastRepairResource) {
-       for (i = player->LastRepairResource; i > 0; --i) {
-           if (costs[i]) {
+       lrr = player->LastRepairResource;
+       for (i = player->LastRepairResource; i < MaxCosts; ++i) {
+           if (costs[i] && lrr == player->LastRepairResource) {
                lrr = i;
+           }                           // Find next higher resource or...
+       }
+       if (lrr == player->LastRepairResource) {
+           for (i = player->LastRepairResource; i > 0; --i) {
+               if (costs[i]) {
+                   lrr = i;
+               }
+           }                           // ...go through the beginning
+       }
+       player->LastRepairResource = lrr;
+       // Thanx for the help, costs, you are reset!
+       for (i = 1; i < MaxCosts; ++i) {
+           costs[i] = 0;
+       }
+       costs[player->LastRepairResource] = COSTS;      // The one we need
+       //
+       //  Check if enough resources are available
+       //
+       for (i = 1; i < MaxCosts; ++i) {
+           if (player->Resources[i] < costs[i]) {
+               snprintf(buf,100,"We need more %s for 
repair!",DefaultResourceNames[i]);
+               NotifyPlayer(player, NotifyYellow, unit->X, unit->Y,buf);
+               if( player->Ai ) {
+                   // FIXME: call back to AI?
+                   RefsDebugCheck(!goal->Refs);
+                   if (!--goal->Refs) {
+                       ReleaseUnit(goal);
+                   }
+                   unit->Orders[0].Goal = NULL;
+                   unit->Orders[0].Action = UnitActionStill;
+                   unit->State = unit->SubAction = 0;
+                   if (unit->Selected) {       // update display for new action
+                       SelectedUnitChanged();
+                   }
+               }
+               // FIXME: We shouldn't animate if no resources are available.
+               return;
            }
-       }                               // ...go through the beginning
-    }
-    player->LastRepairResource = lrr;
-
-    // Thanx for the help, costs, you are reset!
-    for (i = 1; i < MaxCosts; ++i) {
-       costs[i] = 0;
+       }
+       //
+       //  Subtract the resources
+       //
+       PlayerSubCosts(player, costs);
     }
-    costs[player->LastRepairResource] = COSTS; // The one we need
-
+    
     //
     //  Repair the unit
     //
-    goal->HP += hp;
-    if (goal->HP > goal->Stats->HitPoints) {
-       goal->HP = goal->Stats->HitPoints;
+    if (goal->Type->BuilderOutside) {
+       //  hp is the current damage taken by the unit.
+       hp=(goal->Data.Builded.Progress*goal->Stats->HitPoints)/
+               (goal->Type->Stats->Costs[TimeCost]*600)-goal->HP;
+       //
+       //  Calculate the length of the attack (repair) anim.
+       //
+       animlength=0;
+       for 
(anim=unit->Type->Animations->Attack;!(anim->Flags&AnimationReset);anim++) {
+           animlength+=anim->Sleep;
+       }
+       
+       DebugLevel3("Repair animation is %d cycles long\n" _C_ animlength);
+       // FIXME: implement this below:
+       //unit->Data.Builded.Worker->Type->BuilderSpeedFactor;
+       goal->Data.Builded.Progress+=100*animlength;
+       //  Keep the same level of damage while increasing HP.
+       goal->HP=(goal->Data.Builded.Progress*goal->Stats->HitPoints)/
+               (goal->Type->Stats->Costs[TimeCost]*600)-hp;
+       if (goal->HP>goal->Stats->HitPoints) {
+           goal->HP=goal->Stats->HitPoints;
+       }
+       //  HandleActionBuilded will deal with most stuff.
+    } else {
+       goal->HP += hp;
+       if (goal->HP > goal->Stats->HitPoints) {
+           goal->HP = goal->Stats->HitPoints;
+       }
     }
-    //
-    //  Subtract the resources
-    //
-    PlayerSubCosts(player, costs);
 
     if (CheckUnitToBeDrawn(goal)) {
        MustRedraw |= RedrawMinimap;
@@ -260,10 +285,11 @@
                //
                //      Have reached target? FIXME: could use return value
                //
-               if( goal && MapDistanceToUnit(unit->X,unit->Y,goal)
-                       <=REPAIR_RANGE ) {
+               if(goal&&MapDistanceToUnit(unit->X,unit->Y,goal)<=REPAIR_RANGE
+                       &&goal->HP<goal->Type->Stats->HitPoints) {
                    unit->State=0;
                    unit->SubAction=2;
+                   unit->Reset=1;
                    UnitHeadingFromDeltaXY(unit,
                        goal->X+(goal->Type->TileWidth-1)/2-unit->X,
                        goal->Y+(goal->Type->TileHeight-1)/2-unit->Y);
Index: stratagus/src/action/action_resource.c
diff -u stratagus/src/action/action_resource.c:1.48 
stratagus/src/action/action_resource.c:1.49
--- stratagus/src/action/action_resource.c:1.48 Thu Aug 21 17:55:45 2003
+++ stratagus/src/action/action_resource.c      Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_resource.c,v 1.48 2003/08/21 21:55:45 n0body Exp $
+//     $Id: action_resource.c,v 1.49 2003/08/24 18:48:03 n0body Exp $
 
 //@{
 
@@ -120,6 +120,7 @@
            RefsDebugCheck( !goal->Refs );
        }
        unit->Orders[0].Goal=NoUnitP;
+       unit->Orders[0].X=unit->Orders[0].Y=-1;
        // FIXME: Choose an alternative
        unit->Orders[0].Action=UnitActionStill;
        unit->SubAction=0;
@@ -168,6 +169,8 @@
        unit->Wait=1;
     }
 
+    unit->Reset=1;
+
     return 1;
 }
 
@@ -181,6 +184,9 @@
 local int GatherResource(Unit* unit)
 {
     Unit* source;
+    Unit* depot;
+    Unit* uins;
+    int i;
 
     source=unit->Container;
 
@@ -204,7 +210,7 @@
     }
     
     // Change unit to full state.
-    if( unit->Type->TransformWhenLoaded ) {
+    if( unit->Type->TransformWhenLoaded&&unit->Value ) {
        unit->Player->UnitTypesCount[unit->Type->Type]--;
        unit->Type=unit->Type->TransformWhenLoaded;
        unit->Player->UnitTypesCount[unit->Type->Type]++;
@@ -214,8 +220,34 @@
     // End of resource: destroy the resource.
     //
     if( source->Value==0 ) {
-       DebugLevel0Fn("Resource is destroyed\n");
-       DropOutAll(source);
+       DebugLevel0Fn("%lu: Resource is destroyed\n" _C_ GameCycle);
+       uins=source->UnitInside;
+       // Improved version of DropOutAll
+        for( i=source->InsideCount; i; --i,uins=uins->NextContained ) {
+           if (uins->Value && 
(depot=FindDeposit(uins->Player,uins->X,uins->Y,source->Type->GivesResource))) {
+               DropOutNearest(uins,depot->X+depot->Type->TileWidth/2
+                       ,depot->Y+depot->Type->TileHeight/2
+                       ,source->Type->TileWidth,source->Type->TileHeight);
+               uins->Orders[0].Action=UnitActionReturnGoods;
+               uins->SubAction=0;
+               uins->Wait=unit->Reset=1;
+               uins->Orders[0].Goal=depot;
+               
+               RefsDebugCheck( !depot->Refs );
+               ++depot->Refs;
+               DebugLevel0Fn("Sent unit %d to depot\n" _C_ uins->Slot);
+               continue;
+           }
+           DebugLevel0Fn("Unit %d just sits around confused.\n" _C_ 
uins->Slot);
+           DropOutOnSide(uins,LookingW
+                   ,source->Type->TileWidth,source->Type->TileHeight);
+           uins->Orders[0].Goal=0;
+           uins->Orders[0].X=uins->Orders[0].Y=-1;
+           uins->Orders[0].Action=UnitActionStill;
+           uins->Wait=unit->Reset=1;
+           uins->SubAction=0;
+       }
+
        LetUnitDie(source);
        // FIXME: make the workers inside look for a new resource.
        source=NULL;
@@ -232,7 +264,7 @@
 }
 
 /**
-**     Stop gathering from the resource.
+**     Stop gathering from the resource, go home.
 **
 **     @param unit     Poiner to unit.
 **
@@ -243,37 +275,41 @@
     Unit* depot;
     Unit* source;
 
-    source=unit->Container;
-    //  Deactivate the resource. Wicked.
-    source->Data.Resource.Active--;
-    DebugCheck(source->Data.Resource.Active<0);
- 
+    if ((source=unit->Container)) {
+       //  Deactivate the resource. Wicked.
+       source->Data.Resource.Active--;
+       DebugCheck(source->Data.Resource.Active<0);
+    }
+     
     // Store resource position.
     // FIXME: is this the best way?
     unit->Orders[0].Arg1=(void*)((unit->X<<16)|unit->Y);
-    
-    // Find and send to resource deposit.
-    if( 
!(depot=FindDeposit(unit->Player,unit->X,unit->Y,unit->Type->ResourceHarvested))
 ) {
-       DropOutOnSide(unit,LookingW
-               ,source->Type->TileWidth,source->Type->TileHeight);
+   
+    // Find and send to resource deposit.
+    if( 
(!(depot=FindDeposit(unit->Player,unit->X,unit->Y,unit->Type->ResourceHarvested)))
+           || (!unit->Value)) {
+       if (source) {
+           
DropOutOnSide(unit,LookingW,source->Type->TileWidth,source->Type->TileHeight);
+       }
        DebugLevel0Fn("Can't find a resource deposit.\n");
        unit->Orders[0].Action=UnitActionStill;
        unit->SubAction=0;
        // should return 0, done below!
     } else {
-       DropOutNearest(unit,depot->X+depot->Type->TileWidth/2
-               ,depot->Y+depot->Type->TileHeight/2
-               ,source->Type->TileWidth,source->Type->TileHeight);
+       if (source) {
+           DropOutNearest(unit,depot->X+depot->Type->TileWidth/2
+                   ,depot->Y+depot->Type->TileHeight/2
+                   ,source->Type->TileWidth,source->Type->TileHeight);
+       }
        unit->Orders[0].Goal=depot;
        RefsDebugCheck( !depot->Refs );
        ++depot->Refs;
        unit->Orders[0].RangeX=unit->Orders[0].RangeY=1;
        unit->Orders[0].X=unit->Orders[0].Y=-1;
-       unit->Orders[0].X=unit->Orders[0].Y=-1;
        unit->SubAction=SUB_MOVE_TO_DEPOT;
        NewResetPath(unit);
     }
-    
+
     CheckUnitToBeDrawn(unit);
     if( IsOnlySelected(unit) ) {
        SelectedUnitChanged();
@@ -337,8 +373,6 @@
        unit->SubAction=0;
        return 0;
     }
-
-    DebugCheck( MapDistanceToUnit(unit->X,unit->Y,goal)!=1 );
 
     DebugCheck( unit->Wait!=1 );
 
Index: stratagus/src/action/actions.c
diff -u stratagus/src/action/actions.c:1.87 stratagus/src/action/actions.c:1.88
--- stratagus/src/action/actions.c:1.87 Thu Aug 21 03:12:03 2003
+++ stratagus/src/action/actions.c      Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: actions.c,v 1.87 2003/08/21 07:12:03 n0body Exp $
+//     $Id: actions.c,v 1.88 2003/08/24 18:48:03 n0body Exp $
 
 //@{
 
@@ -90,7 +90,7 @@
     DebugLevel3("Heading %d +%d,%d\n" _C_ unit->Direction _C_ unit->IX _C_ 
unit->IY);
     
     if( unit->Frame<0 ) {
-       unit->Frame+=-animation[state].Frame;
+       unit->Frame-=animation[state].Frame;
     } else {
        unit->Frame+=animation[state].Frame;
     }
Index: stratagus/src/ai/ai.c
diff -u stratagus/src/ai/ai.c:1.45 stratagus/src/ai/ai.c:1.46
--- stratagus/src/ai/ai.c:1.45  Thu Aug 21 17:55:45 2003
+++ stratagus/src/ai/ai.c       Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai.c,v 1.45 2003/08/21 21:55:45 n0body Exp $
+//      $Id: ai.c,v 1.46 2003/08/24 18:48:03 n0body Exp $
 
 //@{
 
@@ -249,6 +249,7 @@
     int nunits;
     int num;
     int i;
+    int x;
     Unit *unit;
 
     nunits = FindPlayerUnitsByType(AiPlayer->Player,
@@ -259,9 +260,13 @@
     //
     for (num = i = 0; i < nunits; i++) {
        unit = table[i];
-       if (unit->Orders[0].Action != UnitActionBuild
-               && (unit->OrderCount==1
-                   || unit->Orders[1].Action != UnitActionBuild) ) {
+       for (x=0;x<unit->OrderCount;x++) {
+           if (unit->Orders[x].Action == UnitActionBuild ||
+                   unit->Orders[x].Action == UnitActionRepair ) {
+               break;
+           }
+       }
+       if (x==unit->OrderCount) {
            table[num++] = unit;
        }
     }
@@ -915,7 +920,7 @@
        }
        ++addy;
     }
-    DebugLevel0Fn("no wood reachable\n");
+    DebugLevel3Fn("no wood reachable\n");
     return 0;
 }
 
@@ -1185,6 +1190,7 @@
        return 1;
     }
     if (!PlayerCheckFood(player, type)) {
+       DebugLevel3Fn("%d needs food.\n" _C_ AiPLayer->Player->Player);
        // already building new food (farm or hall)
        if (AiBuildingUnitType(UnitTypeByWcNum(AiChooseRace(UnitFarm)))
                || AiBuildingUnitType(
@@ -1267,7 +1273,7 @@
 */
 local int AiCommandBuild(int type, int number, int action)
 {
-    DebugLevel3Fn("%s(%d), %d, %d\n" _C_
+    DebugLevel0Fn("%s(%d), %d, %d\n" _C_
            UnitTypeByWcNum(type)->Ident _C_ type _C_ number _C_ action);
 
     if (number == 0)
@@ -1431,7 +1437,7 @@
 */
 global void AiNeedMoreFarms(Unit* unit,const UnitType* what)
 {
-    DebugLevel1Fn("%d: %d(%s) need more farms %s at %d,%d\n" _C_
+    DebugLevel3Fn("%d: %d(%s) need more farms %s at %d,%d\n" _C_
            unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident _C_
            what->Ident _C_ unit->X _C_ unit->Y);
 
Index: stratagus/src/ai/ai_building.c
diff -u stratagus/src/ai/ai_building.c:1.35 stratagus/src/ai/ai_building.c:1.36
--- stratagus/src/ai/ai_building.c:1.35 Sun Aug 10 22:14:45 2003
+++ stratagus/src/ai/ai_building.c      Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_building.c,v 1.35 2003/08/11 02:14:45 n0body Exp $
+//      $Id: ai_building.c,v 1.36 2003/08/24 18:48:03 n0body Exp $
 
 #ifdef NEW_AI  // {
 
@@ -270,7 +270,7 @@
     matrix[x+y*w]=1;                           // mark start point
 
     //
-    // Pop a point from stack, push all neightbors which could be entered.
+    // Pop a point from stack, push all neighbours which could be entered.
     //
     for( ;; ) {
        while( rp!=ep ) {
@@ -284,6 +284,9 @@
                    continue;
                }
 
+               DebugLevel3Fn("Checking to build %s(%s) at %d,%d\n"
+                       _C_ type->Ident _C_ type->Name _C_ x _C_ y);
+
                //
                //      Look if we can build here.
                //
@@ -292,6 +295,7 @@
                    *dx=x;
                    *dy=y;
                    free(points);
+                   DebugLevel3Fn("Found a building place!!!\n");
                    return 1;
                }
 
@@ -569,7 +573,7 @@
                //      Look if there is wood
                //
                if ( ForestOnMap(x,y) ) {
-                   if( AiFindBuildingPlace2(worker,type,x,y,dx,dy,0) ) {
+                   if( AiFindBuildingPlace2(worker,type,x,y,dx,dy,1) ) {
                        free(morg);
                        free(points);
                        return 1;
@@ -626,7 +630,9 @@
     //
     // Find a good place for a new hall
     //
+    DebugLevel3Fn("building is  a %s(%s)\n" _C_ type->Ident _C_ type->Name);
     if( type->CanStore[GoldCost] && AiFindHallPlace(worker,type,dx,dy) ) {
+       DebugLevel3Fn("found 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.63 stratagus/src/ai/ai_resource.c:1.64
--- stratagus/src/ai/ai_resource.c:1.63 Thu Aug 21 17:55:45 2003
+++ stratagus/src/ai/ai_resource.c      Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: ai_resource.c,v 1.63 2003/08/21 21:55:45 n0body Exp $
+//      $Id: ai_resource.c,v 1.64 2003/08/24 18:48:03 n0body Exp $
 
 #ifdef NEW_AI  // {
 
@@ -130,6 +130,7 @@
     int remaining;
     const AiBuildQueue* queue;
 
+    DebugLevel3Fn(" for player %d\n" _C_ pai->Player->Player);
     //
     // Count food supplies under construction.
     //
@@ -141,13 +142,14 @@
            remaining+=queue->Made*queue->Type->Supply;
        }
     }
-    DebugLevel3Fn("Remain %d\n" _C_ remaining);
+    DebugLevel3Fn("Remain %d" _C_ remaining);
     //
     // We are already out of food.
     //
     remaining+=pai->Player->Food-pai->Player->NumFoodUnits-type->Demand;
     DebugLevel3Fn("-Demand %d\n" _C_ remaining);
     if( remaining<0 ) {
+       DebugLevel3Fn(" player %d needs more food\n" _C_ pai->Player->Player);
        return 0;
     }
 
@@ -159,6 +161,7 @@
            DebugLevel3Fn("Trained %d remain %d\n"
                _C_ queue->Made _C_ remaining);
            if( (remaining-=queue->Made*queue->Type->Demand)<0 ) {
+               DebugLevel3Fn(" player %d needs more food\n" _C_ 
pai->Player->Player);
                return 0;
            }
        }
@@ -271,8 +274,13 @@
     nunits = FindPlayerUnitsByType(AiPlayer->Player,type,table);
     for (num = i = 0; i < nunits; i++) {
        unit = table[i];
-       if (unit->Orders[0].Action != UnitActionBuild
-               && unit->Orders[0].Action != UnitActionRepair ) {
+       for (x=0;x<unit->OrderCount;x++) {
+           if (unit->Orders[x].Action == UnitActionBuild
+                   || unit->Orders[x].Action == UnitActionRepair ) {
+               break;
+           }
+       }
+       if (x==unit->OrderCount) {
            table[num++] = unit;
        }
     }
@@ -289,7 +297,7 @@
            continue;
        }
 
-       DebugLevel3Fn("Have a building place %d,%d :)\n" _C_ x _C_ y);
+       DebugLevel3Fn("Have a building place %d,%d for %s:)\n" _C_ x _C_ y _C_ 
building->Name);
 
        CommandBuildBuilding(unit, x, y, building,FlushCommands);
 
@@ -329,7 +337,7 @@
            return;
        }
 
-       DebugLevel3Fn("Must build: %s " _C_ type->Ident);
+       DebugLevel3Fn("Must build: %s\n" _C_ type->Ident);
        //
        //      Check if resources available.
        //
@@ -411,6 +419,8 @@
     AiUnitTypeTable* const* tablep;
     const AiUnitTypeTable* table;
 
+    DebugLevel3Fn(":%s\n" _C_ type->Name);
+
     //
     // Check if we have a place for building or an unit to build.
     //
@@ -438,6 +448,7 @@
        //      The type for builder/trainer is available
        //
        if( unit_count[table->Table[i]->Type] ) {
+           DebugLevel3("Found a builder for a %s.\n" _C_ type->ident);
            if( type->Building ) {
                if( AiBuildBuilding(table->Table[i],type) ) {
                    return 1;
@@ -660,6 +671,7 @@
 
     // Food has the highest priority
     if( AiPlayer->NeedFood ) {
+       DebugLevel3Fn("player %d needs food.\n" _C_ AiPlayer->Player->Player);
        if( !(AiPlayer->UnitTypeBuilded && 
AiPlayer->UnitTypeBuilded->Type->Supply) ) {
            AiPlayer->NeedFood=0;
            AiRequestFarms();
@@ -672,7 +684,7 @@
     for( queue=AiPlayer->UnitTypeBuilded; queue; queue=queue->Next ) {
        if( queue->Want>queue->Made ) {
            type=queue->Type;
-           DebugLevel3Fn("Must build: %s " _C_ type->Ident);
+           DebugLevel3Fn("Must build: %s\n" _C_ type->Ident);
 
            //
            //  FIXME: must check if requirements are fulfilled.
@@ -692,7 +704,6 @@
            if( !type->Building ) {
                // Count future
                if(  !AiCheckFood(AiPlayer,type) ) {
-                   DebugLevel3Fn("Need food\n");
                    AiPlayer->NeedFood=1;
                    AiRequestFarms();
                }
@@ -924,7 +935,7 @@
     DebugLevel3Fn("%d\n" _C_ UnitNumber(unit));
     dest = AiFindGoldMine(unit);
     if (!dest) {
-       DebugLevel0Fn("goldmine not reachable by %s(%d,%d)\n"
+       DebugLevel3Fn("goldmine not reachable by %s(%d,%d)\n"
                _C_ unit->Type->Ident _C_ unit->X _C_ unit->Y);
        return 0;
     }
@@ -1172,7 +1183,7 @@
        ep=wp;
     }
 
-    DebugLevel0Fn("no wood in range by %s(%d,%d)\n"
+    DebugLevel3Fn("no wood in range by %s(%d,%d)\n"
            _C_ unit->Type->Ident _C_ unit->X _C_ unit->Y);
 
     free(points);
@@ -1191,7 +1202,7 @@
     DebugLevel3Fn("%d\n" _C_ UnitNumber(unit));
     dest = FindResource(unit->Player, unit->X, unit->Y 
,unit->Type->ResourceHarvested);
     if (!dest) {
-       DebugLevel0Fn("oil platform not reachable by %s(%d,%d)\n"
+       DebugLevel3Fn("oil platform not reachable by %s(%d,%d)\n"
                _C_ unit->Type->Ident _C_ unit->X _C_ unit->Y);
        return 0;
     }
@@ -1269,7 +1280,8 @@
        //
        //  Send workers with resources back home.
        //
-       if (unit->Value) {
+       if (unit->Value||unit->Type==UnitTypeHumanWorkerWithWood
+               ||unit->Type==UnitTypeOrcWorkerWithWood) {
            units_with_resource[num_units_with_resource[c]++][c]=unit;
            if (unit->Orders[0].Action == UnitActionStill
                    && unit->OrderCount==1 ) {
@@ -1325,8 +1337,8 @@
        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_ 
total);
 
     //
     // Reassign workers
@@ -1636,13 +1648,13 @@
     for( i=k; i<n; ++i ) {
        unit=AiPlayer->Player->Units[i];
        repair_flag=1;
-       // Unit defekt?
+       // Unit damaged?
        if( unit->Type->Building
                && unit->Orders[0].Action!=UnitActionBuilded
                && unit->Orders[0].Action!=UnitActionUpgradeTo
                && unit->HP<unit->Stats->HitPoints ) {
 
-           DebugLevel0Fn("Have building to repair %d(%s)\n" _C_
+           DebugLevel2Fn("Have building to repair %d(%s)\n" _C_
                    UnitNumber(unit) _C_ unit->Type->Ident);
 
            //
@@ -1716,7 +1728,7 @@
     //
     if( !AiPlayer->NeedFood
            && AiPlayer->Player->NumFoodUnits==AiPlayer->Player->Food ) {
-       DebugLevel1Fn("Farm in advance request\n");
+       DebugLevel3Fn("Farm in advance request\n");
        AiRequestFarms();
     }
     //
Index: stratagus/src/ai/ccl_ai.c
diff -u stratagus/src/ai/ccl_ai.c:1.65 stratagus/src/ai/ccl_ai.c:1.66
--- stratagus/src/ai/ccl_ai.c:1.65      Sat Aug  2 09:34:24 2003
+++ stratagus/src/ai/ccl_ai.c   Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_ai.c,v 1.65 2003/08/02 13:34:24 grumbel Exp $
+//     $Id: ccl_ai.c,v 1.66 2003/08/24 18:48:03 n0body Exp $
 
 //@{
 
@@ -741,7 +741,7 @@
     if( AiPlayer->Force[force].Completed ) {
        return SCM_BOOL_F;
     }
-    DebugLevel0Fn("Wait force %d\n" _C_ force);
+    DebugLevel3Fn("Wait force %d\n" _C_ force);
 #if 0
     // Debuging
     AiCleanForces();
Index: stratagus/src/ai/new_ai.c
diff -u stratagus/src/ai/new_ai.c:1.70 stratagus/src/ai/new_ai.c:1.71
--- stratagus/src/ai/new_ai.c:1.70      Thu Aug 21 17:55:45 2003
+++ stratagus/src/ai/new_ai.c   Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//      $Id: new_ai.c,v 1.70 2003/08/21 21:55:45 n0body Exp $
+//      $Id: new_ai.c,v 1.71 2003/08/24 18:48:03 n0body Exp $
 
 #ifdef NEW_AI  // {
 
@@ -816,7 +816,7 @@
 global void SaveAi(CLFile* file)
 {
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: AI $Id: new_ai.c,v 1.70 2003/08/21 21:55:45 
n0body Exp $\n\n");
+    CLprintf(file,";;; MODULE: AI $Id: new_ai.c,v 1.71 2003/08/24 18:48:03 
n0body Exp $\n\n");
 
     SaveAiTypesWcName(file);
     SaveAiHelper(file);
@@ -1281,7 +1281,7 @@
 */
 global void AiCanNotBuild(Unit* unit,const UnitType* what)
 {
-    DebugLevel1Fn("%d: %d(%s) Can't build %s at %d,%d\n" _C_
+    DebugLevel0Fn("%d: %d(%s) Can't build %s at %d,%d\n" _C_
            unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident
            _C_ what->Ident _C_ unit->X _C_ unit->Y);
 
@@ -1298,7 +1298,7 @@
 */
 global void AiCanNotReach(Unit* unit,const UnitType* what)
 {
-    DebugLevel1Fn("%d: %d(%s) Can't reach %s at %d,%d\n" _C_
+    DebugLevel3Fn("%d: %d(%s) Can't reach %s at %d,%d\n" _C_
            unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident _C_
            what->Ident _C_ unit->X _C_ unit->Y);
 
@@ -1316,7 +1316,7 @@
 global void AiNeedMoreFarms(Unit* unit,
        const UnitType* what __attribute__((unused)))
 {
-    DebugLevel1Fn("%d: %d(%s) need more farms %s at %d,%d\n" _C_
+    DebugLevel3Fn("%d: %d(%s) need more farms %s at %d,%d\n" _C_
            unit->Player->Player _C_ UnitNumber(unit) _C_ unit->Type->Ident _C_
            what->Ident _C_ unit->X _C_ unit->Y);
 
Index: stratagus/src/clone/unit.c
diff -u stratagus/src/clone/unit.c:1.288 stratagus/src/clone/unit.c:1.289
--- stratagus/src/clone/unit.c:1.288    Thu Aug 21 17:55:45 2003
+++ stratagus/src/clone/unit.c  Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unit.c,v 1.288 2003/08/21 21:55:45 n0body Exp $
+//     $Id: unit.c,v 1.289 2003/08/24 18:48:03 n0body Exp $
 
 //@{
 
@@ -358,6 +358,7 @@
 
     unit->OrderCount = 1;              // No orders
     unit->Orders[0].Action = UnitActionStill;
+    unit->Orders[0].X=unit->Orders[0].Y=-1;
     DebugCheck(unit->Orders[0].Goal);
     unit->NewOrder.Action = UnitActionStill;
     DebugCheck(unit->NewOrder.Goal);
@@ -565,7 +566,7 @@
 global void AddUnitInContainer(Unit* unit, Unit* host)
 {
     if (unit->Container) {
-       printf("Unit is already contained.\n");
+       DebugLevel0Fn("Unit is already contained.\n");
        exit(0);
     }
     unit->Container=host;
@@ -591,11 +592,11 @@
     Unit* host;
     host=unit->Container;
     if (!unit->Container) {
-       printf("Unit not contained.\n");
+       DebugLevel0Fn("Unit not contained.\n");
        exit(0);
     }
     if (host->InsideCount==0) {
-       printf("host's inside count reached -1.");
+       DebugLevel0Fn("host's inside count reached -1.");
        exit(0);
     }
     host->InsideCount--;
@@ -3798,10 +3799,8 @@
                CLprintf(file,"\n  'data-builded '(worker %s",
                        ref=UnitReference(unit->Data.Builded.Worker));
                free(ref);
-               CLprintf(file," sum %d add %d val %d sub %d frame %d",
-                       unit->Data.Builded.Sum,unit->Data.Builded.Add,
-                       unit->Data.Builded.Val,unit->Data.Builded.Sub,
-                       frame);
+               CLprintf(file," progress %d frame %d",
+                       unit->Data.Builded.Progress,frame);
                if( unit->Data.Builded.Cancel ) {
                    CLprintf(file," cancel");
                }
@@ -3872,7 +3871,7 @@
     int InRun, RunStart;
 
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: units $Id: unit.c,v 1.288 2003/08/21 21:55:45 
n0body Exp $\n\n");
+    CLprintf(file,";;; MODULE: units $Id: unit.c,v 1.289 2003/08/24 18:48:03 
n0body Exp $\n\n");
 
     //
     // Local variables
Index: stratagus/src/clone/unit_draw.c
diff -u stratagus/src/clone/unit_draw.c:1.153 
stratagus/src/clone/unit_draw.c:1.154
--- stratagus/src/clone/unit_draw.c:1.153       Thu Aug 21 03:57:54 2003
+++ stratagus/src/clone/unit_draw.c     Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unit_draw.c,v 1.153 2003/08/21 07:57:54 n0body Exp $
+//     $Id: unit_draw.c,v 1.154 2003/08/24 18:48:03 n0body Exp $
 
 //@{
 
@@ -130,7 +130,7 @@
 
     // If building mark all own buildings
     if( CursorBuilding && unit->Type->Building && unit->Player==ThisPlayer ) {
-       return ColorGray;
+       return ColorGray;       
     }
     return -1;
 }
@@ -145,16 +145,21 @@
     int color;
     int x;
     int y;
+    UnitType* type;
+
+    type=unit->Type;
     
     color=SelectionColor(unit);
     if (color<0) {
        return;
     }
     x=Map2ViewportX(CurrentViewport,unit->X)+unit->IX
-       +unit->Type->TileWidth*TileSizeX/2-unit->Type->BoxWidth/2;
+       +type->TileWidth*TileSizeX/2-type->BoxWidth/2
+       -(type->Width-VideoGraphicWidth(type->Sprite))/2;
     y=Map2ViewportY(CurrentViewport,unit->Y)+unit->IY
-       +unit->Type->TileHeight*TileSizeY/2-unit->Type->BoxHeight/2;
-    DrawSelection(color,x,y,x+unit->Type->BoxWidth,y+unit->Type->BoxHeight);
+       +type->TileHeight*TileSizeY/2-type->BoxHeight/2
+       -(type->Height-VideoGraphicHeight(type->Sprite))/2;
+    DrawSelection(color,x,y,x+type->BoxWidth,y+type->BoxHeight);
 }
 
 /**
@@ -572,7 +577,7 @@
 global void SaveDecorations(CLFile* file)
 {
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: decorations $Id: unit_draw.c,v 1.153 2003/08/21 
07:57:54 n0body Exp $\n\n");
+    CLprintf(file,";;; MODULE: decorations $Id: unit_draw.c,v 1.154 2003/08/24 
18:48:03 n0body Exp $\n\n");
 
     CLprintf(file,"(mana-sprite \"%s\"  %d %d  %d %d)\n",
        ManaSprite.File,ManaSprite.HotX,ManaSprite.HotY,
@@ -815,40 +820,51 @@
                if( ShowHealthBackgroundLong ) {
 #if defined(DEBUG)
                    // Johns: I want to see fast moving.
-                   //VideoFillRectangleClip(unit->Data.Move.Fast
+                   // VideoFillRectangleClip(unit->Data.Move.Fast
                    // Johns: I want to see the AI active flag
-                   VideoFillRectangleClip(unit->Active
-                           ? ColorBlack : ColorWhite
+                   VideoFillRectangleClip(unit->Active? ColorBlack : ColorWhite
+                       ,x+((type->TileWidth*TileSizeX-type->BoxWidth)/2)
+                       ,(y+(type->TileHeight*TileSizeY-type->BoxHeight)/2)
+                               +type->BoxHeight+1
+                       ,type->BoxHeight+1
+                       ,5);
 #else
                    VideoFillRectangleClip(ColorBlack
-#endif
-                       ,x+((type->TileWidth*TileSizeX-type->BoxWidth)/2)
+                        ,x+((type->TileWidth*TileSizeX-type->BoxWidth)/2)
                        ,(y+(type->TileHeight*TileSizeY-type->BoxHeight)/2)
                                +type->BoxHeight+1
                        ,type->BoxHeight+1
                        ,5);
+
+#endif
                } else {
 #if defined(DEBUG)
                    // Johns: I want to see fast moving.
-                   VideoFillRectangleClip(unit->Data.Move.Fast
-                           ? ColorBlack : ColorWhite
+                   
VideoFillRectangleClip(unit->Data.Move.Fast?ColorBlack:ColorWhite
+                       ,x+((type->TileWidth*TileSizeX-type->BoxWidth)/2)
+                       ,(y+(type->TileHeight*TileSizeY-type->BoxHeight)/2)
+                               +type->BoxHeight+1
+                       ,((f*type->BoxHeight)/100)+1
+                       ,5);
+
 #else
                    VideoFillRectangleClip(ColorBlack
-#endif
                        ,x+((type->TileWidth*TileSizeX-type->BoxWidth)/2)
                        ,(y+(type->TileHeight*TileSizeY-type->BoxHeight)/2)
                                +type->BoxHeight+1
                        ,((f*type->BoxHeight)/100)+1
                        ,5);
+#endif
                }
-              w = (f*type->BoxHeight)/100-1;
-              if ( w > 0 ) // Prevents -1 turning into unsigned int
+                w = (f*type->BoxHeight)/100-1;
+                if ( w > 0 ) { // Prevents -1 turning into unsigned int
                VideoFillRectangleClip(color
                    ,x+((type->TileWidth*TileSizeX-type->BoxWidth)/2)+1
                    ,(y+(type->TileHeight*TileSizeY-type->BoxHeight)/2)
                            +type->BoxHeight+2
                    ,w
                    ,3);
+               }
            }  else  {
                VideoFillRectangleClip(color
                    ,x+(type->TileWidth*TileSizeX
@@ -1330,28 +1346,41 @@
 }
 
 /**
-**     Get the location of an order.
+**     Get the location of an unit's order.
 **     
+**     @param order    Pointer to unit.
 **     @param order    Pointer to order.
 **     @param x        Resulting screen X cordinate.
 **     @param x        Resulting screen Y cordinate.
 */
-local void GetOrderPosition(const Order* order,int* x,int* y)
+local void GetOrderPosition(const Unit* unit,const Order* order,int* x,int* y)
 {
     Unit* goal;
     // FIXME: n0body: Check for goal gone?
     if ((goal=order->Goal)&&(!goal->Removed)) {
+       // Order has a goal, get it's location.
        *x = 
Map2ViewportX(CurrentViewport,goal->X)+goal->IX+goal->Type->TileWidth*TileSizeX/2;
        *y = 
Map2ViewportY(CurrentViewport,goal->Y)+goal->IY+goal->Type->TileHeight*TileSizeY/2;
     } else {
-       *x = Map2ViewportX(CurrentViewport,order->X)+TileSizeX/2;
-       *y = Map2ViewportY(CurrentViewport,order->Y)+TileSizeY/2;
+       if (order->X>=0 && order->Y >=0) {
+           // Order is for a location, show that.
+           *x = Map2ViewportX(CurrentViewport,order->X)+TileSizeX/2;
+           *y = Map2ViewportY(CurrentViewport,order->Y)+TileSizeY/2;
+       } else {
+           // Some orders ignore x,y (like StandStill).
+           // Use the unit's position instead.
+           
*x=Map2ViewportX(CurrentViewport,unit->X)+unit->IX+unit->Type->TileWidth*TileSizeX/2;
+           
*y=Map2ViewportY(CurrentViewport,unit->Y)+unit->IY+unit->Type->TileHeight*TileSizeY/2;
+       }
        if (order->Action==UnitActionBuild) {
+           // FIXME: mr-russ, can this be removed? since the build order now 
has a goal?
+           // When building a building point to the center of the would-be 
building.
            // The -1 is because of what we have above.
            *x += (order->Type->TileWidth-1)*TileSizeX/2;
            *y += (order->Type->TileHeight-1)*TileSizeY/2;
        }
     }
+    DebugLevel3Fn(": (%d,%d)\n" _C_ order->X _C_ order->Y);
 }
 
 /**
@@ -1370,7 +1399,7 @@
     int e_color;
     int dest;
 
-    GetOrderPosition(order,&x2,&y2);
+    GetOrderPosition(unit,order,&x2,&y2);
     
     dest = 0;
     switch (order->Action) {
@@ -1519,7 +1548,7 @@
     ShowSingleOrder(unit, x1, y1, unit->Orders);
 #if 1
     for (i=1;i<unit->OrderCount;i++) {
-       GetOrderPosition(unit->Orders+i-1,&x1,&y1);
+       GetOrderPosition(unit,unit->Orders+i-1,&x1,&y1);
        ShowSingleOrder(unit,x1,y1,unit->Orders+i);
     }
 #endif
@@ -1755,11 +1784,15 @@
        state = unit->SeenState;
     }
 
-    DebugCheck( frame==UnitNotSeen );
-
     x+=Map2ViewportX(CurrentViewport,unit->X);
     y+=Map2ViewportY(CurrentViewport,unit->Y);
 
+    if( frame==UnitNotSeen ) {
+       DebugLevel0Fn("Something is wrong, please send us the log of your 
game.\n");
+       DrawUnitSelection(unit);
+       return;
+    }
+    
     DrawShadow(unit,x,y);
 
     //
Index: stratagus/src/include/unit.h
diff -u stratagus/src/include/unit.h:1.207 stratagus/src/include/unit.h:1.208
--- stratagus/src/include/unit.h:1.207  Thu Aug 21 03:12:03 2003
+++ stratagus/src/include/unit.h        Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unit.h,v 1.207 2003/08/21 07:12:03 n0body Exp $
+//     $Id: unit.h,v 1.208 2003/08/24 18:48:03 n0body Exp $
 
 #ifndef __UNIT_H__
 #define __UNIT_H__
@@ -585,10 +585,7 @@
     }          Move;                   /// ActionMove,...
     struct _order_builded_ {
        Unit*   Worker;                 /// Worker building this unit
-       int     Sum;                    /// HP sum for building
-       int     Add;                    /// + to HP and sum
-       int     Val;                    /// Counter (fixed point trick)
-       int     Sub;                    /// - to counter
+       int     Progress;               /// Progress counter, in 1/100 cycles.
        int     Cancel;                 /// Cancel construction
        ConstructionFrame* Frame;       /// Construction frame
     }          Builded;                /// ActionBuilded,...
Index: stratagus/src/include/unittype.h
diff -u stratagus/src/include/unittype.h:1.98 
stratagus/src/include/unittype.h:1.99
--- stratagus/src/include/unittype.h:1.98       Thu Aug 21 17:55:45 2003
+++ stratagus/src/include/unittype.h    Sun Aug 24 14:48:03 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unittype.h,v 1.98 2003/08/21 21:55:45 n0body Exp $
+//     $Id: unittype.h,v 1.99 2003/08/24 18:48:03 n0body Exp $
 
 #ifndef __UNITTYPE_H__
 #define __UNITTYPE_H__
@@ -330,15 +330,25 @@
 **
 **             Cycles the unit waits while inside a resource.
 **
-**     UnitType::WaitAtDepot
+**     UnitType::ResourceStep
 **
-**             Cycles the unit waits while inside the depot to unload.
+**             The unit makes so-caled mining cycles. Each mining cycle
+**             it does some sort of animation and gains ResourceStep
+**             resources. You can stop after any number of steps.
+**             when the quantity in the harvester reaches the maximum
+**             (ResourceCapacity) it will return home. I this is 0 then
+**             it's considered infinity, and ResourceCapacity will now
+**             be the limit.
 **
 **     UnitType::ResourceCapacity
 **
 **             Maximum amount of resources a harvester can carry. The
 **             actual amount can be modified while unloading.
 **
+**     UnitType::WaitAtDepot
+**
+**             Cycles the unit waits while inside the depot to unload.
+**
 **     UnitType::TransformWhenEmpty;
 **     
 **             The harvester will transform into another unit when it is
@@ -662,8 +672,9 @@
     unsigned Harvester : 1;            /// Unit is a resource worker.
     unsigned ResourceHarvested;                /// The resource it can harvest.
     unsigned WaitAtResource;           /// Cycles the unit waits while mining.
-    unsigned WaitAtDepot;              /// Cycles the unit waits while 
returning.
+    unsigned ResourceStep;             /// Resources the unit gains per mining 
cycle.
     unsigned ResourceCapacity;         /// Max amount of resources to carry.
+    unsigned WaitAtDepot;              /// Cycles the unit waits while 
returning.
     UnitType* TransformWhenEmpty;      /// UnitType to transform to when empty.
     UnitType* TransformWhenLoaded;     /// UnitType to transform to when 
loaded.
     UnitType* MustBuildOnTop;          /// Must be built on top of something.
Index: stratagus/src/pathfinder/pathfinder.c
diff -u stratagus/src/pathfinder/pathfinder.c:1.51 
stratagus/src/pathfinder/pathfinder.c:1.52
--- stratagus/src/pathfinder/pathfinder.c:1.51  Fri Jul 18 16:26:20 2003
+++ stratagus/src/pathfinder/pathfinder.c       Sun Aug 24 14:48:03 2003
@@ -28,7 +28,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: pathfinder.c,v 1.51 2003/07/18 20:26:20 grumbel Exp $
+//     $Id: pathfinder.c,v 1.52 2003/08/24 18:48:03 n0body Exp $
 
 //@{
 
@@ -375,7 +375,7 @@
     }
 
     if( !reachable ) {
-       DebugLevel1("Can't move to destination, goal unreachable\n");
+       DebugLevel3("Can't move to destination, goal unreachable\n");
        return 0;
     }
 
@@ -394,7 +394,7 @@
     //  Find a path to the place.
     //
     if( (depth=CheckPlaceInMatrix(x1,y1,x2,y2,LocalMatrix)) < 0 ) {
-       DebugLevel1("Can't move to destination, not route to goal\n");
+       DebugLevel3("Can't move to destination, not route to goal\n");
        return 0;
     }
 
Index: stratagus/src/ui/mainscr.c
diff -u stratagus/src/ui/mainscr.c:1.117 stratagus/src/ui/mainscr.c:1.118
--- stratagus/src/ui/mainscr.c:1.117    Thu Aug 21 03:12:03 2003
+++ stratagus/src/ui/mainscr.c  Sun Aug 24 14:48:03 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: mainscr.c,v 1.117 2003/08/21 07:12:03 n0body Exp $
+//     $Id: mainscr.c,v 1.118 2003/08/24 18:48:03 n0body Exp $
 
 //@{
 
@@ -528,6 +528,12 @@
                    ,(100*(CHOP_FOR_WOOD-unit->Value))/CHOP_FOR_WOOD);
            VideoDrawText(x+63,y+8+141,GameFont,buf);
         }
+       // FIXME: Ugly hack.
+       if( 
unit->Type->Harvester&&unit->Value&&unit->Orders[0].Action!=UnitActionHarvest ) 
{
+           sprintf(buf,"Carry: %d %s",unit->Value,
+                   DefaultResourceNames[unit->Type->ResourceHarvested]);
+           VideoDrawText(x+61,y+8+141,GameFont,buf);       
+       }
 
     }
        if( type->CanCastSpell ) {
@@ -542,9 +548,8 @@
                VideoDrawNumber(x+128,y+8+140+1,GameFont,unit->Mana);
            } else {
                int w = 140;
-               /* s0m3body: fix to display mana bar properly for any maxmana
-                  value */
-               /* s0m3body: max mana can vary for the unit */
+               /* fix to display mana bar properly for any maxmana value */
+               /* max mana can vary for the unit */
                i=(100*unit->Mana)/unit->Type->_MaxMana;
                i=(i*w)/100;
                VideoDrawRectangleClip(ColorGray, x+16,  y+8+140, w+4,  16  );
Index: stratagus/src/unit/ccl_unit.c
diff -u stratagus/src/unit/ccl_unit.c:1.63 stratagus/src/unit/ccl_unit.c:1.64
--- stratagus/src/unit/ccl_unit.c:1.63  Sun Aug 10 22:14:46 2003
+++ stratagus/src/unit/ccl_unit.c       Sun Aug 24 14:48:04 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_unit.c,v 1.63 2003/08/11 02:14:46 n0body Exp $
+//     $Id: ccl_unit.c,v 1.64 2003/08/24 18:48:04 n0body Exp $
 
 //@{
 
@@ -344,20 +344,8 @@
            ++UnitSlots[slot]->Refs;
            free(str);
            list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("sum"))) {
-           unit->Data.Builded.Sum = gh_scm2int(gh_car(list));
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("add"))) {
-           unit->Data.Builded.Add = gh_scm2int(gh_car(list));
-           value = gh_car(list);
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("val"))) {
-           unit->Data.Builded.Val = gh_scm2int(gh_car(list));
-           value = gh_car(list);
-           list = gh_cdr(list);
-       } else if (gh_eq_p(value, gh_symbol2scm("sub"))) {
-           unit->Data.Builded.Sub = gh_scm2int(gh_car(list));
-           value = gh_car(list);
+       } else if (gh_eq_p(value, gh_symbol2scm("progress"))) {
+           unit->Data.Builded.Progress = gh_scm2int(gh_car(list));
            list = gh_cdr(list);
        } else if (gh_eq_p(value, gh_symbol2scm("cancel"))) {
            unit->Data.Builded.Cancel = 1;
Index: stratagus/src/unit/ccl_unittype.c
diff -u stratagus/src/unit/ccl_unittype.c:1.75 
stratagus/src/unit/ccl_unittype.c:1.76
--- stratagus/src/unit/ccl_unittype.c:1.75      Thu Aug 21 17:55:45 2003
+++ stratagus/src/unit/ccl_unittype.c   Sun Aug 24 14:48:04 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_unittype.c,v 1.75 2003/08/21 21:55:45 n0body Exp $
+//     $Id: ccl_unittype.c,v 1.76 2003/08/24 18:48:04 n0body Exp $
 
 //@{
 
@@ -643,11 +643,12 @@
 global UnitType* CclGetUnitType(SCM ptr)
 {
     char* str;
+    UnitType* type;
 
     // Be kind allow also strings or symbols
     if( (str = CclConvertToString(ptr)) != NULL )  {
         DebugLevel3("CclGetUnitType: %s\n"_C_ str);
-        UnitType* type = UnitTypeByIdent(str);
+        type = UnitTypeByIdent(str);
         free(str);
         return type;
     } else if (CclGetSmobType(ptr) == SiodUnitTypeTag)  {
Index: stratagus/src/unit/unittype.c
diff -u stratagus/src/unit/unittype.c:1.87 stratagus/src/unit/unittype.c:1.88
--- stratagus/src/unit/unittype.c:1.87  Thu Aug 21 17:55:45 2003
+++ stratagus/src/unit/unittype.c       Sun Aug 24 14:48:04 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unittype.c,v 1.87 2003/08/21 21:55:45 n0body Exp $
+//     $Id: unittype.c,v 1.88 2003/08/24 18:48:04 n0body Exp $
 
 //@{
 
@@ -995,9 +995,9 @@
 local void SaveUnitStats(const UnitStats* stats,const char* ident,int plynr,
        CLFile* file)
 {
-    DebugCheck(plynr>=PlayerMax);
     int j;
-
+    
+    DebugCheck(plynr>=PlayerMax);
     CLprintf(file,"(define-unit-stats '%s %d\n  ",ident,plynr);
     CLprintf(file,"'level %d ",stats->Level);
     CLprintf(file,"'speed %d ",stats->Speed);
@@ -1034,7 +1034,7 @@
     char **sp;
 
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: unittypes $Id: unittype.c,v 1.87 2003/08/21 
21:55:45 n0body Exp $\n\n");
+    CLprintf(file,";;; MODULE: unittypes $Id: unittype.c,v 1.88 2003/08/24 
18:48:04 n0body Exp $\n\n");
 
     // Original number to internal unit-type name.
 
@@ -1327,6 +1327,7 @@
     void** ptr;
     int i;
     int j;
+    Animations* anims;
 
     DebugLevel0Fn("FIXME: icon, sounds not freed.\n");
 
@@ -1348,7 +1349,6 @@
     for( i=0; i<NumUnitTypes; ++i )
     {
        type=UnitTypes[i];
-       Animations* anims;
 
        if( !(anims=type->Animations) ) {       // Must be handled?
            continue;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]