Home » MODDING HQ 1.13 » Flugente's Magika Workshop » New feature: factories
New feature: factories[message #360074] Sun, 17 May 2020 23:46 Go to next message
Flugente

 
Messages:3534
Registered:April 2009
Location: Germany
A long time ago, in a city far, far away (Bremen), I was asked whether I could implement a feature that would allow us to set up factories. It didn't interest me back then (apart from the possibility to dangle this in front of smeag in exchange for food), but now I find myself wanting something contemplativeto do. So here we are.



This feature allows us to set up factories at facilities. A factory creates items and puts them into the sector.
This is set up in FacilityTypes.xml:
Toggle Spoiler

As modders can add and remove facilities in the xmls at any point, we cannot hardcode factories. This poses a problem - how do we store production progress, or whether or not a factory was turned on?
This is solved in strategicmap.lua. Basically each factory is assigned one modder-administered value that is nevertheless stored in the savegames. The value stores whether a factory is on or off, and how much progress on the current item has been reached.
Toggle Spoiler

The feature is off by default, and can be activated in Ja2_Options.ini:
;------------------------------------------------------------------------------------------------------------------------------
; Facilities can produce items.
; This requires defining production lines for each item in FacilityTypes.xml and some set up in SetFactoryLeftoverProgress(...)
; and GetFactoryLeftoverProgress(...) in scripts/strategicmap.lua.
;------------------------------------------------------------------------------------------------------------------------------

FACTORIES = FALSE  <-- set this to TRUE

This allows a modder to set up facilities wherever they want, and to tie them to quests however they want (more on that in the next post). It does require a bit of lua work though, I don't see a way around that.

This is fully savegame compatible.

As this feature includes new map overlay symbols and lua functions, you are required to update the GameDir data.

This has been added to the trunk in r8804 & GameDir r2534. Using the new exe without the new GameDir will cause allergic reactions to html.

[Updated on: Sun, 17 May 2020 23:52]




I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: New feature: factories[message #360075 is a reply to message #360074] Sun, 17 May 2020 23:47 Go to previous messageGo to next message
Flugente

 
Messages:3534
Registered:April 2009
Location: Germany
Now, a few pointers for modders who want to use this.

Producing items is basically a sub-ability of facilities. So whatever you do, you need a facility. These are defined in FacilityTypes.xml and placed on the map in Facilities.xml

We define a T-Shirt factory...
<FACILITYTYPE>
	<ubIndex>23</ubIndex>
	<szFacilityName>T-Shirt Factory</szFacilityName>
	<szFacilityShortName>Factory</szFacilityShortName>
	<ubTotalStaffLimit>4</ubTotalStaffLimit>
	<PRODUCTIONLINE>
		<!-- create string -->
		<usItemToCreate>311</usItemToCreate>
                ...

... and place this in Drassen.
<FACILITY> 
	<SectorGrid>C13</SectorGrid>   
	<FacilityType>23</FacilityType>  
	<ubHidden>1</ubHidden>  
</FACILITY

Now we need to set up a number for each <PRODUCTIONLINE> of our facility in strategicmap.lua:
-- We have an array of 1000 signed integers that a modder can use to set whatever data he wants.
-- We simply set up some enums here to make it easier for us to remember what is what
ModSpecificFacts =
{	
	-- |||||||||||||||||||||||||||||||||| factories |||||||||||||||||||||||||||||||||||||
	FACTORY_PROGRESS_DRASSEN_TSHIRTFACTORY_1 = 159,		-- 9 products

These numbers can be whatever we like, but they should not already be in use. Otherwise you have weird stuff happening, like taking a photo of a Alma prison activating our surgical facemask production angry

In SetFactoryLeftoverProgress(...), we need to store values for when the game sets on, like when we click on the buttons in the laptopn page or when the game writes the partial progress of our factory
function SetFactoryLeftoverProgress(sSectorX, sSectorY, bSectorZ, usFacilityType, usProductionNumber, sProgressLeft)
	
	if ( bSectorZ == 0 ) then
	
		if ( sSectorX == 13 and sSectorY == SectorY.MAP_ROW_C and usFacilityType == 23 ) then
	
			SetModderLUAFact(ModSpecificFacts.FACTORY_PROGRESS_DRASSEN_TSHIRTFACTORY_1 + usProductionNumber, 1 + sProgressLeft)
The above checks for sector are necessary. We could have placed the same facility type in several sectors, so the type isn't enough to identify a production line.

The game also asks us 'what value do we have for a factory', which we answer in GetFactoryLeftoverProgress(...)
function GetFactoryLeftoverProgress(sSectorX, sSectorY, bSectorZ, usFacilityType, usProductionNumber, sProgressLeft)
	
	CANT_ACTIVATE_FACTORY = -20
	
	val = -1
	
	if ( bSectorZ == 0 ) then
	
		if ( sSectorX == 13 and sSectorY == SectorY.MAP_ROW_C and usFacilityType == 23 ) then
	
			-- The T-Shirt factory can only be used once Doreen is gone, one way or the other
			if ( gubQuest( Quests.QUEST_FREE_CHILDREN ) == qStatus.QUESTDONE ) then
				
				val = GetModderLUAFact(ModSpecificFacts.FACTORY_PROGRESS_DRASSEN_TSHIRTFACTORY_1 + usProductionNumber) - 1
				
				-- The T-Shirt factory can be 'upgraded' to also produce uniforms
				-- The upgrade is not an item, it exists purely in the lua values
				-- We've set the upgrade time to be 03:01. As we set the progress on each full hour, there will be a point in time where the value is 180
				-- We use that value as 'upgrade has been done'. The upgrade cannot be built anymore -> val = CANT_ACTIVATE_FACTORY.
				-- The uniform production lines always return CANT_ACTIVATE_FACTORY if the upgrade is not there yet.
				if ( usProductionNumber == FactorySpecialValues.FACTORY_PROGRESS_DRASSEN_TSHIRTFACTORY_UPGRADE and val > 170 ) then
				
					val = CANT_ACTIVATE_FACTORY
					
				elseif ( usProductionNumber > FactorySpecialValues.FACTORY_PROGRESS_DRASSEN_TSHIRTFACTORY_UPGRADE ) then
				
					tmp = GetModderLUAFact(ModSpecificFacts.FACTORY_PROGRESS_DRASSEN_TSHIRTFACTORY_1 + FactorySpecialValues.FACTORY_PROGRESS_DRASSEN_TSHIRTFACTORY_UPGRADE) - 1
					
					if ( tmp < 170 ) then
					
						val = CANT_ACTIVATE_FACTORY
						
					end
				
				end
				
			else
			
				val = CANT_ACTIVATE_FACTORY
				
			end

This is where a modder can add their own conditions. In the above example, if the Doreen quest has not been finished, we always tell the game 'Nah, you can't activate this factory at all'. Which is why I had Moira kill Doreen in the video - I set it up so that we need onwership of the factory first.

There's also a bit more here. As seen in the video, one of the things we set up was an 'Upgrade' to the facility. This does not produce an item, but 'unlocks' the uniform production after three hours. Only once that is done those can be accessed, while the upgrade is permanently locked (no need to do it twice after all).

Of course you can also tie factory activation to NPC deaths, like we do for the Hicks:
elseif ( sSectorX == 10 and sSectorY == SectorY.MAP_ROW_F and usFacilityType == 24 ) then
		
	-- the Hicks farm can only be used if the quest was solved by killing the Hicks family
	if ( MercIsDead(Profil.DARREL) and MercIsDead(Profil.DARYL) ) then

        	val = GetModderLUAFact(ModSpecificFacts.FACTORY_PROGRESS_CAMBRIA_HICKSFARM_1 + usProductionNumber) - 1
				
	else
			
		val = CANT_ACTIVATE_FACTORY
		
	end

Orta is a bit tricker. The factory itself is underground, but facilities can not be defined for underground sectors. I use a trick, I tie the activation on whether or not Ernest gave us access to the storage room. Seems reasonably to me that we can only produce things once we've gained control over the assembly lines.
elseif ( sSectorX == 4 and sSectorY == SectorY.MAP_ROW_K and usFacilityType == 15 ) then
		
	-- the Orta factory can only be used once Ernest gave us the rifles (and presumably control over the assembly lines)
	if ( (CheckFact( Facts.FACT_CONVO_ERNEST, 0 ) == true) ) then

		val = GetModderLUAFact(ModSpecificFacts.FACTORY_PROGRESS_GRUMM_ORTAFACTORY + usProductionNumber) - 1
			
	else
	
		val = CANT_ACTIVATE_FACTORY
				
	end
		
end

Back to FacilityTypes.xml. Factories don't need mercs to be staffing the facility. My intention was for us to pay the civilians to do the work (after all, hiring a merc only for them to sit on an assembly line is kinda silly). That's what the sHourlyCost and usOptional_LoyaltyRequired tags are for.
<sHourlyCost>6</sHourlyCost>
<usOptional_LoyaltyRequired>15</usOptional_LoyaltyRequired>

But you can also tie this to mercs, as seen with Nails in Grumm.
<PRODUCTIONLINE>
	<!-- 60mm Mortar Shell from TNT -->
	<szAdditionalRequirementTips> - Requires staffing by merc</szAdditionalRequirementTips>
	<usItemToCreate>140</usItemToCreate>
	<sMinutesRequired>60</sMinutesRequired>
	<sGridNo_Creation>19101</sGridNo_Creation>
	<requires_staff>1</requires_staff>
	<usOptional_ItemUsedUp>137</usOptional_ItemUsedUp>
	<usOptional_ItemUsedUp>137</usOptional_ItemUsedUp>
</PRODUCTIONLINE>

In this case the factory does not cost money, but work is only done if a merc is staffing and awake. With him also training explosives, it sure looks like he is creating those mortat shells big grin

The idea of this factory is that the mercs use the excessive amount of grenades and explosives they find to create mortar shells. As that sounds... not harmless, the staffing merc is required to be somewhat knowlegeable about explosives, and there is risk of injury here.

While the prices for items in general could use an update, I tried to be somewhat fitting to the items here. In general, producing an item in Arulco is cheaper than outright buying it from a merchant or Bobby Rays. You can of course alter this.
Let's skip this silly 'civil war' nonsense. The best experience is to to acquire a factory, produce items at low prices and sell them for a healthy margin!

Note that we can also use negative values for <sHourlyCost>. So this
<PRODUCTIONLINE>
	<szProductionName>Flugente's gun emporium</szProductionName>
	<sMinutesRequired>60</sMinutesRequired>
	<requires_staff>1</requires_staff>
	<sHourlyCost>-25</sHourlyCost>
	<usOptional_ItemUsedUp>12</usOptional_ItemUsedUp>	<!-- Item #256 is the Colt M4 Commando -->
</PRODUCTIONLINE>
sets up a merc as a street vendor, who sells your M4s for... 25$. What do I know about gun prices big grin

Meanwhile,
<PRODUCTIONLINE>
	<usItemToCreate>1724</usItemToCreate>	<!-- Item #1724 is Wooden Planks -->
	<sMinutesRequired>60</sMinutesRequired>
	<sGridNo_Creation>11306</sGridNo_Creation>
	<requires_staff>1</requires_staff>
</PRODUCTIONLINE>
would set up a lumberjack.

You could also set up a merc to search Estoni for useful goods:
<PRODUCTIONLINE>
	<szProductionName>Dumpster diving</szProductionName>
	<usItemToCreate>xxx</usItemToCreate>
	<sMinutesRequired>20</sMinutesRequired>
	<sGridNo_Creation>11306</sGridNo_Creation>
	<requires_staff>1</requires_staff>
</PRODUCTIONLINE>

The idea here is that 'xxx' is random item, which is resolved into various items we could find in a junkyard. Soda cans, string, rags, low grade ammo clips, pipes, rubber bands...

Similar to the above idea of the 'upgrade' to the T-Shirt factory, you could also use factories to affect other non-item things. As you can add volunteers in lua, you could, I dunno, set up a merc-staffed strip mall that gains volunteers big grin
Or, say, set up a voodoo temple that causes Deidranna's death after a week of ritual prayer and the sacrifice of a thousand skulls suprised

I am sure others will come up with other ideas, that's what this thread is for after all.

[Updated on: Mon, 18 May 2020 00:45]




I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: New feature: factories[message #360078 is a reply to message #360075] Mon, 18 May 2020 04:57 Go to previous messageGo to next message
Kitty

 
Messages:172
Registered:October 2017
Location: Germany
Boah eh, that's just major cool. suprised

While updating AR, I had to do a lot of lua-work (adding about 100 new mod-specific-facts alone), so I allready know this is gonna be work-intensive.
But it'll be certainly worth it, cause it will perfectly fit in with the AR style of live-out-the-land. In some other feature, you advised to leave numbers
unused for those facts for future additions by you, I'm glad I did follow this.

Despite several attempts and a bunch of tutorials, I sadly never managed to succesful compile. And this is certainly a moment where I realy regret this,
cause I wanna try this feature asap shy My thoughts are allready spinning about how to put this to best use.

- an offshore Serverfarm where Speck needs to be assigned, resulting in cash-flow but also spam-emails to the player
- make Lora Ricci hireable and let her start her own Ricci-bag or Eau de Lora factory
- Tex could go back to producing cheesy videos, distributed exclusivly by Betty Fu
- cow meat could be used for producing beef-jerky (no pigs, no spam)

I allready did some work with .sti for a brewery, now I could pick this up for a brewery run by drunk Larry.


Two questions:

01:
<usOptional_ItemUsedUp>1022</usOptional_ItemUsedUp>	<!-- This item is consumed in the creation process. We can enter add several items of the same kind, or different ones altogether. --


The ItemUsedUp has to be in the sector inventory, either by a first line of production or placed there by the player. Is this true?

and

02:

<usItemToCreate>xxx</usItemToCreate>

The idea here is that 'xxx' is random item, which is resolved into various items we could find in a junkyard. Soda cans, string, rags, low grade ammo clips, pipes, rubber bands...



Is "xxx" meant as a placeholder for what to fill in by modder , or will filling in "xxx" result in random items. Probably the first, but if the later, defined in random items or elsewhere?


1.13 certainly has seen some cool new stuff in the past few month, you guys never stop amazing me. Thanks a lot.

[Updated on: Mon, 18 May 2020 07:30]




I need more details.

(Didi Hallervorden)
Re: New feature: factories[message #360082 is a reply to message #360078] Mon, 18 May 2020 21:15 Go to previous messageGo to next message
Flugente

 
Messages:3534
Registered:April 2009
Location: Germany
While there is no lua function to check whether a specific merc staffs a facility, one could simply check for the merc's presence in the sector itself as a requirement in the lua scripts. Then technically someone else could staff the thing, but if the merc has to be present anyway, might as well use them.

01: Yes. The items need to be in the sector inventory and accessible at the time of creation. That's why I lined up the T-Shirt factory things this way, the strings are turned into rags, and both are then turned into T-Shirts etc..

02: 'xxx' is meant as a placeholder for the itemnumber of a to-be-created random item.



I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: New feature: factories[message #360117 is a reply to message #360074] Fri, 22 May 2020 08:22 Go to previous messageGo to next message
Cerhio

 
Messages:118
Registered:March 2013
Holy shit, this is so cool! Imagine creating an ammo factory 😎
Re: New feature: factories[message #360188 is a reply to message #360117] Fri, 29 May 2020 15:55 Go to previous messageGo to next message
funk

 
Messages:45
Registered:March 2008
I take it this can used used for Militia Resources an manpower too?
A smuggle arm or people factory that turns cash in guns or manpower.
It would give us a reason to hold the out edges of the map.
Re: New feature: factories[message #360215 is a reply to message #360188] Sat, 30 May 2020 22:39 Go to previous messageGo to next message
Flugente

 
Messages:3534
Registered:April 2009
Location: Germany
That would work. Basically a 61-minute production line, whenever we set the value 60, add things in lua and set a value of 0.

I don't think there is a an interface function to set militia resources yet, but volunteers/money/intel can already be set.



I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: New feature: factories[message #360241 is a reply to message #360215] Mon, 01 June 2020 12:48 Go to previous messageGo to next message
Vritran

 
Messages:177
Registered:February 2020
Location: North East England
Just an idea but what about a PPE factory?

It makes first aid kits, possibly med kits and stims (possibly) as well.

One thing the current pandemic has taught me, is that you can start PPE factory anywhere with all kinds of (seemingly) random materials.

Re: New feature: factories[message #360242 is a reply to message #360241] Mon, 01 June 2020 14:47 Go to previous messageGo to next message
Flugente

 
Messages:3534
Registered:April 2009
Location: Germany
The T-Shirt factory in the video already creates facemasks from rags & strings, so I'm way ahead of you cheeky

As we can create makeshift bandages by combining 2 rags, we also have pseudo first aid kits (one could simply add a production line for that, in case one doesn't want to do it by hand). Anything more advanced would be odd for a simple workshop.

As for drugs, one could, say, add a drug lab to the ruins of the Cambria university. One of the southernmost rooms seems like a pretty good setup. Ultimately there are a lot of possibilities happy

[Updated on: Mon, 01 June 2020 14:50]




I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: New feature: factories[message #360253 is a reply to message #360242] Wed, 03 June 2020 02:53 Go to previous messageGo to next message
Flugente

 
Messages:3534
Registered:April 2009
Location: Germany
Small fix in GameDir r2543: a facility with no ASSIGNMENT shows a faulty entry in the Facilities menu if ubTotalStaffLimit > 0. As we don't need staffing mercs if there is no assignment (as is the case with the T-Shirt Factory and Hicks Farm), simply setting ubTotalStaffLimit to 0 removes the menu entry.

[Updated on: Wed, 03 June 2020 02:56]




I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: New feature: factories[message #360263 is a reply to message #360253] Thu, 04 June 2020 01:54 Go to previous messageGo to next message
sylar951

 
Messages:57
Registered:December 2013
I remember proposing this idea years ago! http://thepit.ja-galaxy-forum.com/index.php?t=msg&th=23536&goto=351399&#msg_351399
Was not received quite well back then.

Anyway Flugi, do you already have some factories set up like shown in the video? If yes, which ones?

[Updated on: Thu, 04 June 2020 01:56]

Re: New feature: factories[message #360266 is a reply to message #360263] Thu, 04 June 2020 13:07 Go to previous messageGo to next message
Flugente

 
Messages:3534
Registered:April 2009
Location: Germany
All those from the video, since they are in the trunk.



I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: New feature: factories[message #360278 is a reply to message #360266] Fri, 05 June 2020 02:42 Go to previous messageGo to next message
sylar951

 
Messages:57
Registered:December 2013
Flugente wrote on Thu, 04 June 2020 13:07
All those from the video, since they are in the trunk.
Right. So we have clothes factory in drassen, food farm in hicks sector, shells and munitions facility in grumm. Is that all?
And does munitions facility in grumm produce 7.62x39mm ammo boxes only?
Re: New feature: factories[message #360290 is a reply to message #360278] Fri, 05 June 2020 20:11 Go to previous messageGo to next message
Flugente

 
Messages:3534
Registered:April 2009
Location: Germany
There's also Orta, which is somewhat unusual as it produces items on the top, but requires first solving the quest in the basement, as facilities (and thus factories) can only exist in surface sectors due to code limitations.

In stock the munitions factory only produces 7.62x39mm ammo boxes, yes. It's suffices as an example, and producing an old WW2 calibre seems a lot more believable to me than if it produced fancy-schmancy hightech stuff.



I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: New feature: factories[message #360304 is a reply to message #360074] Sun, 07 June 2020 03:12 Go to previous messageGo to next message
Kitty

 
Messages:172
Registered:October 2017
Location: Germany
Is there a way to set the working population and/or amount of available volunteers as an additional (optional) condition for a factory to work? Like it can be done with the mines?



I need more details.

(Didi Hallervorden)
Re: New feature: factories[message #360312 is a reply to message #360304] Sun, 07 June 2020 22:36 Go to previous messageGo to next message
Flugente

 
Messages:3534
Registered:April 2009
Location: Germany
Hmm. I don't think so. You can add volunteers, but there is no function to retrieve the number or volunteers yet. I should probably add that and a few other interface functions, like intel count, worker count, militia resources.

Any other ideas at what we could check against while I'm at it?



I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: New feature: factories[message #360316 is a reply to message #360312] Mon, 08 June 2020 00:32 Go to previous messageGo to next message
Kitty

 
Messages:172
Registered:October 2017
Location: Germany
Hm, probably not possible since likely defined at gamestart, but changing the watertype from clean to poluted could also prevent overusing of a factory. Or the chance to increase the infection-chance when running a factory (the sector-infection, like when not burrying the corpses).

In my opinion, those factories are giving the player an advantage, which is fine. But this immediatly triggers something nasty in me, looking for a way to make this harder to achieve or creating a need to wager benefits against possible hinderances and dangers. shy

I testruns I added ambient to increase the fatigue, to simulate lung-problems when a factory is in the neighbourhood and a health-drop with injury-chance. But that can be done allready.
Connecting a modder-lua-fact for succesfull hacking or reading needs a little more testing, but also seems to be working, which is rather cool. happy

Now I need to find out, how to make use of UB-quests (to rewrite them with other content) and together with this factories, it should be possible to create a fallow-tree and sap plantage at Orilla Island.
Or get this Briefing Room to run, getting a quest by Jake and Brenda to win a sector with a lab to produce sap at the factory located there.
One thing I learned the past year, is that I'll never will run out of stuff to investigate how certain parts in JA2-113 may work and how this could be used happy



I need more details.

(Didi Hallervorden)
Re: New feature: factories[message #360332 is a reply to message #360312] Tue, 09 June 2020 21:23 Go to previous messageGo to next message
Kitty

 
Messages:172
Registered:October 2017
Location: Germany
Quote:
Any other ideas at what we could check against while I'm at it?
Might be asking for too much, but checking for existance of a .sti at certain gridNo in sector would be cool.

What I'm thinking about is, that in some mods (present and future) there are situations when the enemy is blowing up parts of the building when the players attack is recognized.
Mostly done by a panic trigger used to trigger an action item with explosion. In standard 113 this is happening in the MilitaryHeadquarter, injuring Seargant Krott.

This easily can be done for sectors with factories as well, in RR this results in a lightning strike, in MFM the player is greeted with explosions when arriving in Omerta, etc.

While looking at furniture in InteractiveActions, it seems possible to connect .sti at a gridno to result in a lua-ID. So, what if something simular could be done for factories.
If .sti of an assembly line is undamaged, the player can use factory. If .sti of assembly line is replaced by .sti of DestructionPartner, because the enemy has blown it up, the factory
cannot be used. Like with the controls at SAM-Sites, player then could get the opportunity to repair.

I have no glue, how much work this probably would cause, but since you asked .... shy


Or can this be done with InteractiveActions allready and I just failed to see how?
Shutting down a factory and restart a factory should be possible with connecting the results of a hacked PC,
but changes made by explosions (changed .sti) I couldn't find a way.

[Updated on: Tue, 09 June 2020 21:33]




I need more details.

(Didi Hallervorden)
Re: New feature: factories[message #360350 is a reply to message #360332] Thu, 11 June 2020 22:14 Go to previous message
Flugente

 
Messages:3534
Registered:April 2009
Location: Germany
As of r8819, you can use the following functions in lua, which might be useful here too:
-- get town id, add or get number of workers
townid = GetTownIdForSector(sectory,sectory)
AddTownWorkers(townid, workerstoadd)
workersintown = GetTownWorkers(townid)

-- add or get militia resource
AddMilitiaResources(gunstoadd,armourtoadd,misctoadd)
resourcesgun = GetMilitiaResources_Gun()
resourcesarmour = GetMilitiaResources_Armour()
resourcesmisc = GetMilitiaResources_Misc()

-- add or get intel
AddIntel(inteltoadd)
val = GetIntel()

AddVolunteers(volunteerstoadd)
val = GetVolunteers()

Testing whether structures still exist is tricky, as we can only test that if a sector is currently loaded. This will not always be the case.
This means you'd have to store that status in a lua modderfact value. However, there is not function in lua that is called when a structure-remove action happens, which is where we'd have to do that. Even more this assumes that a structure exists at start to begin with.
Add to that the fact that the AI only ever destroys scenery by accident, and this seems like a relatively huge effort for tiny gains.

However, iirc the actions you described, like the explosion that injures Krott, are triggered by action items, which are handled in ExplosionControl.lua. So simply adding a check that looks whether a specific item on a spacific gridno is triggered and subsequently setting a variable seems a lot more fruitful to me.

Water quality and other sector stuff is taken from the xml. What your proposal would require is a separate function that modifies those according to lua input. All doable, but... meh. Seems like a slippery slope before outsourcing ever increasing parts of the code to lua, which I'm not too big a fan of, even though I use it.



I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Previous Topic: New feature: exploration
Next Topic: New feature: Arulco Special Division
Goto Forum:
  


Current Time: Fri Jul 10 18:58:52 EEST 2020

Total time taken to generate the page: 0.01028 seconds