stratagus-cvs
[Top][All Lists]
Advanced

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

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


From: Crestez Leonard
Subject: [Stratagus-CVS] stratagus data/ccl/human/units.ccl src/action/a...
Date: Sat, 11 Oct 2003 15:07:24 -0400

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Crestez Leonard <address@hidden>        03/10/11 15:07:23

Modified files:
        data/ccl/human : units.ccl 
        src/action     : action_resource.c 
        src/missile    : missile.c 
        src/video      : X11.c 

Log message:
        Fixed resource bug

Patches:
Index: stratagus/data/ccl/human/units.ccl
diff -u stratagus/data/ccl/human/units.ccl:1.40 
stratagus/data/ccl/human/units.ccl:1.41
--- stratagus/data/ccl/human/units.ccl:1.40     Thu Oct  9 07:31:42 2003
+++ stratagus/data/ccl/human/units.ccl  Sat Oct 11 15:07:21 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.40 2003/10/09 11:31:42 n0body Exp $
+;;     $Id: units.ccl,v 1.41 2003/10/11 19:07:21 n0body Exp $
 
 ;;=============================================================================
 ;;     Define unit-types.
@@ -91,6 +91,7 @@
   'can-gather-resource '(
        file-when-loaded "human/units/peasant_with_gold.png"  
        resource-id gold
+       harvest-from-outside
        resource-capacity 100
        wait-at-resource 150
        wait-at-depot 150 )
Index: stratagus/src/action/action_resource.c
diff -u stratagus/src/action/action_resource.c:1.57 
stratagus/src/action/action_resource.c:1.58
--- stratagus/src/action/action_resource.c:1.57 Fri Oct  3 18:16:26 2003
+++ stratagus/src/action/action_resource.c      Sat Oct 11 15:07:22 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: action_resource.c,v 1.57 2003/10/03 22:16:26 jsalmon3 Exp $
+//     $Id: action_resource.c,v 1.58 2003/10/11 19:07:22 n0body Exp $
 
 //@{
 
@@ -269,6 +269,74 @@
     }
 }
 
