How easily can you...

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
2,984
Location
Operation Padlock ground zero
1)...as a unit ability, give it an extra defense boost when near a friendly city? (Sort of like Defender of the Faith, except it doesn't require religion, and is restricted to defense)

2)...also as a unit ability, give it an extra combat bonus against units from an enemy civilization that doesn't have this particular unit's prereq tech?

3)...as a UA, during wartime, enemy units adjacent to your civ's borders take damage at the end of their turn?

I assume most of these would require lua but these abilities in particular I'm pretty much in the dark about how to code them. Any ideas? And if anyone as any idea to do it with xml that would be even better.

TIA :goodjob:
 
Sorry to bump the thread, but for #1, would this work?
Code:
GameEvents.PlayerDoTurn.Add(
function(playerID)
	pPlayer = Players[playerID]
	if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_NEWCIV) then
		for pUnit in pPlayer:Units() do
			if (pUnit:GetUnitType() == GameInfoTypes.UNIT_UNIQUEUNIT) then
				pCity = pPlayer:Cities()
				if (Map.PlotDistance(pUnit:GetX(), pUnit:GetY(), pCity:GetX(), pCity:GetY()) <= 2) then
					pUnit:SetHasPromotion(GameInfoTypes.PROMOTION_EXTRADEFENSE, true)
				else
					pUnit:SetHasPromotion(GameInfoTypes.PROMOTION_EXTRADEFENSE, false)
				end
			end
		end
	end
end)
It would give the effect a range of 2 hexes (in theory); isn't that the same range DotF has? Then I could just the unit in question a defense-boosting promotion.

#2 sounds easy enough... except I can't find any function that returns the enemy unit when your unit is in combat.
#3... I have no idea how to find a civ's borders. :sad:
 
#1 is really easy, and I'm pretty sure you have it figured out -- at least the jist of it.

#2 is, as far as I know, very hard, since there really isn't an event that triggers just before combat. The closest thing I could suggest is a unit that gains power all the time based on the number of major players that don't have the prereq tech.

#3 is one of those ugly tricks you can play. You go through all the enemy units' plots, and then you find all the plots within 1 hex of that plot, and you check the owner of all the plots. If the middle plot does not belong to you, but one of the other plots does, the middle plot is just outside your border. If the middle plot does belong to you, and one of the other plots does not, the middle plot is just inside your border.
 
#2 is, as far as I know, very hard, since there really isn't an event that triggers just before combat. The closest thing I could suggest is a unit that gains power all the time based on the number of major players that don't have the prereq tech.
Dang. :( I've been going through the functions and I can't find any kind of function like Unit.IsInCombatWithUnit() or anything.

Basically, the unit replaces the musketman, and should get some kind of combat bonus against civs without gunpowder. The only problem I can forsee with your solution is that it would make it blatantly obvious how many civs are still in the game. Say if it would normally have a strength of 28 and it gets +1 strength per non-gunpowder civ... the 34 strength would alert you that there are 6 opponents still alive. Not only that, but if its strength suddenly drops by one, it becomes clear that a civ was just wiped off the face of the Earth.

Kind of a stupid thing to worry about, but it is at least a small problem.
#3 is one of those ugly tricks you can play. You go through all the enemy units' plots, and then you find all the plots within 1 hex of that plot, and you check the owner of all the plots. If the middle plot does not belong to you, but one of the other plots does, the middle plot is just outside your border. If the middle plot does belong to you, and one of the other plots does not, the middle plot is just inside your border.
I don't know what you mean by "middle plot", but I would like to clarify that by "adjacent to your civ's borders" applies to both inside and outside the civ's borders, not just outside.

Furthermore, in your opinion, does that sound like a UA even worth implementing?
 
By middle plot, I mean the plot that the enemy unit is standing on.

Whether it would be worth it -- yes, it is interesting enough for a UA, assuming that it fits the civ in question.
 
For #3 the AI would have no concept of where the damage is coming from, so, unlike citadels, it will have no logic for allowing for it in it's calculations of when to fight and when to run, so you'll also need some Lua to boost the AI's logic in that area.
 
For #3 the AI would have no concept of where the damage is coming from, so, unlike citadels, it will have no logic for allowing for it in it's calculations of when to fight and when to run, so you'll also need some Lua to boost the AI's logic in that area.

I didn't even think of that. Is that really possible to do with lua? I thought that required DLL modding.

I might have to think of a new UA. I still want to see if #2 is possible, since it sounds like it should be doable, probably because it's similar to the Zulu UA from the scramble to Africa scenario. Unfortunately,
1) That's probably some unalterable XML column that makes that effect, and
2) That unalterable XML column is probably only available for BNW. (My civs are all made for G&K)
 
I didn't even think of that. Is that really possible to do with lua? I thought that required DLL modding.

As you loop each enemy unit and deal out the damage, you'll need to add Lua to work out if the unit will die at the current/expected attrition and if so give it a PushMission to run away. Don't know of any specific examples, although I'm pretty sure that one of the TC's (Ea or Adea possibly) pretty much take over the combat decisions for the AI entirely in Lua

I might have to think of a new UA. I still want to see if #2 is possible, since it sounds like it should be doable, probably because it's similar to the Zulu UA from the scramble to Africa scenario. Unfortunately,
1) That's probably some unalterable XML column that makes that effect, and
2) That unalterable XML column is probably only available for BNW. (My civs are all made for G&K)

CombatBonusVsHigherTech in Traits and it's available for both BNW and G&K - but you want a combat bonus vs a specific "missing" tech so it won't help.
 
So in the Conquest of the New World scenario, does the AI not understand how the Scurvy mechanic works?

Long time since I've played it, but not that I noticed.

Edit: Just checked and there is nothing in the DLL that takes into account damage possible from promotions or plots/terrain/features, only code to apply such damage.

The AI doesn't even understand the damage from mountains and will happily auto-route Carthage's workers from A to B via two mountain tops = death

Edit: And it doesn't even take into account things it should understand - ever watched an AI scout under attack from a barby archer heal itself to death (+10 hp from heal -19hp from archer per turn)

I'm guessing that if your border damage did 10hp per turn and the AI decided that a unit needed to heal (+10hp per turn) and it happened to be on your borders it would sit there for eternity or at least until something wandered past and killed it or your borders happened to shift or you made peace. So you'd need to at least add Lua that said "if I'm about to apply border damage to a healing unit, move that unit away from my borders first" - the hard part of that would be determining the direction of movement.
 
Edit: And it doesn't even take into account things it should understand - ever watched an AI scout under attack from a barby archer heal itself to death (+10 hp from heal -19hp from archer per turn)
:lol: Yeah, I've seen that. The AI can be so stupid most of the time...
I'm guessing that if your border damage did 10hp per turn and the AI decided that a unit needed to heal (+10hp per turn) and it happened to be on your borders it would sit there for eternity or at least until something wandered past and killed it or your borders happened to shift or you made peace. So you'd need to at least add Lua that said "if I'm about to apply border damage to a healing unit, move that unit away from my borders first" - the hard part of that would be determining the direction of movement.
I was thinking more like 25 damage, but the resulting AI add-in lua would be about the same, I guess. Way above my level.


So no one is aware of any kind of function to detect combatants? Does anyone know how to code a new function to do that? If so, the rest of #2 falls right into place: Check that the civilization owning the enemy unit doesn't have gunpowder (the reason behind this being that the unit was among the very first in their continent to use gunpowder weaponry) and quickly add a bonus promotion, then remove it when combat ends. But since no such function apparently exists, I'm at a loss here. :(
 
Is there an example of this somewhere, that you're aware of?

RedAI_Air.lua
RedAI_Global.lua

in R.E.D. WWII Edition for some example of controlled AI units in Lua:
- airsweep
- interception
- destroyers hunting subs
- basic units healing (but the mod use a completely different "healing" system)
- ships looking for harbors to heal
- auto-moving specific units ("convoys" or military units embarked for reinforcement or operations to an area of the map)

some events refers to R.E.D DLL, but all the logic is in Lua (part of this was made before the infamous patch that broke the combat events)
 
Top Bottom