Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Robosturm committed Oct 20, 2023
1 parent 8a13b53 commit 959d391
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions ai/coreai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,7 @@ void CoreAI::finishTurn()
AI_CONSOLE_PRINT("CoreAI::finishTurn(()", GameConsole::eDEBUG);
m_usedTransportSystem = false;
m_usedPredefinedAi = false;
m_productionSystem.setCurrentTurnProducedUnitsCounter(0);
spGameAction pAction = MemoryManagement::create<GameAction>(ACTION_NEXT_PLAYER, m_pMap);
CO* pCO0 = m_pPlayer->getCO(0);
CO* pCO1 = m_pPlayer->getCO(1);
Expand Down
16 changes: 16 additions & 0 deletions ai/productionSystem/simpleproductionsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ void SimpleProductionSystem::updateActiveProductionSystem(QmlVectorBuilding* pBu
}
}

qint32 SimpleProductionSystem::getCurrentTurnProducedUnitsCounter() const
{
return m_currentTurnProducedUnitsCounter;
}

void SimpleProductionSystem::setCurrentTurnProducedUnitsCounter(qint32 newCurrentTurnProducedUnitsCounter)
{
m_currentTurnProducedUnitsCounter = newCurrentTurnProducedUnitsCounter;
}

void SimpleProductionSystem::updateIslandSizeForBuildings(QmlVectorBuilding* pBuildings)
{
m_averageMoverange.clear();
Expand Down Expand Up @@ -634,6 +644,7 @@ bool SimpleProductionSystem::buildUnit(qint32 x, qint32 y, QString unitId)
if (pAction->canBePerformed())
{
CONSOLE_PRINT("Building unit " + unitId + " at x=" + QString::number(x) + " y=" + QString::number(y), GameConsole::eDEBUG);
++m_currentTurnProducedUnitsCounter;
emit m_owner->sigPerformAction(pAction);
return true;
}
Expand Down Expand Up @@ -686,6 +697,7 @@ void SimpleProductionSystem::serializeObject(QDataStream& pStream) const
pStream << item.count;
}
m_Variables.serializeObject(pStream);
pStream << m_currentTurnProducedUnitsCounter;
}

void SimpleProductionSystem::deserializeObject(QDataStream& pStream)
Expand Down Expand Up @@ -734,6 +746,10 @@ void SimpleProductionSystem::deserializeObject(QDataStream& pStream)
m_initialProduction.push_back(item);
}
m_Variables.deserializeObject(pStream);
if (version > 0)
{
pStream >> m_currentTurnProducedUnitsCounter;
}
}

Unit* SimpleProductionSystem::getDummyUnit(const QString & unitId)
Expand Down
6 changes: 5 additions & 1 deletion ai/productionSystem/simpleproductionsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SimpleProductionSystem final : public QObject, public FileSerializable, pu
*/
virtual qint32 getVersion() const override
{
return 0;
return 1;
}
void initialize();
bool buildUnit(QmlVectorBuilding* pBuildings, QmlVectorUnit* pUnits, QmlVectorUnit * pEnemyUnits, QmlVectorBuilding * pEnemyBuildings, bool & executed);
Expand Down Expand Up @@ -105,6 +105,9 @@ class SimpleProductionSystem final : public QObject, public FileSerializable, pu
Q_INVOKABLE Unit* getDummyUnit(const QString & unitId);
Q_INVOKABLE qint32 getProductionFromList(const QStringList & unitIds, QmlVectorUnit* pUnits, QmlVectorBuilding* pBuildings, qint32 minBuildMode, qint32 maxBuildMode, const QVector<bool> & enableList = QVector<bool>());
Q_INVOKABLE void updateIslandSizeForBuildings(QmlVectorBuilding* pBuildings);
Q_INVOKABLE qint32 getCurrentTurnProducedUnitsCounter() const;
void setCurrentTurnProducedUnitsCounter(qint32 newCurrentTurnProducedUnitsCounter);

private:
bool buildUnit(QmlVectorBuilding* pBuildings, QString unitId, qreal minAverageIslandSize);
bool buildUnitCloseTo(QmlVectorBuilding* pBuildings, QString unitId, qreal minAverageIslandSize, const spQmlVectorUnit & pUnits);
Expand All @@ -123,6 +126,7 @@ class SimpleProductionSystem final : public QObject, public FileSerializable, pu
std::map<Building*, AverageBuildData> m_averageMoverange;
ScriptVariables m_Variables;
spUnit m_dummy;
qint32 m_currentTurnProducedUnitsCounter{0};
};

Q_DECLARE_INTERFACE(SimpleProductionSystem, "SimpleProductionSystem");
14 changes: 13 additions & 1 deletion resources/aidata/normal/__coreai.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ var COREAI =
subCounterUnitBalance : 2.5,
ownCounterUnitMinHp : 7,
enemyCounterUnitMinHp : 5,
// the following units are only build if nothing else is possible
specialUnits = ["PIPERUNNER", "HOELLIUM"],
specialProductionCount = 4,

getGroundModifier : function(system)
{
Expand Down Expand Up @@ -574,7 +577,16 @@ var COREAI =
break;
}
}
return system.buildNextUnit(buildings, units, minMode, maxMode, COREAI.minAverageIslandSize, minBaseCost, maxBaseCost);
var build = system.buildNextUnit(buildings, units, minMode, maxMode, COREAI.minAverageIslandSize, minBaseCost, maxBaseCost);
if (!build && system.getCurrentTurnProducedUnitsCounter() === 0)
{
for (var i = 0; i < COREAI.specialProductionCount; ++i)
{
system.addForcedProduction(COREAI.specialUnits);
}
build = system.buildNextUnit(buildings, units, minMode, maxMode, COREAI.minAverageIslandSize, minBaseCost, maxBaseCost);
}
return build;
},

getFactoryMenuItem : function(ai, action, ids, costs, enabled, units, buildings, owner, map)
Expand Down

0 comments on commit 959d391

Please sign in to comment.