C++/Lua Request Thread

Civilians can violate 1upt (with each other) and can pass through other civ's units rather than having to route around them.

While I was looking for something else, I've stumbled on that code in CvAStar.cpp :

Code:
	if(!bUnitIsCombat && unit_domain_type != DOMAIN_AIR)
	{
		const PlayerTypes eUnitPlayer = unit_owner;
		const int iUnitCount = pToPlot->getNumUnits();
		for(int iUnit = 0; iUnit < iUnitCount; ++iUnit)
		{
			const CvUnit* pToPlotUnit = pToPlot->getUnitByIndex(iUnit);
			if(pToPlotUnit != NULL && pToPlotUnit->getOwner() != eUnitPlayer)
			{
				return FALSE; // Plot occupied by another player
			}
		}
	}

Delete it (there are 2 occurrences in that file) to allow go-through.

It'll be in R.E.D. DLL after BNW update.
 
I have a request:

I'm looking for a <PreReqImprovement> tag for buildings, that will allow a building to be constructed only if a certain tile improvement is within the cities borders.

Example: Can build a Steel Mill only if there is a Manufactory within the cities borders.


Thank you in advance!
 
Is there a way to modify/add non-gold trade route yields for civs in BNW, and if not, could someone add one? I need to be able to give one civ a % bonus Food or Production from internal trade routes, and another to generate Tourism from outgoing Science on international trade routes. If there's an existing reference for what events involving those are called, much less how to modify them, I can't find it.
 
A script that makes DoF provides culture to the Empire and a Great Merchant that can conduct an additional Trade Mission that provides Culture instead of Gold.
 
Currently, annex City State via Merchant of Venice and Austria's UA both give all cities and units owned by a CS over to the Player. This may be working as intended, but it is not very good for scenario makers. In my scenario, many CS own more than one city. It is the best way to simulate a minor kingdom (as opposed to as city state). Even in a standard game, it is sometimes possible that a city state has multiple cities under its control. I would like a DLL change that would only allocate the nearest city and tiles under its control (however that is determined), plus units that are closer to that city then they are to other CS cities, to the annexing player.

I could probably create some clunky lua code using wHowards DLL that would have the effect I want above, but it would only work on the Merchant of Venice. In that case, I could delete the annex code in the XML for the Merchant of Venice and cludge together some lua that would act when a trade mission occurs using the Merchant of Venice to transfer the closest city and its units.

A change in the DLL would be less clunky and effect Austria also.

Please save me from trying to put together some half-assed code...:)
 
I have a request for Lua code that should be relatively simple to write for experts on the subject:

When a human player researches a technology, clear the production orders of all non-puppet cities belonging to that player that produce Wealth or Research (but it shouldn't make that player lose one turn of production in these cities). This should cause production popups to appear for these cities at the same turn as the technology popup.
 
When a human player researches a technology, clear the production orders of all non-puppet cities belonging to that player that produce Wealth or Research

Code:
local iProcessWealth = GameInfoTypes.PROCESS_WEALTH
local iProcessResearch = GameInfoTypes.PROCESS_RESEARCH

local bTeamProcesses = {}

function OnTeamSetHasTech(iTeam, iTech)
  local pTeamCaptain = Players[Teams[iTeam]:GetLeaderID()]
	
  if (bTeamProcesses[iTeam] or pTeamCaptain:CanMaintain(iProcessWealth) or pTeamCaptain:CanMaintain(iProcessResearch)) then
    bTeamProcesses[iTeam] = true
	
    for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
      local pPlayer = Players[iPlayer]

      if (pPlayer:GetTeam() == iTeam and pPlayer:IsHuman()) then
        for pCity in pPlayer:Cities() do
          if (not pCity:IsPuppet() and pCity:IsProductionProcess()) then
            pCity:ClearOrderQueue()
          end
        end
      end
    end
  end
end
GameEvents.TeamSetHasTech.Add(OnTeamSetHasTech)

This is the same as cycling all your cities after researching a tech and manually clearing the process orders, so should work as required for ...

(but it shouldn't make that player lose one turn of production in these cities). This should cause production popups to appear for these cities at the same turn as the technology popup.
 
Testing showed that the production popup was coming the next turn, not the turn when the tech was researched. I managed to fix it -

After:
Code:
pCity:ClearOrderQueue()

I added:
Code:
pCity:ChooseProduction()

Now it seems to work properly, although the UI update is delayed - the process icon is not removed immediately when the tech is researched, but it's not a big problem for me.
 
I've been using GameEvents.TeamTechResearched (same args). If (if!) there is a difference in event timing, it's possible that this would fire off before UI updates.
 
I checked it, and it's the same as before. So I changed it back to TeamSetHasTech, as probably it also triggers when getting a tech from other sources than research (like a free tech from a wonder).

Edit: Delayed interface updates seems to be a problem with the game itself. I checked it in unmodded game, and when a city is producing Wealth/Research, it doesn't update properly when the population grows.
 
I think I may have seen this too in a different form. I added a bunch of processes. When a city is building one, then the city ranged attack button won't appear when enemy unit in range. Entering/exiting city screen clears the problem. I blamed it on my modding but never tested one of the original processes. (I've never seen this reported as a bug for base Civ5.)
 
So the Iron Curtain policy gives what I want (a %-based increase in yields from internal trade routes applied before the sea modifier). So at this point, I am guessing I need to make a social policy that is invisible and unpickable, give it Iron Curtain's % bonus set to the value I want, and make it so this civilization is automatically granted that social policy at game start.

So, uh, how do I do that thing I said?
 
How to make a Trait that gives a certain civilization UP to 3 of a certain Unit whenever that Civ builds a Wonder?

I believe this is via Lua, because I have no idea how to make it work via .xml.

Code:
After you build a Wonder, up to three Brotherhood Monks appear at your capital.
This is the trait.


That's what I came up with after trying to merge two mods (Tuscany from sukritact and Ningen no Sato from bouncymischa):

Code:
print ("loaded Hoshi Dragon Clan UA Lua") 

include( "SaveUtils" ); MY_MOD_NAME = "TogashiHoshi";

function TogashiUA (iPlayer)

	-- Putmalk: Initialize pointer for PlayerID iPlayer
	local pPlayer = Players[iPlayer];

	-- Ignore Minors and Barbarians
	if( pPlayer:IsMinorCiv() or pPlayer:IsBarbarian() ) then
		--print("Player is minor or barbarian, not executing code.");
		return;
	end

	-- for testing purposes --print these out to verify they are equal / not equal
	----print( tostring(pPlayer:GetCivilizationType()) );
	----print( tostring(GameInfoTypes["CIVILIZATION_TOUHOU_HV"] ) );
	
	if ( pPlayer:GetCivilizationType() ~= GameInfoTypes["CIVILIZATION_TOGASHI"] ) then
		--print("Player " .. tostring(iPlayer) .. " is not the Human Village");
		return;
	end
	
	--local pCity = pPlayer:GetCapitalCity();
	--local iBuildingType = GameInfo.Buildings()

	leaderType = GameInfo.Leaders[pPlayer:GetLeaderType()].Type
	traitType = GameInfo.Leader_Traits("LeaderType ='" .. leaderType .. "'")().TraitType
	trait = GameInfo.Traits[traitType]
	--print("Player has trait " .. trait.Type);
	
	for pCity in pPlayer:Cities() do

	for building in GameInfo.Buildings() do
		strName = GameInfo.Buildings[building.ID].Description
		strType = GameInfo.Buildings[building.ID].Type
		strCityName = pCity:GetName()
	
		if pCity:IsHasBuilding(building.ID) then
			if load( pPlayer, building.ID .. "and" .. iPlayer) ~= true then
				strBuildingClass = GameInfo.Buildings[building.ID].BuildingClass
				if GameInfo.BuildingClasses[strBuildingClass].MaxPlayerInstances > (-1)then
					save( pPlayer, building.ID .. "and" .. iPlayer, true );
					----print(strName .. " inserted from: " .. strCityName .. " but not applicable for UA")
				else if GameInfo.BuildingClasses[strBuildingClass].MaxGlobalInstances > (-1) then
					--print(strType .. " completed.");
						local iUnitID = GameInfo.Units.UNIT_WORKER.ID
						pPlayer:InitUnit (iUnitID, pCity:GetX(), pCity:GetY() );
					else
						--print("is not a Wonder");
					end
				end
			else
				--print (strName .. " not new construction in city: " .. strCityName)
			end
		else
			--print("Building: " .. strName .. " does not exist in city: " .. strCityName)
		end
	end
	end
end

GameEvents.PlayerDoTurn.Add(TogashiUA)
GameEvents.PlayerAdoptPolicy.Add(TogashiUA)

function CityScreenTogashiUA()
	local iPlayer = Game.GetActivePlayer()
	TogashiUA(iPlayer)
end

Events.SerialEventExitCityScreen.Add(CityScreenTogashiUA)

What should I do now? I never did anything related to lua. I know nothing, less so than Jon Snow. Please help! :)

bouncymischa gave me perfect directions and it is working now, but it gives me a Worker EVERY turn after every time I look at the Wonder, I want to have a random number (up to 3) spawn once after each Wonder is built.

Also, I got a ton of these on lua.log file:
Code:
[262538.107] Dragon: Warning: cache not shared.
[262538.107] Dragon: Warning: cache not shared.
[262538.107] Dragon: Warning: cache not shared.
[262538.107] Dragon: Warning: cache not shared.
[262538.107] Dragon: Warning: cache not shared.
[262538.107] Dragon: Warning: cache not shared.
[262538.123] Dragon: Warning: cache not shared.
[262538.123] Dragon: Warning: cache not shared.
[262538.123] Dragon: Warning: cache not shared.
[262538.123] Dragon: Warning: cache not shared.
[262538.123] Dragon: Warning: cache not shared.
[262538.123] Dragon: Warning: cache not shared.
[262544.799] Dragon: Warning: cache not shared.
[262544.799] Dragon: Warning: cache not shared.
[262544.799] Dragon: Warning: cache not shared.
[262544.799] Dragon: Warning: cache not shared.
[262544.799] Dragon: Warning: cache not shared.
[262544.799] Dragon: Warning: cache not shared.
[262544.831] Dragon: Warning: cache not shared.
[262544.831] Dragon: Warning: cache not shared.
 

Attachments

  • Civ5Screen0058.jpg
    Civ5Screen0058.jpg
    364 KB · Views: 194
I'm getting to the point of requiring Lua for my next mod, and there's a couple ways I could use it. The trait I've decided on is essentially, something like this: During :c5goldenage: Golden Ages, all tiles that yield at least 1 :c5gold: Gold also yield +1 :c5science: Science.

So, this could go in a few different ways. Like bouncymischa suggested to me a while ago, it could be done with a hidden building that increases the yields of resources/features that yield gold, but there's no way (that I know of) for a building to increase an Improvement's yields. Alternatively, it would be a godsend if someone could figure out a way to make a Buildings tag that increases a tile's yield based on its existing yields, sorta like this, as a theoretical example:
Code:
<Building_TerrainYieldImprovedYield>
	<Row>
		<BuildingType>BUILDING_GOLDAGEHIDDEN</BuildingType>
		<TerrainYieldType>YIELD_GOLD</TerrainYieldType>
		<YieldType>YIELD_SCIENCE</YieldType>
		<Yield>1</Yield>
	</Row>
</Building_TerrainYieldImprovedYield>
Of course, if anyone provides me with any scripts that I end up using in the final release, I'll be EXTREMELY thankful and credit you appropriately (and would be willing to mark you as a creator on the steam workshop, if you so wish), though I wish there were more I could do in exchange.
 
I'm not sure this is the right place to ask, but I need a way to make a resource (specifically warpstone) appear in random locations on the map during the game. This is to represent meteorites of warpstone crashing to earth and, like in real Warhammer, having huge armies clash over them.:spear:

If possible, having the "meteorites" damage the unit or city they appear under would be great.

Sorry, I just love that smilie...
 
I'm not sure this is the right place to ask
It's fine for a short request, but you don't want to have an extended conversation.

I need a way to make a resource (specifically warpstone) appear in random locations on the map during the game.
Most of the pieces have been done for you already. Check out one of the random event generators such as JHW Random Events SP.

Your event will combine a few of the existing events in MyUserEvents.lua. Apparently the meteor strike event caused crashes, so it was disabled (but that event was just a random nuke strike). Take a look at the New Mineral event. You'll want to combine that with the Tornado (which pillages improvements) and Sickness (which damages a unit) [note that cities also have a SetDamage function, though the Plague event (which lowers population) might be good for cities too].
 
Back
Top Bottom