Custom Map #1010: City defense tribute. By: UberWaffe

Started by AutoPost, March 13, 2021, 04:06:45 AM

Previous topic - Next topic

AutoPost

This topic is for discussion of map #1010: City defense tribute


Author: UberWaffe
Size: 320x200

UberWaffe

This is just a test map.
I wanted to share the city production and warehouse scripts with chaotea.

Should be effectively an auto-win map.

Karsten75

Quote from: UberWaffe on March 13, 2021, 04:13:46 AM
This is just a test map.
I wanted to share the city production and warehouse scripts with chaotea.

Should be effectively an auto-win map.

But you should not use the Colonies upload to share maps/scripts/ Auto-win maps are a no-no. Also, a test map has no place in the colonies.

UberWaffe

What is the correct place to share map/scripts/ then?

And how do I go about deleting a map from colonies if it violates the rules?

Karsten75

Quote from: UberWaffe on March 13, 2021, 07:15:18 AM
What is the correct place to share map/scripts/ then?

And how do I go about deleting a map from colonies if it violates the rules?

You can post maps and scripts here on the forums, you can use Discord, you can use the wiki where your CPACK anad CMODs are documented, and you can use any external repository you wish and link people to it.

As for deleting, that's not possible Either the community will flag it or it will remain. :)

chaotea

Interesting stuff. Having a single script for everything works well. Though it works well to reduce the lag, im not 100% sold on the structures being buffs to the other buildings. That said im not against it. Its certainly interesting.

You could apply this concept to a custom weapon, that needs you to build the weapon, then ancillary buildings to improve it.

chaotea

Well on that note im already going back an re-building the city defence based on this to see if it works. Ive re-dont the warehouse building to fit more with the style too.

chaotea

Quote from: UberWaffe on March 13, 2021, 04:13:46 AM
This is just a test map.
I wanted to share the city production and warehouse scripts with chaotea.

Should be effectively an auto-win map.

Found something weird. The warehouse is sucking up about 3k power putting me in a deficit. No idea why, ive not changed the script, just lowered some energy float values for city buildings.

chaotea

Ok, so there seems to be an issue that if you alter the values of the buildings too much, it will take the current value of the energy and apply it as a permanent negative drain to the warehouse.

UberWaffe

#9
Quote from: chaotea on March 14, 2021, 10:24:30 AM
Ok, so there seems to be an issue that if you alter the values of the buildings too much, it will take the current value of the energy and apply it as a permanent negative drain to the warehouse.

Yes, if you alter the values of buildings after any buildings are placed, then things will get wonky.
The principle the script works on is that each building adds its bonus once, and then subtracts it once if destroyed.

If you recompile scripts while buildings are already placed, you'll likely get double additions.

If you change values after placing, before deleting, then the new value will be subtracted instead of the original.

I'm not sure there are good ways around these problems, since scripts always seem to rerun from scratch when you recompile. (Which makes sense, it sort of has to.)


I could look at what would be needed for a script you can run to recalculate the production from scratch.
It wouldn't be for while playing the map normally, but could be run while editing the map.

I'll paste an example here once I get it working.

