- Joined
- Jan 24, 2011
- Messages
- 4,793
I'm loving Lua and its capabilities!
It's awesome seeing you use it!
I'm loving Lua and its capabilities!
Yeah! And thanks to Lua I'm even saving more unit slots! I used to have a unit to represent the town of Guernika and trigger the bombing event "on unit killed"...now I can simply use Lua code to check the defender location and throw an event when the city of Guernika is bombed by German planes...It's awesome seeing you use it!
I have finished implementing the mentioned combat mechanics (units, comba events, and commander bonuses), it's all working like a charm in all my tests. I found using the traits module for adding combat bonuses/penalties to unit types very easy and readable so I'm pasting some sample code in case somebody wants to give it a try:So far I'm implementing a quite complex and nice system to customize the combat based on the below premises:
- Specific units are more suitable than others against enemy units (as shown above with my usage of the LST Traits module). Nothing new here.
- There's a chance of specific Combat Events to trigger during combat: counterattack, encirclement, assault, etc which can modify the attacker/defender stats and even cause specific behaviours (troops fleeing or surrendering!). The better trained the units are (by tech), the more chance of these events triggering on their favour. This is innovative in a way that you need to train your troops (research specific techs) to improve your performance in combat and increase the chances to kick off one or more of these events.
- Commander (Leader) units have specific traits that substantially alter the stats of the units under their command. If combat occurs on an adyacent tile, the fighting troops inherit the effects of these traits. For instance, a "fortress buster" commander will allow troops fighting "under their command" to be stronger when attacking units entrenched in fortifications. An "africanist" will be especially effective when commanding African colonial troops (legión, regulares). A "prince of terror" commander will have a chance to make the enemy withdraw from combat and flee from their positions even before fight starts, other traits will give bonuses when fighting on specific terrain, etc. Many cool combinations that I have implemented, and many more I can include!
traits.assign(object.uGuardiaCivil,"infantry","police","ground_air_vulnerable")
traits.assign(object.uCarroVeloceCV33,"armoured","ground_air_vulnerable")
local traitCombatBonusesTable = {
-- LAND COMBAT
-- Infantry particularly vulnerable attacking MG and armoured units.
["infantry"] = {tcbtDefenderTable={"mg","armoured"},tcbtAttackerBonusTable={0.8,1},tcbtDefenderBonusTable={1.5,1.75}}
}
-- This function will return the specific bonuses if combat occurs between specific unit types as defined on traitCombatBonusesTable
local function getUnitTypeCombatModifiers(attacker, defender)
local aCustomMult,dCustomMult = 1, 1
-- Loop through the traitCombatBonusesTable table
for attackerTrait,bonuses in pairs(traitCombatBonusesTable) do
if traits.hasTrait(attacker.type,attackerTrait) then
-- Loop through all defined defender traits
for i,defenderTrait in pairs(bonuses.tcbtDefenderTable) do
if traits.hasTrait(defender.type,defenderTrait) then
-- Combination found, retrieve modifiers
aCustomMult,dCustomMult = aCustomMult*bonuses.tcbtAttackerBonusTable[i],dCustomMult*bonuses.tcbtDefenderBonusTable[i]
-- civ.ui.text("getUnitTypeCombatModifiers added for attacker trait: "..attackerTrait.." and defenderTrait: "..defenderTrait)
end
end
end
end
return aCustomMult,dCustomMult
end
-- Apply specific unit type combat modifier (traits)
local aUnitAtt, aUnitDef = getUnitTypeCombatModifiers(attacker, defender)
You could rename it "bombard city infrastructures" ?) If I choose the second option, there is a chance that a city improvement gets destroyed by the air raid. In this example the air raid was successful:
You could rename it "bombard city infrastructures" ?
And maybe specialize these in 3 options like "city defenses", "city industries" and "city civil infrastructures" ?
Whatever, it already looks great !
Thanks! Which advantages do you see?Very nice play on the strategic bombing mechanism! It certainly has some advantages over the one I've been using. Can you also tie it into changing some terrain to rubble? Not sure if your scenario has a terrain slot for that.
Thanks! Which advantages do you see?
That's the main issue I see to justify an air map : a land unit wall shall not stop planesthough that might be a little trickier in situations where they encounter a unit in the field.
-It saves unit slots
for target in strat.iterateTargets(attackedCityObject) do
strat.verifyTarget(target)
end
"My" system is not complicated at all as I don't want to link any improvements with terrains or special units. The LST strategicTargets module is very useful for a particular objective, but I developed something simpler to meet my own needs, which were just about diversifying the standard civ2 combat and basically reproduce the air raids in Spain 1936-1939, which most of the time were to just target enemy positions (city defenders - standard civ2 combat), but also some terror bombing (especially in cities such as Madrid and Barcelona) and some "more or less successful" strategic raids against specific industrial objectives. That's why I allow the human player to take a choice of possible actions, and the AI have different random actions, with most of the time performing standard civ2 combat.So, in @Pablostuka 's system, the following extra code would be needed to make the terrain change happen immediately:
Code:for target in strat.iterateTargets(attackedCityObject) do strat.verifyTarget(target) end
I think you've run into one of the few major gaps in the TOTPP functionality, that we can't control happiness the same way we can control shield/trade/food production. I can think of a couple ideas.So in summary, I want to see how can I control the number of unhappy citizens with Lua. So far I know the LST generalLibrary allows me to set civil disorder (gen.setCivilDisorder(city)) and that I can play around with city.specialists and city.workers, but unfortunately city.numUnhappy cannot be set, it's a "read only" value. So I need to do tests and think about how can I mess around with that.
You must be right Prof !!2. In the onCalculateCityYield event, modify cosmic.sizeUnhappiness so that you get the desired city happiness. I don't think anyone has done anything like this yet.
sizeUnhappiness (get/set - ephemeral)
cosmic.sizeUnhappiness -> integer
Returns the city size at which the first unhappy citizen appears at Chieftain difficulty.
onCalculateCityYield (since 0.16)
civ.scen.onCalculateCityYield(function (city, food, shields, trade) -> (foodChange, shieldChangeBeforeWaste, shieldChangeAfterWaste, tradeChangeBeforeCorruption, tradeChangeAfterCorruption)) -> void
Registers a function to be called every time a city calculates its total resource yield. Input is the city, and the food, shields and trade of its tiles. Returns a 5-tuple of modifiers, food change, shield change before waste, shield change after waste, trade change before corruption, trade change after corruption. These modifiers are applied at the following points in the calculation:
- Calculate yield from all worked tiles
- Run onCalculateCityYield
- Add foodChange, shieldChangeBeforeWaste and tradeChangeBeforeCorruption
- Add changes from food trade routes
- Add shields from improvements
- Calculate and subtract waste
- Calculate corruption and add changes from commodity trade routes
- Calculate corruption again (now using the value after trade routes) and subtract.
- Add shieldChangeAfterWaste and tradeChangeAfterCorruption
- Calculate Tax/Lux/Sci
That's definitly something to developp ! Miam miam !Forgot to say that the chances of these combat events to trigger can be increased by researching the appropriate technologies on the "military training" branch of the tech tree The more doctrines are researched, the better the troops will generally perform as they will have increased chances of triggering combat events in their favour.
Back in the MGE days this was completely unthinkable!