[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus src/ai/new_ai.c src/ai/ai_rules.c src...
From: |
ludovic pollet |
Subject: |
[Stratagus-CVS] stratagus src/ai/new_ai.c src/ai/ai_rules.c src... |
Date: |
Sat, 01 Nov 2003 06:30:44 -0500 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: ludovic pollet <address@hidden> 03/11/01 06:30:44
Modified files:
src/ai : new_ai.c ai_rules.c ai_plan.c ai_force.c
data/ccl : ai.ccl
Log message:
code cleanup
Patches:
Index: stratagus/data/ccl/ai.ccl
diff -u stratagus/data/ccl/ai.ccl:1.58 stratagus/data/ccl/ai.ccl:1.59
--- stratagus/data/ccl/ai.ccl:1.58 Fri Oct 31 04:14:41 2003
+++ stratagus/data/ccl/ai.ccl Sat Nov 1 06:30:43 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.58 2003/10/31 09:14:41 pludov Exp $
+;; $Id: ai.ccl,v 1.59 2003/11/01 11:30:43 pludov Exp $
;(define (ai:sleep) () #t)
@@ -895,7 +895,7 @@
;; (ai:attack-with-force 1)
(ai:sleep 500)
- (ai:force 0 'unit-grunt 1 'unit-axethrower 0 'unit-ranger 2
+ (ai:force 0 'unit-grunt 1 'unit-axethrower 0
'unit-ogre-mage 6 'unit-catapult 1 'unit-death-knight 5)
;; (ai:force 1 'unit-grunt 1 'unit-axethrower 0 'unit-ranger 2
;; 'unit-ogre-mage 2 'unit-catapult 1 'unit-death-knight 1)
@@ -1920,7 +1920,7 @@
(ai:research 'upgrade-berserker)
(ai:research 'upgrade-berserker-scouting)
(ai:research 'upgrade-raise-dead)
- (ai:force 0 'unit-grunt 1 'unit-axethrower 0 'unit-ranger 4
'unit-ogre-mage 16 'unit-catapult 3 'unit-death-knight 6 'unit-dragon 4)
+ (ai:force 0 'unit-grunt 1 'unit-axethrower 4 'unit-ogre-mage 16
'unit-catapult 3 'unit-death-knight 6 'unit-dragon 4)
(ai:sleep 500)
(ai:need 'unit-great-hall)
Index: stratagus/src/ai/ai_force.c
diff -u stratagus/src/ai/ai_force.c:1.39 stratagus/src/ai/ai_force.c:1.40
--- stratagus/src/ai/ai_force.c:1.39 Fri Oct 31 06:39:24 2003
+++ stratagus/src/ai/ai_force.c Sat Nov 1 06:30:43 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_force.c,v 1.39 2003/10/31 11:39:24 pludov Exp $
+// $Id: ai_force.c,v 1.40 2003/11/01 11:30:43 pludov Exp $
//@{
@@ -146,7 +146,7 @@
// 2 - Remove unavailable unittypes
for (i = 0; i < usableTypesCount; ) {
- if (! CheckDependByIdent(AiPlayer->Player,
UnitTypes[usableTypes[i]]->Ident)) {
+ if (!CheckDependByIdent(AiPlayer->Player,
UnitTypes[usableTypes[i]]->Ident)) {
// Not available, remove it
usableTypes[i] = usableTypes[usableTypesCount - 1];
usableTypesCount--;
@@ -251,6 +251,64 @@
AiUnit *aiunit;
int type;
int counter[UnitTypeMax + 1];
+ int missing;
+
+ //
+ // Count units in dest force.
+ //
+ AiForceCountUnits(dst, counter);
+
+ //
+ // Check the dest force requirements.
+ //
+ if ((missing = AiForceSubstractWant(dst, counter)) == 0) {
+ // Nothing missing => mark completed & abort.
+ AiPlayer->Force[dst].Completed = 1;
+ return;
+ }
+
+ // Iterate the source force, moving needed units into dest...
+ prev = &AiPlayer->Force[src].Units;
+ while (*prev) {
+ aiunit = (*prev);
+ type = UnitTypeEquivs[aiunit->Unit->Type->Type];
+ if (counter[type] < 0) {
+ // move in dest force...
+ *prev = aiunit->Next;
+
+ aiunit->Next = AiPlayer->Force[dst].Units;
+ AiPlayer->Force[dst].Units = aiunit;
+
+ counter[type]++;
+ missing--;
+
+ if (!missing) {
+ AiPlayer->Force[dst].Completed = 1;
+ return;
+ }
+ } else {
+ // Just iterate
+ prev = &aiunit->Next;
+ }
+ }
+}
+
+/**
+** Complete dst force with overflow units in src force.
+**
+** FIXME : should check that unit can reach dst force's hotspot.
+**
+** @param src the force from which units are taken
+** @param dst the force into which units go
+*/
+global void AiForceTransfertOverflow(int src, int dst)
+{
+ AiUnit **prev;
+ AiUnit *aiunit;
+ int type;
+ int counter[UnitTypeMax + 1];
+ int overflow[UnitTypeMax + 1];
+ int missing;
//
// Count units in dest force.
@@ -260,17 +318,24 @@
//
// Check the dest force requirements.
//
- if (AiForceSubstractWant(dst, counter) == 0) {
+ if ((missing = AiForceSubstractWant(dst, counter)) == 0) {
// Nothing missing => abort.
+ AiPlayer->Force[dst].Completed = 1;
return;
}
+ //
+ // Find overflow units in src force
+ //
+ AiForceCountUnits(src, overflow);
+ AiForceSubstractWant(src, overflow);
+
// Iterate the source force, moving needed units into dest...
prev = &AiPlayer->Force[src].Units;
while (*prev) {
aiunit = (*prev);
type = UnitTypeEquivs[aiunit->Unit->Type->Type];
- if (counter[type] < 0) {
+ if (counter[type] < 0 && overflow[type] > 0) {
// move in dest force...
*prev = aiunit->Next;
@@ -278,6 +343,12 @@
AiPlayer->Force[dst].Units = aiunit;
counter[type]++;
+ overflow[type]--;
+ missing--;
+ if (!missing) {
+ AiPlayer->Force[dst].Completed = 1;
+ return;
+ }
} else {
// Just iterate
prev = &aiunit->Next;
@@ -494,24 +565,39 @@
*/
global void AiForceComplete(int force)
{
- int j;
+ int j, overflowonly;;
for (j = 0; j < AI_MAX_FORCES; ++j) {
// Don't complete with self ...
if (j == force) {
continue;
}
+
// Complete only with "reusable" forces.
if (!AiPlayer->Force[j].UnitsReusable) {
continue;
}
+
// Honor "populate from attack"
if ((AiPlayer->Force[force].PopulateMode == AiForcePopulateFromAttack)
&&
(!AiPlayer->Force[j].Role == AiForceRoleAttack)) {
- continue;
+
+ // Use overflow from force 0...
+ if (j == 0) {
+ overflowonly = 1;
+ } else {
+ continue;
+ }
+ } else {
+ overflowonly = 0;
}
+
// Complete the force automatically...
- AiForceTransfert(j, force);
+ if (!overflowonly) {
+ AiForceTransfert(j, force);
+ } else {
+ AiForceTransfertOverflow(j, force);
+ }
if (AiPlayer->Force[force].Completed) {
break;
Index: stratagus/src/ai/ai_plan.c
diff -u stratagus/src/ai/ai_plan.c:1.20 stratagus/src/ai/ai_plan.c:1.21
--- stratagus/src/ai/ai_plan.c:1.20 Wed Oct 29 18:11:54 2003
+++ stratagus/src/ai/ai_plan.c Sat Nov 1 06:30:43 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_plan.c,v 1.20 2003/10/29 23:11:54 pludov Exp $
+// $Id: ai_plan.c,v 1.21 2003/11/01 11:30:43 pludov Exp $
//@{
@@ -631,7 +631,7 @@
}
// Nothing => abort
- if (! requestcount) {
+ if (!requestcount) {
return;
}
@@ -666,9 +666,9 @@
ray = 3 * ray / 2;
trycount ++;
- } while (trycount < 8 && ! targetok);
+ } while (trycount < 8 && !targetok);
- if (! targetok) {
+ if (!targetok) {
continue;
}
Index: stratagus/src/ai/ai_rules.c
diff -u stratagus/src/ai/ai_rules.c:1.4 stratagus/src/ai/ai_rules.c:1.5
--- stratagus/src/ai/ai_rules.c:1.4 Fri Oct 31 04:14:46 2003
+++ stratagus/src/ai/ai_rules.c Sat Nov 1 06:30:43 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ai_rules.c,v 1.4 2003/10/31 09:14:46 pludov Exp $
+// $Id: ai_rules.c,v 1.5 2003/11/01 11:30:43 pludov Exp $
//@{
@@ -566,6 +566,7 @@
local int AiEvaluateScript(SCM script)
{
SCM get_need_lambda, rslt, willeval;
+
get_need_lambda = gh_cadr(gh_car(script));
willeval =
cons(get_need_lambda,
@@ -864,7 +865,7 @@
if (leftCost <= ((7 * totalCost) / 10)) {
DebugLevel3Fn("launch defense script\n");
AiStartScript(bestScriptAction, "defend");
- }else{
+ } else {
DebugLevel3Fn("not ready for defense\n");
AiStartScript(bestScriptAction, "defend");
}
@@ -951,7 +952,7 @@
AiActionEvaluation *actionEvaluation = AiPlayer->FirstEvaluation;
AiPlayer->FirstEvaluation = actionEvaluation->Next;
- if (! AiPlayer->FirstEvaluation) {
+ if (!AiPlayer->FirstEvaluation) {
AiPlayer->LastEvaluation = 0;
}
@@ -1059,7 +1060,7 @@
actionEvaluation = actionEvaluation->Next;
}
- if ((! bestActionEvaluation) && bestValue != -1 ){
+ if ((!bestActionEvaluation) && bestValue != -1 ){
// If nothing available, try the best compromis ( value - hotspot )
actionEvaluation = AiPlayer->FirstEvaluation;
bestDelta=0;
Index: stratagus/src/ai/new_ai.c
diff -u stratagus/src/ai/new_ai.c:1.83 stratagus/src/ai/new_ai.c:1.84
--- stratagus/src/ai/new_ai.c:1.83 Fri Oct 31 04:48:20 2003
+++ stratagus/src/ai/new_ai.c Sat Nov 1 06:30:42 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: new_ai.c,v 1.83 2003/10/31 09:48:20 pludov Exp $
+// $Id: new_ai.c,v 1.84 2003/11/01 11:30:42 pludov Exp $
//@{
@@ -764,7 +764,7 @@
{
CLprintf(file, "\n;;; -----------------------------------------\n");
CLprintf(file,
- ";;; MODULE: AI $Id: new_ai.c,v 1.83 2003/10/31 09:48:20 pludov Exp
$\n\n");
+ ";;; MODULE: AI $Id: new_ai.c,v 1.84 2003/11/01 11:30:42 pludov Exp
$\n\n");
SaveAiTypesWcName(file);
SaveAiHelper(file);
@@ -1131,6 +1131,8 @@
local void AiReduceMadeInBuilded(const PlayerAi * pai, const UnitType * type)
{
int i;
+ int equivs[UnitTypeMax + 1];
+ int equivnb;
if (AiReduceMadeInBuilded2(pai, type)) {
return;
@@ -1138,12 +1140,11 @@
//
// This could happen if an upgrade is ready, look for equivalent units.
//
- if (type->Type < AiHelpers.EquivCount && AiHelpers.Equiv[type->Type]) {
- DebugLevel2Fn("Equivalence for %s\n" _C_ type->Ident);
- for (i = 0; i < AiHelpers.Equiv[type->Type]->Count; ++i) {
- if (AiReduceMadeInBuilded2(pai,
AiHelpers.Equiv[type->Type]->Table[i])) {
- return;
- }
+ equivnb = AiFindUnitTypeEquiv(type, equivs);
+
+ for (i = 0; i < AiHelpers.Equiv[type->Type]->Count; ++i) {
+ if (AiReduceMadeInBuilded2(pai, UnitTypes[equivs[i]])) {
+ return;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus src/ai/new_ai.c src/ai/ai_rules.c src...,
ludovic pollet <=