Page 1 of 3

Switching off line of sight for dead units?

Posted: Sun Jun 09, 2013 7:20 pm
by GottaLove88s
Gents,

One of the things that's always struck me as odd (aka infuriating! lol) is that killed enemy units continue to provide line of sight (LOS) during the turn that they die.

For example, if I kill an enemy scout, but then sneak up other units after I have killed that scout, distant enemy tanks can still 'see' my sneaking infantry (by using the dead scout's LOS) and will fire in reaction from long range... often killing or at least suppressing what should rationally be a hidden movement... defeating any quick advantage that might be gained by killing the scout...

I'd like to add a mod to immediately switch off LOS from dead units...
So 3 questions please:

1. Where is the code that resets and sets enemy LOS before each turn?
2. Where is the code that tests and records when an enemy unit is killed?
3. Is there a way to reset enemy LOS immediately after each enemy unit is killed, rather than at the end of the turn, so that dead units cannot offer 'ghostly LOS' (from Heaven, one assumes)?

Then reaction fire would have to be based on live units at all times...

Thanks for all and any ideas...

:-)

Re: Switching off line of sight for dead units?

Posted: Mon Jun 10, 2013 2:57 pm
by pipfromslitherine
The key issue would be that the LOS you had opened up during the turn with all units would be lost. That is - you would reset to just the visible tiles for the current unit positions. Keeping the LOS for a dead unit is the same as keeping opened LOS tiles as you move. :)

Cheers

Pip

Re: Switching off line of sight for dead units?

Posted: Tue Jun 11, 2013 12:06 am
by GottaLove88s
Thanks Pip,

Actually I reckon I could live with that... so each turn would only show what units should be able to 'see' from their current positions... ie. when a player moves a unit, he loses the LOS from that unit's previous position...

If I understand correctly, to mod that I would have to make a change that resets LOS...
i) after each unit moves, and
ii) after any unit dies...

Would that restrain LOS to what all live units should be able to see 'at that instant' ?

Re: Switching off line of sight for dead units?

Posted: Tue Jun 11, 2013 3:10 pm
by pipfromslitherine
I don't think that is possible currently, unless you go across the entire map each tick setting the LOS to 0 and then forcing a recalc of all the LOS, and that would slow the game to a crawl.

Cheers

Pip

Re: Switching off line of sight for dead units?

Posted: Tue Jun 11, 2013 6:25 pm
by GottaLove88s
Instead of updating per tick...

I was thinking of updating LOS with either...
i) movement, or
ii) destroyunit calls

So LOS would only update when something moves or dies.

Should keep LOS to what is realistic, without slowing things down.

Workable?

Re: Switching off line of sight for dead units?

Posted: Tue Jun 11, 2013 6:48 pm
by Ranger
GottaLove88s wrote:Thanks Pip,

Actually I reckon I could live with that... so each turn would only show what units should be able to 'see' from their current positions... ie. when a player moves a unit, he loses the LOS from that unit's previous position...

If I understand correctly, to mod that I would have to make a change that resets LOS...
i) after each unit moves, and
ii) after any unit dies...

Would that restrain LOS to what all live units should be able to see 'at that instant' ?
I agree with GottaLove88s... actually I think this preferable to the way LOS etc currently works in BA.

IMHO, and if BA is capable, LOS and field of view, should be limited to the specific unit and not "shared", it should be positionally dependent lost as a unit moves, and/or lost after a unit is destroyed, and/or lost when a unit is suppressed.

When a unit becomes suppressed, that unit's LOS/field of vision should be temporarily lost for the remainder of the turn. LOS/Field of view for suppressed units would be regained at the beginning of the same players next turn, and/or sooner, if morale is returned to 50+.

