TheAssemblyArmada / Vanilla-Conquer

Vanilla Conquer provides clean, cross-platform builds of the C&C Remastered Collection and the standalone legacy games.
Other
330 stars 51 forks source link

Various AI fixes / improvements #227

Open TobiasKarnat opened 3 years ago

TobiasKarnat commented 3 years ago

Only let AI build buildings, infantry and units the tech tree allows

diff -urN a/redalert/base.cpp b/redalert/base.cpp
--- a/redalert/base.cpp 2020-09-24 17:38:00.856284099 +0200
+++ b/redalert/base.cpp 2020-09-24 17:38:21.275670503 +0200
@@ -386,7 +386,7 @@
         ** For STRUCT_NONE, return the first hole found
         */
         if (type == STRUCT_NONE) {
-            if (!Is_Built(i)) {
+            if (BuildingTypeClass::As_Reference(Nodes[i].Type).Level != -1 && !Is_Built(i)) {
                 return (&Nodes[i]);
             }

diff -urN a/tiberiandawn/base.cpp b/tiberiandawn/base.cpp
--- a/tiberiandawn/base.cpp 2020-09-24 17:38:00.816283342 +0200
+++ b/tiberiandawn/base.cpp 2020-09-24 17:38:21.276670521 +0200
@@ -481,7 +481,7 @@
         ** For STRUCT_NONE, return the first hole found
         */
         if (type == STRUCT_NONE) {
-            if (!Is_Built(i)) {
+            if (BuildingTypeClass::As_Reference(Nodes[i].Type).IsBuildable && !Is_Built(i)) {
                 return (&Nodes[i]);
             }

diff -urN a/tiberiandawn/house.cpp b/tiberiandawn/house.cpp
--- a/tiberiandawn/house.cpp    2020-09-24 17:38:00.840283796 +0200
+++ b/tiberiandawn/house.cpp    2020-09-24 17:38:21.281670616 +0200
@@ -3724,8 +3724,7 @@
             int bestcount = 0;
             UnitType bestlist[UNIT_COUNT];
             for (UnitType utype = UNIT_FIRST; utype < UNIT_COUNT; utype++) {
-                if (counter[utype] > 0 && Can_Build(utype, Class->House)
-                    && UnitTypeClass::As_Reference(utype).Cost_Of() <= Available_Money()) {
+                if (counter[utype] > 0 && UnitTypeClass::As_Reference(utype).Who_Can_Build_Me(false, false, Class->House) && UnitTypeClass::As_Reference(utype).Cost_Of() <= Available_Money()) {
                     if (bestval == -1 || bestval < counter[utype]) {
                         bestval = counter[utype];
                         bestcount = 0;
@@ -3826,8 +3825,7 @@
             int bestcount = 0;
             InfantryType bestlist[INFANTRY_COUNT];
             for (InfantryType utype = INFANTRY_FIRST; utype < INFANTRY_COUNT; utype++) {
-                if (counter[utype] > 0 && Can_Build(utype, Class->House)
-                    && InfantryTypeClass::As_Reference(utype).Cost_Of() <= Available_Money()) {
+                if (counter[utype] > 0 && InfantryTypeClass::As_Reference(utype).Who_Can_Build_Me(false, false, Class->House) && InfantryTypeClass::As_Reference(utype).Cost_Of() <= Available_Money()) {
                     if (bestval == -1 || bestval < counter[utype]) {
                         bestval = counter[utype];
                         bestcount = 0;

Give the AI the same speed bonus for multiple factories as the human player [TD]

diff -urN a/tiberiandawn/factory.cpp b/tiberiandawn/factory.cpp
--- a/tiberiandawn/factory.cpp  2020-09-24 17:38:00.823283475 +0200
+++ b/tiberiandawn/factory.cpp  2020-09-24 17:38:21.276670521 +0200
@@ -228,11 +228,8 @@

         /*
         ** Determine the acceleration factor for factory production.
-        ** This applies only to human players. The computer builds
-        ** units on a building by building basis -- quantity of building
-        ** factory types doesn't affect individual factories.
         */
-        if (Object && House->IsHuman) {
+        if (Object) {
             switch (Object->What_Am_I()) {
             case RTTI_AIRCRAFT:
                 stages = House->AircraftFactories;

Fix spelling error to allow discovered enemy objects to go into hunt mode

diff -urN a/redalert/techno.cpp b/redalert/techno.cpp
--- a/redalert/techno.cpp   2020-10-15 18:57:03.525696597 +0200
+++ b/redalert/techno.cpp   2020-10-15 18:57:38.768162149 +0200
@@ -774,7 +774,7 @@
         ** An enemy object that is discovered will go into hunt mode if
         ** its current mission is to ambush.
         */
-        if (!house->IsHuman && Mission == MISSION_AMBUSH) {
+        if (!House->IsHuman && Mission == MISSION_AMBUSH) {
             Assign_Mission(MISSION_HUNT);
         }

diff -urN a/tiberiandawn/techno.cpp b/tiberiandawn/techno.cpp
--- a/tiberiandawn/techno.cpp   2020-10-15 18:57:03.530696663 +0200
+++ b/tiberiandawn/techno.cpp   2020-10-15 18:58:07.586547972 +0200
@@ -549,7 +549,7 @@
         ** An enemy object that is discovered will go into hunt mode if
         ** its current mission is to ambush.
         */
-        if (!house->IsHuman && Mission == MISSION_AMBUSH) {
+        if (!House->IsHuman && Mission == MISSION_AMBUSH) {
             Assign_Mission(MISSION_HUNT);
         }
mvdhout1992 commented 3 years ago

The "Only let AI build buildings, infantry and units the tech tree allows" will break custom missions and maybe some official maps. Some Aftermath/Counterstrike missions have the AI built buildings via [Base] that they can't normally build.

TobiasKarnat commented 3 years ago

Which ones? I played through all Aftermath/Counterstrike missions actually again without noticing a bug.

This change is primarily for TD, it is just annoying that the AI can just rebuild the construction yard.

mvdhout1992 commented 3 years ago

Try the Gargnev Revolution mission, on the bottom left there are mixed arms yellow buildings. Brothers in Arms too. Note that you need to check them rebuilding the buildings.

hifi commented 3 years ago

If these changes make skirmish more enjoyable we could include these behind a rules flag in the skirmish window that is enabled by default.

We must not change how the original campaign plays.

TobiasKarnat commented 3 years ago

None of the buildings get rebuild in Gargnev Revolution even without this patch in the original version (maybe a bug itself?).

I think making it an option even for original campaign would be good.

Nyerguds commented 2 years ago

In C&C1 this is specifically intended. Look at the Covert Ops mission "Blackout" for a very specific example of a second construction yard only scripted to get built later in the mission.