+/*
+**     Find something else to do when the resource is exhausted.
+**     This is called from GatherResorce when the resource is empty.
+**
+**     @param unit     pointer to harvester unit.
+**     @param source   pointer to resource unit.
+*/
+local void LoseResource(Unit* unit,const Unit* source)
+{
+    Unit* depot;
+    ResourceInfo* resinfo;
+    resinfo = unit->Type->ResInfo[unit->CurrentResource];
+
+    if (unit->Container) {
+       DebugCheck(resinfo->HarvestFromOutside);
+    }
+
+    //
+    //  If we are loaded first search for a depot.
+    // 
+    if (unit->Value && (depot = FindDeposit(unit, unit->X, unit->Y,
+           1000, unit->CurrentResource))) {
+       if (unit->Container) {
+           DropOutNearest(unit, depot->X + depot->Type->TileWidth / 2,
+               depot->Y + depot->Type->TileHeight / 2,
+               source->Type->TileWidth, source->Type->TileHeight);
+       }
+       //
+       //  Remember were it mined, so it can look around for another resource.
+       //  
+       unit->Orders[0].Arg1 = (void*)((unit->X << 16) | unit->Y);
+       unit->Orders[0].Goal = depot;
+       RefsDebugCheck(!depot->Refs);
+       ++depot->Refs;
+       NewResetPath(unit);
+       unit->SubAction = SUB_MOVE_TO_DEPOT;
+       unit->Wait = unit->Reset = 1;
+       unit->State = 0;
+       DebugLevel0Fn("Sent unit %d to depot\n" _C_ unit->Slot);
+       return;
+    }
+    //
+    // No depot found, or harvester empty
+    // Dump the unit outside and look for something to do.
+    //
+    if (unit->Container) {
+       DebugCheck(resinfo->HarvestFromOutside);
+       DropOutOnSide(unit, LookingW, source->Type->TileWidth,
+           source->Type->TileHeight);
+    }
+    unit->Orders[0].X = unit->Orders[0].Y = -1;
+    if ((unit->Orders[0].Goal = FindResource(unit, unit->X, unit->Y,
+           10, unit->CurrentResource))) {
+       DebugLevel0Fn("Unit %d found another resource.\n" _C_ unit->Slot);
+       unit->SubAction = SUB_START_RESOURCE;
+       unit->Wait = unit->Reset = 1;
+       unit->State = 0;
+       RefsDebugCheck(!uins->Orders[0].Goal->Refs);
+       ++unit->Orders[0].Goal->Refs;
+    } else {
+       DebugLevel0Fn("Unit %d just sits around confused.\n" _C_ unit->Slot);
+       unit->Orders[0].Action = UnitActionStill;
+       unit->SubAction = 0;
+       unit->Wait = unit->Reset = 1;
+       unit->State = 0;
+    }
+}
+
 /**
 **     Wait in resource, for collecting the resource.
 **
@@ -279,7 +347,6 @@
 local int GatherResource(Unit* unit)
 {
     Unit* source;
-    Unit* depot;
     Unit* uins;
     ResourceInfo* resinfo;
     int i;
@@ -376,45 +443,14 @@
            //
            if (source->Destroyed || source->Removed || !source->HP ||
                    source->Orders[0].Action == UnitActionDie || source->Value 
== 0) {
-               DebugLevel0Fn("Resource is destroyed\n");
+               DebugLevel0Fn("Resource is destroyed for unit %d\n" _C_ 
unit->Slot);
                uins = source->UnitInside;
                //
                // Improved version of DropOutAll that makes workers go to the 
depot.
-               // FIXME: empty harvesters should find another resource.
                // 
+               LoseResource(unit,source);
                for (i = source->InsideCount; i; --i, uins = 
uins->NextContained) {
-                   if (uins->Value && (depot = FindDeposit(uins, uins->X, 
uins->Y,
-                           1000, unit->CurrentResource))) {
-                       DropOutNearest(uins, depot->X + depot->Type->TileWidth 
/ 2,
-                           depot->Y + depot->Type->TileHeight / 2,
-                           source->Type->TileWidth, source->Type->TileHeight);
-                       //  Remember were it mined, so it can look around for 
another resource.
-                       uins->Orders[0].Arg1 = (void*)((unit->X << 16) | 
unit->Y);
-                       uins->Orders[0].Goal = depot;
-                       RefsDebugCheck(!depot->Refs);
-                       ++depot->Refs;
-                       NewResetPath(uins);
-                       uins->SubAction = SUB_MOVE_TO_DEPOT;
-                       uins->Wait = 1;
-                       DebugLevel0Fn("Sent unit %d to depot\n" _C_ uins->Slot);
-                       continue;
-                   }
-                   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, unit->CurrentResource))) {
-                       DebugLevel0Fn("Unit %d found another resource.\n" _C_ 
uins->Slot);
-                       uins->SubAction = SUB_START_RESOURCE;
-                       uins->Wait = 1;
-                       RefsDebugCheck(!uins->Orders[0].Goal->Refs);
-                       ++uins->Orders[0].Goal->Refs;
-                   } else {
-                       DebugLevel0Fn("Unit %d just sits around confused.\n" 
_C_ uins->Slot);
-                       uins->Orders[0].Action = UnitActionStill;
-                       uins->SubAction = 0;
-                       uins->Wait = unit->Reset = 1;
-                   }
+                   LoseResource(uins,source);
                }
 
                //  Don't destroy the resource twice.
@@ -424,6 +460,7 @@
                    // FIXME: make the workers inside look for a new resource.
                }
                source = NULL;
+               return 0;
            }
        }
        if (resinfo->TerrainHarvester) {
@@ -484,9 +521,9 @@
     unit->Orders[0].Arg1 = (void*)((unit->X << 16) | unit->Y);
  
     if (!unit->Value) {
-       DebugLevel0Fn("Unit is empty???\n");
+       DebugLevel0Fn("Unit %d is empty???\n" _C_ unit->Slot);
     } else {
-       DebugLevel3Fn("Unit is fine, search for a depot.\n");
+       DebugLevel3Fn("Unit %d is fine, search for a depot.\n" _C_ unit->Slot);
     }
     // Find and send to resource deposit.
     if (!(depot = FindDeposit(unit, unit->X, unit->Y, 1000, 
unit->CurrentResource)) ||
@@ -496,7 +533,7 @@
            DropOutOnSide(unit, LookingW, source->Type->TileWidth,
                source->Type->TileHeight);
        }
-       DebugLevel0Fn("Can't find a resource deposit.\n");
+       DebugLevel0Fn("Can't find a resource deposit for unit %d.\n" _C_ 
unit->Slot);
        unit->Orders[0].Action = UnitActionStill;
        unit->SubAction = 0;
        // should return 0, done below!
Index: stratagus/src/missile/missile.c
diff -u stratagus/src/missile/missile.c:1.88 
stratagus/src/missile/missile.c:1.89
--- stratagus/src/missile/missile.c:1.88        Thu Oct  9 19:04:03 2003
+++ stratagus/src/missile/missile.c     Sat Oct 11 15:07:22 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: missile.c,v 1.88 2003/10/09 23:04:03 jsalmon3 Exp $
+//     $Id: missile.c,v 1.89 2003/10/11 19:07:22 n0body Exp $
 
 //@{
 
@@ -1708,7 +1708,7 @@
     int i;
 
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: missile-types $Id: missile.c,v 1.88 2003/10/09 
23:04:03 jsalmon3 Exp $\n\n");
+    CLprintf(file,";;; MODULE: missile-types $Id: missile.c,v 1.89 2003/10/11 
19:07:22 n0body Exp $\n\n");
 
     //
     // Original number to internal missile-type name.
@@ -1803,7 +1803,7 @@
     Missile* const* missiles;
 
     CLprintf(file,"\n;;; -----------------------------------------\n");
-    CLprintf(file,";;; MODULE: missiles $Id: missile.c,v 1.88 2003/10/09 
23:04:03 jsalmon3 Exp $\n\n");
+    CLprintf(file,";;; MODULE: missiles $Id: missile.c,v 1.89 2003/10/11 
19:07:22 n0body Exp $\n\n");
 
     for (missiles = GlobalMissiles; *missiles; ++missiles) {
        SaveMissile(*missiles, file);
Index: stratagus/src/video/X11.c
diff -u stratagus/src/video/X11.c:1.76 stratagus/src/video/X11.c:1.77
--- stratagus/src/video/X11.c:1.76      Wed Oct  1 20:35:19 2003
+++ stratagus/src/video/X11.c   Sat Oct 11 15:07:23 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: X11.c,v 1.76 2003/10/02 00:35:19 jsalmon3 Exp $
+//     $Id: X11.c,v 1.77 2003/10/11 19:07:23 n0body Exp $
 
 //@{
 
@@ -294,6 +294,38 @@
     }
 }
 
+/*
+**     Create empty cursor to work around X11 brain-damage
+**     (can't hide the cursor)
+**
+**     @param display  X11 display
+**     @param root     Window?
+**
+**     @notes: 'stolen' from quake1 source
+*/
+Cursor CreateNullCursor(Display *display, Window root)
+{
+    Pixmap cursormask; 
+    XGCValues xgc;
+    GC gc;
+    XColor dummycolour;
+    Cursor cursor;
+
+    cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
+    xgc.function = GXclear;
+    gc =  XCreateGC(display, cursormask, GCFunction, &xgc);
+    XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
+    dummycolour.pixel = 0;
+    dummycolour.red = 0;
+    dummycolour.flags = 04;
+    cursor = XCreatePixmapCursor(display, cursormask, cursormask,
+          &dummycolour,&dummycolour, 0,0);
+    XFreePixmap(display,cursormask);
+    XFreeGC(display,gc);
+    return cursor;
+}
+
+
 /**
 **     X11 initialize.
 */
@@ -419,7 +451,11 @@
     TheMainDrawable = attributes.background_pixmap =
        XShmCreatePixmap(TheDisplay,DefaultRootWindow(TheDisplay),
            shminfo.shmaddr,&shminfo,VideoWidth, VideoHeight, xvi. depth);
+#if 1
     attributes.cursor = XCreateFontCursor(TheDisplay, XC_tcross - 1);
+#else
+    attributes.cursor = CreateNullCursor(TheDisplay,TheMainDrawable);
+#endif
     attributes.backing_store = NotUseful;
     attributes.save_under = False;
     attributes.event_mask = KeyPressMask | KeyReleaseMask | /*ExposureMask|*/
@@ -1210,7 +1246,7 @@
 **
 **     @return         A hardware dependent pixel.
 */
-global unsigned long VideoMapRGB(int r, int g, int b)
+global VMemType VideoMapRGB(int r, int g, int b)
 {
     XColor color;
     XWindowAttributes xwa;
@@ -1229,7 +1265,7 @@
        //ExitFatal(-1);
     }
 
-    return color.pixel;
+    return (VMemType)(VMemType32)color.pixel;
 }
 
 /**




reply via email to

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