BA gets so many things right but one thing it doesn't do very well is the concept of "suppression". In reality, not only can a suppressed unit not return fire or engage enemy targets, it's view of the enemy action/position is lost/impaired. It's situational awareness, of the enemy position, location, type, strength, and/or action, is momentarily impaired and or lost for the duration that it is suppressed. Since "time" is turn-based in BA, the duration of suppression would be the remainder of the turn.
(units that continue to have a morale below 50, in subsequant turns, would probably be more accurately described as "nuetralized" because they have been rendered ineffective for the duration etc, but that's an entirely different discussion altogether. My apologies for going off on a tangent.)

Cheers,

Thomas

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 12:23 am
by GottaLove88s
pipfromslitherine wrote:I don't think that is possible currently, unless you go across the entire map each tick setting the LOS to 0 and then forcing a recalc of all the LOS, and that would slow the game to a crawl.

Cheers

Pip
Pip, Where does BA force the recalc for LOS at the start of each turn? Thanks!
(Does the BA game engine automatically redraw the map based on current LOS data? Or do I have to instruct a re-draw somehow?)

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 3:25 pm
by pipfromslitherine
It's part of the main code flow I'm afraid. So I don't think you're going to be able to do such a fundamental change to the mechanics.

The engine redraws based on the current LOS each time, yes. There is no need to 'redraw' anything.

Cheers

Pip

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 3:50 pm
by GottaLove88s
pipfromslitherine wrote:The engine redraws based on the current LOS each time, yes. There is no need to 'redraw' anything.
Thanks Pip,

Forgive the foolish questions. I'm just trying to get my head around exactly what's happening in your code.
Thanks for clarifying that BA's engine 'redraws' the battle map based on current LOS...

The part that I'm missing is how often does the engine do this?
Does it only 'redraw' once per turn? Or are there certain actions or events that trigger a 'redraw' before, during or after a player's turn?

For example, if I update LOS for certain units, would that trigger an automatic update in the battle map? A 'redraw' if you like.
Or does that 'redraw' only happen at the beginning of each turn?

Let me know if that doesn't make sense and I'll try to re-explain... :oops:

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 3:53 pm
by GottaLove88s
pipfromslitherine wrote:It's part of the main code flow I'm afraid.
What I've realised with BA is that you've created such an awesome game engine, there's usually a way to create some new effect, if one experiments hard enough...

Please could you point out the part of the main code that executes the battle map 'redraw'?

Maybe the easiest solution is for me to simply execute a redraw each time that a unit dies...?

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 5:26 pm
by GottaLove88s
Hmmm... Ok, I've tried the obvious... setting LOS to zero, immediately prior to DestroyUnit calls in MoraleTools.bsf and CombatTools.bsf... and this does not affect the enemy team's ability to see... Dead units still provide line of sight...

So 'redraw' definitely isn't continuous... There must be some specific event that triggers a battle map redraw?

Code: Select all

						SetAttrib(me, "LOS", 0) ;
						SetAttrib(me, "CoverLOS", 0) ;
						DestroyUnit( me, 255) ;

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 5:33 pm
by pipfromslitherine
You're misunderstanding. Most of this happens inside the game EXE code, not in script. Currently the LOS is reset when you start a new turn, this is done in code not in the scripts.

The only way to do what you are suggesting is to clear the LOS each tick or movement. The only way I can see currently to do this in a reasonable way would be to hook unto a reaction script and do the clear there (as a call to build reactions happens whenever a new move occurs etc). If you did some logic to only do it once (e.g. by storing the last unit and tile that you got the call on perhaps) then it might not cause any performance issues. You can force an "update" using SetUnitForReaction, although then you would end up shooting at it (unless you had some other universal var to set and tell the reaction hack not to actually return a real score for any unit).

As you can tell, this is pretty involved and hacky stuff, but it might be possible with some script-fu. But the engine isn't really designed to do what you are looking to achieve. :)

Cheers

Pip

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 5:59 pm
by GottaLove88s
Thanks again Pip... Aha, ok, I see what you mean. The LOS redraw is in EXE code, not moddable script... Darn it!!

To be honest, having an LOS update on movement is only a nice to have...

But immediate removal of LOS from dead units is something I really want to figure out...
I'm hoping that might make any calculations/code simpler because I should only need to remove LOS from a single defined unit.

To be 100% sure I understand you, are you suggesting that if I SetUnitForReaction for a killed unit, it will clear that unit's contribution to that side's LOS?
I really appreciate your help on this...

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 6:11 pm
by pipfromslitherine
No. Nothing you can call or do simply will remove LOS from the map. You would need to hook something into (e.g.) a reaction callback to clear LOS. Perhaps (e.g.) clearing the LOS around the unit that is being reacted too might work.

Cheers

Pip

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 6:35 pm
by GottaLove88s
Hmmm... Big headache in my Neanderthal brain, lol...

Ok...
1. There's no way to remove LOS from a dead unit, right?
2. There's no way (from script) to clear and simply redraw LOS for all of the live units on the battle map?

But...
It might be possible to manually clear LOS surrounding a (dead or live?) unit... and subsequently call a SetUnitForReaction for that (dead or live?) unit to correctly update the LOS for what that unit can actually see...

Am I still wildly off the mark?

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 7:26 pm
by pipfromslitherine
We do seem to be wandering around somewhat, so I will try and answer the various levels of things that have been talked about.

1 - clearing around dead units. Yes. Can be done. Simplest way would be to hook into KILL_CALLBACK (in Callbacks.bsf) and use SetLOS to zero out the LOS around him. This has the problem that it is inconsistent (e.g. tiles opened up by other units would then still be zeroed). NOTE: calls to SetLOS cause all units' "current" LOS to be recalculated.

2 - calling SetLOS across the entire map would automatically cause all living units to recalc their LOS, removing any "opened up" tiles. Working out how to do this to most efficiently is tricky though - you could try attaching it to a reaction callback.

Don't worry about SetUnitForReaction - I have had it pointed out that SetLOS causes the recalc of LOS and so that is a better fn to use.

Cheers

Pip

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 8:13 pm
by GottaLove88s
pipfromslitherine wrote:2 - calling SetLOS across the entire map would automatically cause all living units to recalc their LOS, removing any "opened up" tiles. Working out how to do this to most efficiently is tricky though - you could try attaching it to a reaction callback.

Don't worry about SetUnitForReaction - I have had it pointed out that SetLOS causes the recalc of LOS and so that is a better fn to use.
YAY!! That's wonderful news.

One final question please... What's the format for SetLOS? I can't find it in the autodocs...

I'm guessing if I run SetLOS for the whole map, once only each time that a unit dies, it will clear and reload LOS so dead units can't see anymore.

PS. Thanks Pip. You're awesome...

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 8:25 pm
by pipfromslitherine
The command is actually SetTileLOS, which is in the autodocs. I was shorthanding it.

Clearing the whole map will look very odd, as units will wander around, opening up the map as they move, only to have all those tiles vanish when someone on the other side of the map dies. But that is your call! :)