(Basically the idea would be, set the global values back to 0, and have a way for all the buildings to rerun their "Once" setup.


EDIT:
I see the negative values seem to happen whenever you do a "Update Unit Instances" after at least one game tick has happened (i.e. the global values fall back to 0, and if you then destroy any building, 0 minus a value ends up negative.)
Delete all non-warehouse city buildings, then doing a "Update Unit Instances" and then placing all buildings again should also fix the map.

Once I got the reset script working I'll post that here as well, but the above steps should work as well.

EDIT2: Find attached a console script "CityProductionRest" that can be run once from the console. It will reset the production, and cause all warehouse fillers to re-add their production. Run it once after making changes to buildings and doing a "Update Unit Instances".

Also attached is the updated "CityWarehouseFiller" script. It was changed slightly to include the trigger to recalculate. I also adjusted it to add production on :BuildComplete instead, in case you want to make the buildings buildable like in your tycoon map.
(I uploaded them as txt files, as the forums do not allow 4rpl files.)

chaotea

Quote from: UberWaffe on March 14, 2021, 11:49:24 AM
Quote from: chaotea on March 14, 2021, 10:24:30 AM
Ok, so there seems to be an issue that if you alter the values of the buildings too much, it will take the current value of the energy and apply it as a permanent negative drain to the warehouse.

Yes, if you alter the values of buildings after any buildings are placed, then things will get wonky.
The principle the script works on is that each building adds its bonus once, and then subtracts it once if destroyed.

If you recompile scripts while buildings are already placed, you'll likely get double additions.

If you change values after placing, before deleting, then the new value will be subtracted instead of the original.

I'm not sure there are good ways around these problems, since scripts always seem to rerun from scratch when you recompile. (Which makes sense, it sort of has to.)


I could look at what would be needed for a script you can run to recalculate the production from scratch.
It wouldn't be for while playing the map normally, but could be run while editing the map.

I'll paste an example here once I get it working.

(Basically the idea would be, set the global values back to 0, and have a way for all the buildings to rerun their "Once" setup.


EDIT:
I see the negative values seem to happen whenever you do a "Update Unit Instances" after at least one game tick has happened (i.e. the global values fall back to 0, and if you then destroy any building, 0 minus a value ends up negative.)
Delete all non-warehouse city buildings, then doing a "Update Unit Instances" and then placing all buildings again should also fix the map.

Once I got the reset script working I'll post that here as well, but the above steps should work as well.

EDIT2: Find attached a console script "CityProductionRest" that can be run once from the console. It will reset the production, and cause all warehouse fillers to re-add their production. Run it once after making changes to buildings and doing a "Update Unit Instances".

Also attached is the updated "CityWarehouseFiller" script. It was changed slightly to include the trigger to recalculate. I also adjusted it to add production on :BuildComplete instead, in case you want to make the buildings buildable like in your tycoon map.
(I uploaded them as txt files, as the forums do not allow 4rpl files.)

Right that makes sense. I layed the buildings out, then wanted to reduce the power of each one as global power was too high. I'll update my scripts, probably tuesday night, though i alreadys starteded again. Still, it does seem relitivly lag free.

Thanks for the help here btw. I've got alot of idea, but my coding isnt fantastic (CW4 is my first attempt at coding anything). Im happy that the idea interested you enough to invest time into this. So thank you for that.

UberWaffe

Quote from: chaotea on March 15, 2021, 06:25:35 AM

Right that makes sense. I layed the buildings out, then wanted to reduce the power of each one as global power was too high. I'll update my scripts, probably tuesday night, though i alreadys starteded again. Still, it does seem relitivly lag free.

Thanks for the help here btw. I've got alot of idea, but my coding isnt fantastic (CW4 is my first attempt at coding anything). Im happy that the idea interested you enough to invest time into this. So thank you for that.
No problem.

I thought the map was awesome, and really liked the concept.
Had a lot of fun with the Tycoon map as well. (Hence the update to the script to work with buildings getting built rather than placed.   ;D )

Your coding is much better than you think.
I do this sort of coding (not 4rpl, but similar type coding) for a living, so it was also a fun little challenge to see if I could come up with a way to reduce the lag.

And I figured that a script that does something like this (production across multiple buildings, but only one or two connections) would be useful for other maps / variants as well.

Karsten75

If the scripts have taken on a general-purpose nature, there is a spot on the wiki (4RPL, Tools) where you can contribute it for other players to hopefully find it.

Not as easy to update as GitHub, but I'm not so skilled with GitHub that I'd know how to manage a repo with multiple contributors.

UberWaffe

#13
Noticed I made a really dumb error in the resource build-up part of the warehouse script.
I did not add a "Only once per 30 frames" check, so all resources are basically being added each tick.
Alternatively adjust the values in the script down to 1/30th their per second rate.

It should look like this, with an "if (GetGameUpdateCount mod(30) eq0)"

:DoWaresBuildup
SetUnitUIText(self 1 Concat("Bluite +" <-*CITYPRODBLUITE))
SetUnitUIText(self 2 Concat("Redon +" <-*CITYPRODREDON))
SetUnitUIText(self 3 Concat("Greenar +" <-*CITYPRODGREENAR))
if (GetGameUpdateCount mod(30) eq0)
if (GetGameUpdateCount <-*CITYLASTUPDATED neq)
GetGameUpdateCount ->*CITYLASTUPDATED
<-*CITYBUILDUPBLUITE <-*CITYPRODBLUITE + ->*CITYBUILDUPBLUITE
<-*CITYBUILDUPREDON <-*CITYPRODREDON + ->*CITYBUILDUPREDON
<-*CITYBUILDUPGREENAR <-*CITYPRODGREENAR + ->*CITYBUILDUPGREENAR
endif
endif


EDIT:
Another note: The syntax on the wiki for the :_WarePacketSent is wrong. Should be curley brackets for table data, not square brackets.
See below:

# --------------------------------------------------
:_WarePacketSent
<-_DATA{"unit"} ->unit
<-_DATA{"ware"} ->sentWare
if(<-sentWare 4 eq)
<-*CITYBUILDUPBLUITE 1.0 - ->*CITYBUILDUPBLUITE
endif
if(<-sentWare 5 eq)
<-*CITYBUILDUPREDON 1.0 - ->*CITYBUILDUPREDON
endif
if(<-sentWare 6 eq)
<-*CITYBUILDUPGREENAR 1.0 - ->*CITYBUILDUPGREENAR
endif