can i ask for some idea about how this game was made?
Fri, 2013-11-22 13:22
i have download the game and source code in windows,
the game run fast and the AI is excellent,only that i can' understand pascal,and how the game source code works.
and i know there won't be any C or C++ version.
so i think maybe i could ask the main algorithm.
something about how the terrain collide with missile
how ai compute how to attack player (avoid terrain or something) and what weapon he should use
The Pascal used is fairly similar to C - I suspect you could understand it if you gave it a shot.
There is a Pascal to C conversion in effect for the HTML5 cross compile, but it makes the code a lot less readable, since the C has no function or operator overloading, or units.
Compare:
http://m8y.org/tmp/uGears.c
and
https://code.google.com/p/hedgewars/source/browse/hedgewars/uGears.pas?r=cffa2c8275e0
https://code.google.com/p/hedgewars/source/browse/hedgewars/GSHandlers.inc?r=cffa2c8275e0
The use of hwFloat math makes the C particularly tough. Especially if there's a fair amount of it, since uFloat uses operator and function overloading quite a lot.
Compare the Pascal:
resetdy:= resetdy + hwPow(resetdy,3)/_6 + _3 * hwPow(resetdy,5) / _40 + _5 * hwPow(resetdy,7) / resety + resetx * hwPow(resetdy,9) / resetdx;
versus the C:
resetdy = ufloat_hwFloat_hwFloat_op_add(ufloat_hwFloat_hwFloat_op_add(ufloat_hwFloat_hwFloat_op_add(ufloat_hwFloat_hwFloat_op_add(resetdy, ufloat_hwFloat_hwFloat_op_div(ufloat_hwPow(resetdy, 3), _6)), ufloat_hwFloat_hwFloat_op_div(ufloat_hwFloat_hwFloat_op_mul(_3, ufloat_hwPow(resetdy, 5)), _40)), ufloat_hwFloat_hwFloat_op_div(ufloat_hwFloat_hwFloat_op_mul(_5, ufloat_hwPow(resetdy, 7)), resety)), ufloat_hwFloat_hwFloat_op_div(ufloat_hwFloat_hwFloat_op_mul(resetx, ufloat_hwPow(resetdy, 9)), resetdx));
But anyway, really, if you know C, the Pascal and C are not that different…
…Pascal
^.
…C
-> (well actually the Pascal ^ and . is a bit more consistent than C -> and . but anyway)
…Pascal
begin/end
…C
{ }
…Pascal
not/and/or
…C
!/&/|
Feel free to drop by IRC (live chat) if there's anything particularly confusing.
On to the questions.
Most missiles check collision here:
https://code.google.com/p/hedgewars/source/browse/hedgewars/uGearsHandlersMess.pas#318
See the "TestCollision" lines which come from:
https://code.google.com/p/hedgewars/source/browse/hedgewars/uCollisions.pas
With regards to AI, consider the bazooka:
https://code.google.com/p/hedgewars/source/browse/hedgewars/uAIAmmoTests.pas#134
It is generating trajectories, then, on impact with something solid, using the rate explosion code:
https://code.google.com/p/hedgewars/source/browse/hedgewars/uAIMisc.pas#477
to work out how many allies and enemies are injured, and weight it accordingly.
--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev
learn some basic pacal and back.
the code
https://code.google.com/p/hedgewars/source/browse/hedgewars/uAIAmmoTests.pas#156
what does it mean
if not (r > 1) then
r is square of the third edge and should be greater than 1,and not means skip this condition until r <= 1?why?guess r is very big,so will it never be less than 1?