Cheers

Pip

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 8:43 pm
by GottaLove88s
Got it!

SetTileLOS(x, y, side, los)

So, an approach might be...

1. Check the side of the unit that died... Is there a function for returning the side of a given unit?
2. SetTileLOS to 0 for the whole map for that side... X 16->79, Y 16->79
3. Count up through all of the units for that side and reopen the LOS for each, one by one... SetTileLOS back to 1 using a formula that relates to squads.csv LOS data

It sounds painful, but I suspect it could be processed quickly... and if it only executes when a unit dies, hopefully won't interfere too much...

Does that feel workable?

Re: Switching off line of sight for dead units?

Posted: Wed Jun 12, 2013 8:55 pm
by GottaLove88s
For reopening LOS, I could work through the affected side using something like...

side=GetUnitSide(unit)
for(i=0;i<GetUnitCount(side);i++) // work through all of the units on that side

id = GetUnitID(side,i) ;
if (IsUnitValid(id)==1) // only open LOS for live units
{
los = GetBaseAttrib(id, "LOS");
x = GetUnitX(id)
y = GetUnitY(id)

Now I just need to create a clever formula to reproduce the round LOS shape that you guys use...
There muuust be a mathematical trick to quickly recreate eg. 3 square LOS, as below...
Are there any clever mathematicians out there...?
:D

0 0 1 1 1 0 0
0 1 1 1 1 1 0
1 1 1 1 1 1 1
1 1 1 X 1 1 1
1 1 1 1 1 1 1
0 1 1 1 1 1 0
0 0 1 1 1 0 0