[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus ./Rules.make.in data/ccl/ai.ccl doc/C...
From: |
ludovic pollet |
Subject: |
[Stratagus-CVS] stratagus ./Rules.make.in data/ccl/ai.ccl doc/C... |
Date: |
Wed, 19 Nov 2003 21:23:42 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: ludovic pollet <address@hidden> 03/11/19 21:23:41
Modified files:
. : Rules.make.in
data/ccl : ai.ccl
doc : ChangeLog.html
src/action : action_board.c action_move.c action_unload.c
command.c
src/ai : ai_force.c ai_local.h ccl_ai.c new_ai.c
src/include : actions.h unittype.h
Log message:
AI can use automatically transporters (Task #2852)
Patches:
Index: stratagus/Rules.make.in
diff -u stratagus/Rules.make.in:1.16 stratagus/Rules.make.in:1.17
--- stratagus/Rules.make.in:1.16 Thu Oct 9 11:17:07 2003
+++ stratagus/Rules.make.in Wed Nov 19 21:23:38 2003
@@ -51,7 +51,7 @@
IFLAGS= -I$(TOPDIR)/src/include $(XIFLAGS)
-I$(TOPDIR)/src/movie/vp31/include
address@hidden@ @DEBUG_CFLAGS@ $(IFLAGS) \
- -DUNIT_ON_MAP -DUSE_LIBMODPLUG -DUSE_HP_FOR_XP \
+ -DUNIT_ON_MAP -DUSE_LIBMODPLUG -DUSE_HP_FOR_XP -DMAP_REGIONS\
@PROFILE_CFLAGS@ @DEBUG_CFLAGS@ @VIDEO_CFLAGS@ @BZ2_CFLAGS@ \
@OGG_CFLAGS@ @MAD_CFLAGS@ @FLAC_CFLAGS@ @CDAUDIO_CFLAGS@ @GUILE_CFLAGS@ \
$(CCL) $(VERSION) $(COMP_CFLAGS) @SOUND_CFLAGS@ @PLATFORM@ \
Index: stratagus/data/ccl/ai.ccl
diff -u stratagus/data/ccl/ai.ccl:1.61 stratagus/data/ccl/ai.ccl:1.62
--- stratagus/data/ccl/ai.ccl:1.61 Wed Nov 5 13:00:24 2003
+++ stratagus/data/ccl/ai.ccl Wed Nov 19 21:23:39 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: ai.ccl,v 1.61 2003/11/05 18:00:24 pludov Exp $
+;; $Id: ai.ccl,v 1.62 2003/11/20 02:23:39 pludov Exp $
;(define (ai:sleep) () #t)
@@ -624,10 +624,10 @@
(lambda (script)
(let
((gauges (cdadr script)))
- ;; (force-mini-gauges (cdadr script))
+ ;; (force-mini-gauges (cdadr script))
;; (units_pct (cddr script)))
- (if (ai:check-gauges gauges)
+ (if (ai:check-gauges gauges)
(let
((result 0))
@@ -640,9 +640,11 @@
(ai:force-complete (ai:own-force))
;; compute cost to complete the tmp force
(set! result (ai:evaluate-force-cost (ai:own-force)))
-
- ;; return the computed value
- result
+
+ ;; return the computed value if can transport
+ (if (ai:can-reach-hotspot 'lazy)
+ result
+ -1)
)
;; can't, return -1
-1
@@ -651,25 +653,18 @@
(define ai:ground-get-needs
(lambda (script)
- ;; Check if hotspot is accessible by ground
- (if (ai:can-reach-hotspot 'ground)
- (ai:default-get-needs script)
- -1)))
-
+ ;; Check if hotspot is accessible by ground
+ (ai:default-get-needs script)))
+
(define ai:sea-get-needs
(lambda (script)
- ;; Check if hotspot is accessible by ground
- (if (ai:can-reach-hotspot 'sea)
- (ai:default-get-needs script)
- -1)))
-
+ ;; Check if hotspot is accessible by ground
+ (ai:default-get-needs script)))
+
(define ai:sea-only-get-needs
(lambda (script)
- (if (> (ai:get-gauge 'enemy-hotspot-sea-force) 0)
- ;; Check if hotspot is accessible by ground
- (ai:sea-get-needs script)
- -1)))
-
+ (ai:default-get-needs script)))
+
;;
;; This script is used in the simplest case when :
;; - a force ( defend-force ) is ready
Index: stratagus/doc/ChangeLog.html
diff -u stratagus/doc/ChangeLog.html:1.582 stratagus/doc/ChangeLog.html:1.583
--- stratagus/doc/ChangeLog.html:1.582 Wed Nov 19 21:22:27 2003
+++ stratagus/doc/ChangeLog.html Wed Nov 19 21:23:39 2003
@@ -2,7 +2,7 @@
<html>
<head>
<!--
----- $Id: ChangeLog.html,v 1.582 2003/11/20 02:22:27 pludov Exp $
+---- $Id: ChangeLog.html,v 1.583 2003/11/20 02:23:39 pludov Exp $
---- (c) Copyright 1998-2003 by Lutz Sammer
@@ -36,7 +36,8 @@
<li>Future 2.00 Release<p>
<ul>
<li>++
- <li>Add a map splitter for fast PlaceReachable.
+ <li>AI can use automatically transporters (Task #2852) (from Ludovic
Pollet)
+ <li>Added a map splitter for fast PlaceReachable. (from Ludovic Pollet)
<li>Food, replaced with Supply/Demand. Buildings support demand (from
Russell Smith).
<li>Fixed Bug #6230: Hack to detect wc2 swamp tileset (from Russell Smith).
<li>AI tries to move its own units when blocked (from Pollet Ludovic).
Index: stratagus/src/action/action_board.c
diff -u stratagus/src/action/action_board.c:1.44
stratagus/src/action/action_board.c:1.45
--- stratagus/src/action/action_board.c:1.44 Sun Nov 9 17:13:56 2003
+++ stratagus/src/action/action_board.c Wed Nov 19 21:23:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_board.c,v 1.44 2003/11/09 22:13:56 n0body Exp $
+// $Id: action_board.c,v 1.45 2003/11/20 02:23:40 pludov Exp $
//@{
@@ -157,10 +157,13 @@
if (transporter->InsideCount < transporter->Type->MaxOnBoard) {
RemoveUnit(unit, transporter);
- //Don't make anything funny after going out of the transporter.
- // FIXME: This is probably wrong, but it works for me (n0b0dy)
- unit->OrderCount = 1;
- unit->Orders[0].Action = UnitActionStill;
+ if (!unit->Player->AiEnabled) {
+ //Don't make anything funny after going out of the transporter.
+ // FIXME: This is probably wrong, but it works for me (n0b0dy)
+ unit->OrderCount = 1;
+ unit->Orders[0].Action = UnitActionStill;
+ }
+
if (IsOnlySelected(transporter)) {
SelectedUnitChanged();
MustRedraw |= RedrawInfoPanel;
Index: stratagus/src/action/action_move.c
diff -u stratagus/src/action/action_move.c:1.73
stratagus/src/action/action_move.c:1.74
--- stratagus/src/action/action_move.c:1.73 Fri Nov 14 12:35:50 2003
+++ stratagus/src/action/action_move.c Wed Nov 19 21:23:40 2003
@@ -21,7 +21,7 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
-// $Id: action_move.c,v 1.73 2003/11/14 17:35:50 pludov Exp $
+// $Id: action_move.c,v 1.74 2003/11/20 02:23:40 pludov Exp $
//@{
@@ -101,11 +101,13 @@
switch (d = NextPathElement(unit, &xd, &yd)) {
#endif /* HIERARCHIC_PATHFINDER */
case PF_UNREACHABLE: // Can't reach, stop
- unit->Reset = unit->Wait = 1;
- unit->Moving = 0;
- if (unit->Player->AiEnabled) {
+ if (unit->Player->AiEnabled) {
AiCanNotMove(unit);
}
+
+ unit->Reset = unit->Wait = 1;
+ unit->Moving = 0;
+
return d;
case PF_REACHED: // Reached goal, stop
unit->Reset = unit->Wait = 1;
Index: stratagus/src/action/action_unload.c
diff -u stratagus/src/action/action_unload.c:1.42
stratagus/src/action/action_unload.c:1.43
--- stratagus/src/action/action_unload.c:1.42 Sun Nov 9 17:13:56 2003
+++ stratagus/src/action/action_unload.c Wed Nov 19 21:23:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_unload.c,v 1.42 2003/11/09 22:13:56 n0body Exp $
+// $Id: action_unload.c,v 1.43 2003/11/20 02:23:40 pludov Exp $
//@{
@@ -268,8 +268,8 @@
*resx=x;
*resy=y;
return 1;
- }
-
+ }
+
switch(transporterType) {
case UnitTypeLand:
// in this case, loadedType==UnitTypeSea
@@ -406,6 +406,7 @@
unit->Orders[0].X = x;
unit->Orders[0].Y = y;
}
+
NewResetPath(unit);
unit->SubAction = 1;
case 1:
Index: stratagus/src/action/command.c
diff -u stratagus/src/action/command.c:1.120
stratagus/src/action/command.c:1.121
--- stratagus/src/action/command.c:1.120 Tue Nov 18 12:56:19 2003
+++ stratagus/src/action/command.c Wed Nov 19 21:23:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: command.c,v 1.120 2003/11/18 17:56:19 pludov Exp $
+// $Id: command.c,v 1.121 2003/11/20 02:23:40 pludov Exp $
//@{
@@ -199,6 +199,61 @@
PfHierReleaseData(unit);
#endif
unit->SavedOrder = unit->NewOrder = *order;
+}
+
+/**
+** Order an already formed Order structure
+**
+** @param unit pointer to unit
+** @param order pointer to valid order
+** @param flush if true, flush command queue.
+*/
+global void CommandAnyOrder(Unit* unit,Order * cpyorder,int flush)
+{
+ Order* order;
+ if (!(order = GetNextOrder(unit, flush))) {
+ return;
+ }
+
+ *order = *cpyorder;
+ if (order->Goal) {
+ RefsIncrease(order->Goal);
+ }
+ ClearSavedAction(unit);
+}
+
+/**
+** Move an order in the order queue.
+** ( Cannot move the order 0 ! )
+**
+** @param unit pointer to unit
+** @param src the order to move
+** @param dst the new position of the order
+*/
+global void CommandMoveOrder(Unit * unit,int src,int dst)
+{
+ Order tmp;
+ int i;
+ DebugCheck(src == 0 || dst == 0 || src >= unit->OrderCount || dst >=
unit->OrderCount);
+
+ if (src == dst) {
+ return;
+ }
+
+ if (src < dst) {
+ tmp = unit->Orders[src];
+ for(i = src; i < dst; i++) {
+ unit->Orders[i] = unit->Orders[i+1];
+ }
+ unit->Orders[dst] = tmp;
+ } else {
+ // dst < src
+ tmp = unit->Orders[src];
+ for (i = src - 1 ; i >= dst; i--){
+ unit->Orders[i + 1] = unit->Orders[i];
+ }
+ unit->Orders[dst] = tmp;
+ }
}
/**
Index: stratagus/src/ai/ai_force.c
diff -u stratagus/src/ai/ai_force.c:1.41 stratagus/src/ai/ai_force.c:1.42
--- stratagus/src/ai/ai_force.c:1.41 Sun Nov 9 17:13:56 2003
+++ stratagus/src/ai/ai_force.c Wed Nov 19 21:23:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_force.c,v 1.41 2003/11/09 22:13:56 n0body Exp $
+// $Id: ai_force.c,v 1.42 2003/11/20 02:23:40 pludov Exp $
//@{
@@ -46,6 +46,8 @@
#include "actions.h"
#include "map.h"
#include "depend.h"
+
+#include "pathfinder.h"
/*----------------------------------------------------------------------------
-- Variables
Index: stratagus/src/ai/ai_local.h
diff -u stratagus/src/ai/ai_local.h:1.44 stratagus/src/ai/ai_local.h:1.45
--- stratagus/src/ai/ai_local.h:1.44 Sun Nov 16 01:49:25 2003
+++ stratagus/src/ai/ai_local.h Wed Nov 19 21:23:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_local.h,v 1.44 2003/11/16 06:49:25 mr-russ Exp $
+// $Id: ai_local.h,v 1.45 2003/11/20 02:23:40 pludov Exp $
#ifndef __AI_LOCAL_H__
#define __AI_LOCAL_H__
@@ -257,6 +257,16 @@
AiExplorationRequest*Next; /// Next in linked list
};
+typedef struct _ai_transport_request_ AiTransportRequest;
+
+struct _ai_transport_request_ {
+ Unit* Unit;
+
+ Order Order;
+
+ AiTransportRequest* Next;
+};
+
/**
** AI variables.
*/
@@ -296,6 +306,8 @@
AiExplorationRequest*FirstExplorationRequest;/// Requests for exploration
unsigned int LastExplorationGameCycle;/// When did the last explore
occur ?
+
+ AiTransportRequest* TransportRequests;
unsigned int LastCanNotMoveGameCycle;
/// number of elements in UnitTypeRequests
Index: stratagus/src/ai/ccl_ai.c
diff -u stratagus/src/ai/ccl_ai.c:1.81 stratagus/src/ai/ccl_ai.c:1.82
--- stratagus/src/ai/ccl_ai.c:1.81 Sun Nov 16 01:49:25 2003
+++ stratagus/src/ai/ccl_ai.c Wed Nov 19 21:23:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_ai.c,v 1.81 2003/11/16 06:49:25 mr-russ Exp $
+// $Id: ccl_ai.c,v 1.82 2003/11/20 02:23:40 pludov Exp $
//@{
@@ -1380,63 +1380,24 @@
*/
local SCM CclAiCanReachHotSpot(SCM way)
{
- int wayid, i;
- int x, y, w, h;
+#ifdef MAP_REGIONS
+ ZoneSet targets={0};
+ ZoneSet sources={0};
+ ZoneSet transportable={0};
+ int i;
Unit *unit;
-
-
+ int transporterplace;
+ UnitType * transporter;
+ AiUnit * aiunit;
+
if ((AiScript->HotSpot_X == -1) || (AiScript->HotSpot_Y == -1)
|| (AiScript->HotSpot_Ray <= 0)) {
return SCM_BOOL_T;
}
-
- wayid = -1;
- // Air is always accessible...
- if (gh_eq_p(way, gh_symbol2scm("air"))) {
- wayid = 0;
- }
- if (gh_eq_p(way, gh_symbol2scm("ground"))) {
- wayid = 1;
- }
- if (gh_eq_p(way, gh_symbol2scm("sea"))) {
- wayid = 2;
- }
-
- if (wayid == -1) {
- errl("Unknown way ", way);
- }
- // Calculate a rectangle...
- // FIXME : Why 2 ?
- x = AiScript->HotSpot_X - 2;
- y = AiScript->HotSpot_Y - 2;
- w = 5;
- h = 5;
-
- // clip it
- if (x < 0) {
- w += x;
- x = 0;
- }
- if (y < 0) {
- h += y;
- y = 0;
- }
- if (x + w >= TheMap.Width) {
- w = TheMap.Width - x;
- }
-
- if (y + h >= TheMap.Height) {
- h = TheMap.Height - y;
- }
- // Dummy check...
- if ((w <= 0) || (h <= 0)) {
- return SCM_BOOL_F;
- }
- // Air is no problem...
- if (wayid == 0) {
- return SCM_BOOL_T;
- }
- // Find a unit which can move, check if it can access the hotspot.
+
+ ZoneSetClear(&sources);
+ transporter = 0;
+ transporterplace = 0;
for (i = 0; i < AiPlayer->Player->TotalNumUnits; i++) {
unit = AiPlayer->Player->Units[i];
@@ -1452,27 +1413,54 @@
continue;
}
- if (unit->Type->Building) {
- continue;
- }
-
- if ((wayid == 1) && (unit->Type->UnitType != UnitTypeLand)) {
- continue;
+ if (unit->Type->UnitType == UnitTypeNaval && unit->Type->Transporter) {
+ ZoneSetAddUnitZones(&sources, unit);
+ if ((!transporter) || (transporter->MaxOnBoard <
unit->Type->MaxOnBoard)) {
+ transporter = unit->Type;
+ }
+ transporterplace += unit->Type->MaxOnBoard;
}
+ }
+ ZoneSetClear(&transportable);
+ // Add land connected to transporter
+ ZoneSetAddConnected(&transportable,&sources);
+ // Add water as well
+ ZoneSetAddSet(&transportable,&sources);
+
- if ((wayid == 2) && (unit->Type->UnitType != UnitTypeNaval)) {
- continue;
- }
- // Ok, unit is a possible test
- if (PlaceReachable(unit, x, y, w, h, 2)) {
- return SCM_BOOL_T;
+ aiunit = AiPlayer->Force[AiScript->ownForce].Units;
+
+ while (aiunit) {
+ switch(aiunit->Unit->Type->UnitType) {
+ case UnitTypeFly:
+ break;
+ case UnitTypeNaval:
+ if (!PlaceReachable(aiunit->Unit, AiScript->HotSpot_X,
AiScript->HotSpot_Y, 1, 1,0,aiunit->Unit->Type->_AttackRange)) {
+ return SCM_BOOL_F;
+ }
+ break;
+ case UnitTypeLand:
+
+ ZoneSetClear(&sources);
+ ZoneSetAddUnitZones(&sources,aiunit->Unit);
+
+ ZoneSetClear(&targets);
+ ZoneSetAddGoalZones(&targets, aiunit->Unit, AiScript->HotSpot_X
- 4, AiScript->HotSpot_Y - 4, 9, 9,0,0);
+
+ if (!ZoneSetHasIntersect(&targets,&sources) &&
+ (!ZoneSetHasIntersect(&targets,&transportable) ||
+ !ZoneSetHasIntersect(&sources,&transportable))) {
+ return SCM_BOOL_F;
+ }
+ break;
}
- return SCM_BOOL_F;
+ aiunit = aiunit->Next;
}
- // Fall back : no unit at all ? Use the starting point...
- DebugLevel3Fn("CclAiCanReach failled to use a test unit...\n");
return SCM_BOOL_T;
+#else
+ return SCM_BOOL_F;
+#endif
}
Index: stratagus/src/ai/new_ai.c
diff -u stratagus/src/ai/new_ai.c:1.90 stratagus/src/ai/new_ai.c:1.91
--- stratagus/src/ai/new_ai.c:1.90 Sun Nov 16 01:49:25 2003
+++ stratagus/src/ai/new_ai.c Wed Nov 19 21:23:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: new_ai.c,v 1.90 2003/11/16 06:49:25 mr-russ Exp $
+// $Id: new_ai.c,v 1.91 2003/11/20 02:23:40 pludov Exp $
//@{
@@ -152,6 +152,8 @@
#include "actions.h"
#include "map.h"
+#include "pathfinder.h"
+
#if defined(DEBUG) && defined(TIMEIT)
#include "rdtsc.h"
#endif
@@ -782,7 +784,7 @@
{
CLprintf(file, "\n;;; -----------------------------------------\n");
CLprintf(file,
- ";;; MODULE: AI $Id: new_ai.c,v 1.90 2003/11/16 06:49:25 mr-russ Exp
$\n\n");
+ ";;; MODULE: AI $Id: new_ai.c,v 1.91 2003/11/20 02:23:40 pludov Exp
$\n\n");
SaveAiTypesWcName(file);
SaveAiHelper(file);
@@ -1195,7 +1197,7 @@
}
}
- DebugCheck(1);
+ //DebugCheck(1);
}
/*----------------------------------------------------------------------------
@@ -1339,15 +1341,9 @@
AiReduceMadeInBuilded(unit->Player->Ai, what);
}
-/**
-** Called if an unit can't move. Try to move unit in the way
-**
-** @param unit Pointer to unit what builds the building.
-** @param what Pointer to unit-type.
-*/
-global void AiCanNotMove(Unit * unit)
+local void AiMoveUnitInTheWay(Unit* unit)
{
- static int
dirs[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}};
+ static int
dirs[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}};
int ux0,uy0,ux1,uy1;
int bx0,by0,bx1,by1;
int x,y;
@@ -1375,8 +1371,7 @@
movablenb = 0;
- DebugLevel2Fn("AiCanNotMove : %s at %d %d\n" _C_ unittype->Ident _C_ ux0
_C_ uy0);
-
+
// Try to make some unit moves around it
for (i = 0; i < NumUnits; ++i) {
blocker = Units[i];
@@ -1467,6 +1462,256 @@
}
}
+
+#ifdef MAP_REGIONS
+/**
+** Return : 0 if nothing available
+** 1 if exists (unit may still be null if no one ready)
+**
+*/
+local int FindTransporterOnZone(int waterzone,ZoneSet * destzones,
+ int x,int y,unsigned int unitType,
+ Unit ** bestunit)
+{
+ static ZoneSet TransporterZones={0};
+ Unit ** allunits;
+ Unit * unit;
+ int i;
+ int unitdst;
+ int unitok;
+ int result;
+ int bestunitdst;
+ int unitX,unitY;
+
+ result = 0;
+ *bestunit = 0;
+ unitdst = -1;
+
+ // Travel through all units
+ allunits = AiPlayer->Player->Units;
+ for (i = 0; i < AiPlayer->Player->TotalNumUnits; i++) {
+ unit = allunits[i];
+
+ if (UnitUnusable(unit)) {
+ continue;
+ }
+ if (unit->Type->UnitType != unitType || !unit->Type->Transporter) {
+ continue;
+ }
+
+ result = 1;
+
+ if (unit->InsideCount >= unit->Type->MaxOnBoard) {
+ continue;
+ }
+
+ // check that it is in the region
+ ZoneSetClear(&TransporterZones);
+ ZoneSetAddUnitZones(&TransporterZones, unit);
+ if (!ZoneSetContains(&TransporterZones, waterzone)) {
+ continue;
+ }
+
+ unitok = UnitIdle(unit);
+ unitX = unit->X;
+ unitY = unit->Y;
+
+ // If transporter is moving, check if it is moving on our coast
+ if (!unitok &&
+ unit->OrderCount + (unit->OrderFlush?1:0) >= 2 &&
+ unit->OrderCount < MAX_ORDERS - 1 &&
+ unit->Orders[unit->OrderFlush ? 1 : 0].Action == UnitActionFollow &&
+ unit->Orders[unit->OrderCount - 1].Action == UnitActionUnload &&
+ unit->InsideCount + unit->OrderCount - (unit->OrderFlush ? 1 : 0)
<= unit->Type->MaxOnBoard) {
+
+
+ // Check that it will unload in the dest zone
+ ZoneSetClear(&TransporterZones);
+ ZoneSetAddCell(&TransporterZones,
+ unit->Orders[unit->OrderCount - 1].X,
unit->Orders[unit->OrderCount - 1].Y);
+
+ unitok = ZoneSetHasIntersect(&TransporterZones, destzones);
+ if (unitok) {
+ unitX = unit->Orders[unit->OrderFlush ? 1 : 0].Goal->X;
+ unitY = unit->Orders[unit->OrderFlush ? 1 : 0].Goal->Y;
+ }
+ }
+
+ if (!unitok) {
+ continue;
+ }
+
+ unitdst = (unitX - x) * (unitX - x) + (unitY - y) * (unitY - y);
+ if (bestunitdst != -1 && unitdst > bestunitdst) {
+ continue;
+ }
+
+ bestunitdst = unitdst;
+ *bestunit = unit;
+ }
+
+ return result;
+}
+
+local void HelpWithTransporter(Unit * unit, Unit * transporter, int
transporterzone, int destzone)
+{
+ int x,y;
+ // Order temp;
+
+ if (UnitIdle(transporter)) {
+ CommandFollow(transporter, unit, FlushCommands);
+ ZoneFindConnexion(destzone, transporterzone, unit->X, unit->Y, &x, &y);
+ CommandUnload(transporter, x, y ,NoUnitP, 0);
+ } else {
+ CommandFollow(transporter, unit, 0);
+ // We need to swap last with order 1
+ CommandMoveOrder(transporter, transporter->OrderCount - 1, 1);
+ }
+ // Fixme : save order & restore it when unloaded
+ CommandBoard(unit, transporter, FlushCommands);
+}
+#endif // MAP_REGIONS
+
+/**
+** Called if an unit can't move. Try to move unit in the way
+**
+** @param unit Pointer to unit what builds the building.
+** @param what Pointer to unit-type.
+*/
+global void AiCanNotMove(Unit * unit)
+{
+
+#ifdef MAP_REGIONS
+ AiTransportRequest* aitr;
+#endif
+ int gx,gy,gw,gh;
+ int minrange, maxrange;
+
+ DebugLevel2Fn("%s at %d %d\n" _C_ unit->Type->Ident _C_ unit->X _C_
unit->Y);
+
+ AiPlayer = unit->Player->Ai;
+
+ if (unit->Orders[0].Goal) {
+ gw=unit->Orders[0].Goal->Type->TileWidth;
+ gh=unit->Orders[0].Goal->Type->TileHeight;
+ gx=unit->Orders[0].Goal->X;
+ gy=unit->Orders[0].Goal->Y;
+ maxrange=unit->Orders[0].Range;
+ minrange=unit->Orders[0].MinRange;
+ } else {
+ // Take care of non square goals :)
+ // If goal is non square, range states a non-existant goal rather
+ // than a tile.
+ gw = unit->Orders[0].Width;
+ gh = unit->Orders[0].Height;
+ maxrange=unit->Orders[0].Range;
+ minrange=unit->Orders[0].MinRange;
+ gx=unit->Orders[0].X;
+ gy=unit->Orders[0].Y;
+ }
+
+ if (PlaceReachable(unit, gx, gy, gw, gh, minrange, maxrange) ||
unit->Type->UnitType == UnitTypeFly) {
+ // Path probably closed by unit here
+ DebugLevel2Fn("Place reacheable, move unit in the way.\n");
+ AiMoveUnitInTheWay(unit);
+ return;
+ }
+
+#ifdef MAP_REGIONS
+ aitr = AiPlayer->TransportRequests;
+ while (aitr) {
+ if (aitr->Unit == unit) {
+ return;
+ }
+ aitr = aitr->Next;
+ }
+
+ aitr = malloc(sizeof(AiTransportRequest));
+ aitr->Next = AiPlayer->TransportRequests;
+ aitr->Unit = unit;
+ aitr->Order = unit->Orders[0];
+ RefsIncrease(unit);
+ if (aitr->Order.Goal) {
+ RefsIncrease(aitr->Order.Goal);
+ }
+ AiPlayer->TransportRequests = aitr;
+ return;
+#endif // MAP_REGIONS
+}
+
+#ifdef MAP_REGIONS
+local void HandleTransportRequests(AiTransportRequest * aitr)
+{
+ static ZoneSet UnitZones={0};
+ static ZoneSet DestZones={0};
+
+ Unit * transporter;
+ int zonepath[MaxZoneNumber];
+ int zonepathlen;
+ int gx,gy,gw,gh,maxrange,minrange;
+
+ if (aitr->Unit->Removed) {
+ return;
+ }
+
+ if (aitr->Order.Goal) {
+ // Check for dead goal here (?)
+ if (aitr->Order.Goal->Removed) {
+ return;
+ }
+
+ gw=aitr->Unit->Orders[0].Goal->Type->TileWidth;
+ gh=aitr->Unit->Orders[0].Goal->Type->TileHeight;
+ gx=aitr->Unit->Orders[0].Goal->X;
+ gy=aitr->Unit->Orders[0].Goal->Y;
+ maxrange=aitr->Unit->Orders[0].Range;
+ minrange=aitr->Unit->Orders[0].MinRange;
+ } else {
+ // Take care of non square goals :)
+ // If goal is non square, range states a non-existant goal rather
+ // than a tile.
+ gw = aitr->Unit->Orders[0].Width;
+ gh = aitr->Unit->Orders[0].Height;
+ maxrange=aitr->Unit->Orders[0].Range;
+ minrange=aitr->Unit->Orders[0].MinRange;
+ gx=aitr->Unit->Orders[0].X;
+ gy=aitr->Unit->Orders[0].Y;
+ }
+
+ // Check if we have an idle air transporter.
+
+ // Check if we have an idle water tranporter
+ ZoneSetClear(&UnitZones);
+ ZoneSetAddUnitZones(&UnitZones, aitr->Unit);
+
+ ZoneSetClear(&DestZones);
+ ZoneSetAddGoalZones(&DestZones, aitr->Unit, gx, gy, gw, gh, minrange,
maxrange);
+
+ if (ZoneSetHasIntersect(&UnitZones, &DestZones)) {
+ // Can go, nothing to do.
+ return;
+ }
+
+ if (!ZoneSetFindPath(&UnitZones, &DestZones, zonepath, &zonepathlen)) {
+ DebugLevel2Fn("no way over there.\n");
+ return;
+ }
+
+ DebugCheck(zonepathlen < 3);
+
+ if (FindTransporterOnZone(zonepath[1], &DestZones,
aitr->Unit->X,aitr->Unit->Y,UnitTypeNaval,&transporter)) {
+ if (transporter) {
+ HelpWithTransporter(aitr->Unit, transporter, zonepath[1],
zonepath[2]);
+ CommandAnyOrder(aitr->Unit, &aitr->Order, 0);
+ } else {
+ DebugLevel2Fn("All transporters are busy, waits.\n");
+ }
+ } else {
+ // FIXME : Find or build transporter builder in the zone
+ }
+}
+#endif // MAP_REGIONS
+
/**
** Called if the AI needs more farms.
**
@@ -1546,6 +1791,27 @@
*/
global void AiEachCycle(Player * player __attribute__ ((unused)))
{
+ AiTransportRequest * aitr, * next;
+
+ AiPlayer = player->Ai;
+
+ aitr = AiPlayer->TransportRequests;
+ while (aitr) {
+ next = aitr->Next;
+
+#ifdef MAP_REGIONS
+ HandleTransportRequests(aitr);
+#endif // MAP_REGIONS
+
+ RefsDecrease(aitr->Unit);
+ if (aitr->Order.Goal) {
+ RefsDecrease(aitr->Order.Goal);
+ }
+ free(aitr);
+
+ aitr = next;
+ }
+ AiPlayer->TransportRequests = 0;
}
/**
Index: stratagus/src/include/actions.h
diff -u stratagus/src/include/actions.h:1.59
stratagus/src/include/actions.h:1.60
--- stratagus/src/include/actions.h:1.59 Sun Nov 9 17:13:57 2003
+++ stratagus/src/include/actions.h Wed Nov 19 21:23:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: actions.h,v 1.59 2003/11/09 22:13:57 n0body Exp $
+// $Id: actions.h,v 1.60 2003/11/20 02:23:40 pludov Exp $
#ifndef __ACTIONS_H__
#define __ACTIONS_H__
@@ -127,7 +127,10 @@
extern void CommandDiplomacy(int player,int state,int opponent);
/// Prepare shared vision command
extern void CommandSharedVision(int player,int state,int opponent);
-
+ /// Send any command
+extern void CommandAnyOrder(Unit* unit,Order * order,int flush);
+ /// Move an order in command queue
+extern void CommandMoveOrder(Unit* unit,int src,int dst);
/*----------------------------------------------------------------------------
-- Actions: in action_<name>.c
----------------------------------------------------------------------------*/
Index: stratagus/src/include/unittype.h
diff -u stratagus/src/include/unittype.h:1.130
stratagus/src/include/unittype.h:1.131
--- stratagus/src/include/unittype.h:1.130 Mon Nov 17 14:14:33 2003
+++ stratagus/src/include/unittype.h Wed Nov 19 21:23:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unittype.h,v 1.130 2003/11/17 19:14:33 nehalmistry Exp $
+// $Id: unittype.h,v 1.131 2003/11/20 02:23:40 pludov Exp $
#ifndef __UNITTYPE_H__
#define __UNITTYPE_H__
@@ -676,7 +676,7 @@
int _Costs[MaxCosts]; /// How many resources needed
int RepairHP; /// Amount of HP per repair
- int RepairCosts[MaxCosts]; /// How much it costs to repair
+ int RepairCosts[MaxCosts]; /// How much it costs to repair
int TileWidth; /// Tile size on map width
int TileHeight; /// Tile size on map height
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus ./Rules.make.in data/ccl/ai.ccl doc/C...,
ludovic pollet <=