[LUA] Add function to restrict buildings
In order to create better barriers for the AI (as in the original) we need a function that blocks certain buildings in certain areas. As a map may have multiple of those zones, one must be able to pass an ID in order to lift the correct restrictions if wanted.
Then function should only forbid buildings as you may have 2 overlapping areas. So defining a new area may look like this: SetBuildingRestrictions(NO_LARGE_MILI, {BLD_FORTRESS, BLD_WATCHTOWER}, {32,32, 0, 32, 0,0, 32,0})
That way we can recreate the barriers of the original game and may also create new features like a swamp where only barracks are allowed.
I feel that this may be to fine grained and "un-settlerish". Why can one only build small military buildings although the building spots are big? It can also become a performance bottleneck if everyone would need to check polygons for each building one wants to build
So:
- Is this only for AI?
- Would it be enough to disallow all military buildings in an area? (your swamp use case could just make the map so that only small buildings are allowed)
- Counter-proposal for the interface: 2 functions for enable/disable each taking an area. Overlapping areas won't be possible anyway if there is only 1 type of area, right?
- Otherwise: Return an ID for the created area and use that, but then: What if you want to (re)allow only a part of the area? IMO the enable/disable approach looks more flexible
I thought this may be tied to the building spot itself, so only when the script sets the values they need to be updated. Most operations I can think of are: SetRestriction, lift them by event. In most cases one would set the same restrictions for everyone I think, but why limit it (if not for performance reasons)? Surely the scripter should display a message like "oh no, its a swamp, bad ground, no big buildings there" or something like that.
Also this would be a nice feature for an introduction mission where you may only build on certain spots.
Regarding the question:
- Should be for both, players and AI
- To recreate the original missions, it's okay to simply forbid military buildings in areas
- I don't understand the 2nd idea right now. Why are there no overlapping areas?
There are 2 solutions: Either store the polygons and check them on each access (which is kinda costly especially for AI that loops over spots to find a good one) or store an array of the map with spots that are allowed/disallowed. This takes more memory but for a 512*512 map it is only 262kb when we use a enabled/disabled approach and is very fast to check. When we use per-building regions then it's gonna be harder... On the other hand: We could then also replace the enable/disablebuilding by this function: Just pass a region spanning the whole map.
Surely the scripter should display a message like "oh no, its a swamp, bad ground, no big buildings there" or something like that.
Ok but why not design the map in a way that it only allows small buildings? This is what I meant with "settlerish": When the building quality shows that you can build a large building you'd better be able to do that ;)
Also this would be a nice feature for an introduction mission where you may only build on certain spots.
Ok I get that. This indeed allows "Build a barack next to the stone to the north" and only allow it there. Might be worth allowing that... Still hesitant but I can check performance implications before abandoning this.
Why are there no overlapping areas?
Ok understood you now. Hmm... Then probably return a ID for the created restriction. Might still be strange to use with things like: DisallowBuilding(bld, wholeMap); AllowBuilding(bld, somePart) as you'd need to lift both restrictions. But short of the strange approach of passing multiple polygons at once (which I'd avoid) I don't see a different solution.
BTW: Keep in mind that designing maps like this is gonna be hard: Currently you can show the restricted area via map debug. When it is per building this becomes unfeasible.
Well, thinking about all this, you are right I guess. It'd be really nice - but we don't need it at all. There might be like 5 use cases for a lot of work and overhead.
So guess, going with no military buildings is fine for now.
While thinking about, just to make sure: Best option is to not make this map based but player based, e.g. one player may pass an area and another not. However to recreate the original mission it'd be enough if this was AI only.
My proposal would then be:
- Use player:Enable/DisableMilitaryBuildingsInArea(area) which adds/removes an area where those are allowed (AI and player)
- Deprecate AddRestrictedArea by printing a warning on usage and using the behavior of the above functions instead by replacing all enabled/disabled areas (due to how restricted area used to work) or maybe remove this function completely. It is complicated to use and the implementation isn't to good either. E.g. when lifting restrictions the area is not recalculated.
Does this meet your request? If not please make a counter proposal :)
Well, for the sake of features one may have, I'd keep the old restrictions - but I agree, that they aren't that usefull in the current state so - yeah, I agree and can't think of any bad side effect. Currently only our scripts use the restricted area, no warning needed IMO, simply drop the function and I replace calls in the current scripts.
So how does one define an area with the new function? By giving bounding points?
Well I'd rather have less features than keeping ones that are hard to use and buggy. Removing it is great for me ;)
Correct: Pass a single polygon and the inner area will be added.