Skip to content
This repository has been archived by the owner on Apr 17, 2022. It is now read-only.

Unhardcode oil drums #4143

Closed
wzdev-ci opened this issue Dec 15, 2013 · 21 comments
Closed

Unhardcode oil drums #4143

wzdev-ci opened this issue Dec 15, 2013 · 21 comments

Comments

@wzdev-ci
Copy link
Contributor

resolution_fixed type_patch (an actual patch, not a request for one) | by NoQ


Could anybody ... review that?

I recently got really fed up with hardcoded oil drum placement when i tried to make another tower defence map and wanted fine control over how much power the human player has after each wave (>_<)

So i made this patch to move oil drums code to rules.js.

I didn't bother understanding the confusing original drum placement algorithm, so it is made slightly differently. Number of initially placed oil drums is now proportional to map area, one drum per 64x64 tiles, with at least one to be placed regardless (originally it was proportional to number of players). Oil drums are now respawned in 10 minutes after they are picked up. Oil drums are always placed in locations reachable from at least one starting position, otherwise uniformly spread around the map.

One of the recent (and quite flooded up) forum discussion on this topic is here: http://forums.wz2100.net/viewtopic.php?f=30&t=10410

It seems that we no longer need moveInitialize(). Remove it or keep for future use?

And the thing that troubles me the most is sync-unsafe javascript division. It is known that there is no such thing as integer in javascript. So when i divide map area by 4096, i might get a platform-specific double. I worked around by using right shift instead of division, but maybe it's worth it to add special javascript functions for division - something like syncDiv(a,b) and syncMod(a,b) that would simply do these operations on the C++ side?


Issue migrated from trac:4143 at 2022-04-16 11:39:26 -0700

@wzdev-ci
Copy link
Contributor Author

NoQ uploaded file 0001-Move-random-oil-drum-placement-to-rules-js.patch (7.3 KiB)

@wzdev-ci
Copy link
Contributor Author

Per changed blocking which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

Per changed blockedby which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

Per commented


I really like the idea of moving drum placement into scripts.

Perhaps add a check that drums are never placed inside any player's starting base?

(And maybe oil drums should always spawn near an oil resource? Just an idea that popped out of my head.)

Please add a comment to large numbers like 600000 saying what it means in reasonable units like minutes. They are hard to parse for humans otherwise :)

No need to keep unnecessary code.

Might be a good idea to add syncDiv() and syncMod().

@wzdev-ci
Copy link
Contributor Author

NoQ changed _comment0 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

NoQ commented


600000
Hmm. As homework, I'd try to implement exponential distribution for this value. Otherwise people would remember to look for drums every 10 minutes.

P.S. why do we respawn them at all? That's hardly realistic. The "near oils" idea looks curious though.

Perhaps add a check that drums are never placed inside any player's starting base?

Can do, by increasing radius in enumRange() call. Or maybe add a special check ...

@wzdev-ci
Copy link
Contributor Author

NoQ commented


Or rather geometric distribution.

// generate Geom(1/6) distribution for oil drum respawn delay
for (delay = 0;; ++delay)
{
	if (syncRandom(6) == 0)
	{
		break;
	}
}
// amounts to 10 minutes average respawn time
queue("placeOilDrum", delay * 120000);

Then for the real trouble: propulsionCanReach() aka fpathCheck() sometimes fails. Steps to reproduce: start a game on Sk-Highground and execute propulsionCanReach("wheeled01", 18, 31, 11, 31) in jsdebug. It prints true, which is wrong because (11, 31) is a cliff tile.

@wzdev-ci
Copy link
Contributor Author

vexed commented


The only reason we respawn them is, it was like that since day 1, with the change being that VTOL's can't pick them up like they did before (I think--I don't recall exactly)

Not sure I follow the reason to move it to JS, I guess it could be just as easy to turn on / off this feature via a script command, then you can place whatever feature you want where ever you want.

As you have noticed, we still have lots of issues with the pathing code and associated routines.

@wzdev-ci
Copy link
Contributor Author

NoQ commented


A JS function for disabling (or enabling) drum spawning is enough of course, it just simply looks ugly, and it won't solve it when somebody would anyway want to make a custom respawn method.

I am still to figure out what really needs to be done to fpathCheck(). Maybe just add a JS function to get tile type of tiles (such as ground/water/cliff/road/whatever)? This ticket is a good example of a lightweight use case for such function.

@wzdev-ci
Copy link
Contributor Author

NoQ commented


Well, i guess i really shouldn't touch fpathCheck(); it just checks for something different from what i expected.

So i think i'd add a function to check terrain type. I add JS constants for only TER_WATER and TER_CLIFFFACE and say that everything else is ground; this is enough for simple stuff, and this way we can later extend API to either allow distinguishing between sand and road, or disallow it if we eventually deprecate speed differences between them.

Attaching a working version with two patches:

0001-qtscript-Add-terrainType-x-y-to-check-passability-of.patch
0002-Move-random-oil-drum-placement-to-rules.js.patch

@wzdev-ci
Copy link
Contributor Author

NoQ uploaded file 0001-qtscript-Add-terrainType-x-y-to-check-passability-of.patch (2.8 KiB)

@wzdev-ci
Copy link
Contributor Author

NoQ uploaded file 0002-Move-random-oil-drum-placement-to-rules-js.patch (7.7 KiB)

second version, requires qtscript patch

@wzdev-ci
Copy link
Contributor Author

Per commented


Looks good to me.

@wzdev-ci
Copy link
Contributor Author

NoQ changed status from new to closed

@wzdev-ci
Copy link
Contributor Author

NoQ changed resolution from `` to fixed

@wzdev-ci
Copy link
Contributor Author

NoQ commented


Pushed :)

@wzdev-ci
Copy link
Contributor Author

vexed commented


in d289598813fbf1f865faebdd79de6492c1967262

(use closes/fixes #4143 in commit message...) Makes book keeping easier :)

BTW, moving this to JS also opens the door to more abuse.

@wzdev-ci
Copy link
Contributor Author

Per commented


I don't think this allows for abuse. If anyone changes the algorithm, then this will create a desync.

@wzdev-ci
Copy link
Contributor Author

NoQ commented


Even without unhardcoding, a cheater could implement his own oil drum spawner in rules.js, along with the hardcoded oil drum spawner.

@wzdev-ci
Copy link
Contributor Author

vexed commented


See forum thread for more about this.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Dec 28, 2013

crab_ commented


Replying to Warzone2100/old-trac-import#4143 (comment:12):

See forum thread for more about this.

Please can you give me link to that forum thread.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant