Switching off line of sight for dead units?

Modders can post their questions on scripting and more.

Moderators: Slitherine Core, BA Moderators

pipfromslitherine
Site Admin
Site Admin
Posts: 8977
Joined: Wed Mar 23, 2005 10:35 pm

Re: Switching off line of sight for dead units?

Post by pipfromslitherine » Wed Jun 12, 2013 9:24 pm

You don't need to OPEN any LOS for active units. That will always happen every time the LOS gets updated. You only need to zero out any tiles which you do not still want to be visible.

Cheers

Pip
follow me on Twitter here

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Wed Jun 12, 2013 9:30 pm

Sorry Pip... Forgive my feeble brain... I'm becoming confused...

Your first reply made me think that if I clear the map, then the LOS won't reopen until the player actually moves a unit...
pipfromslitherine wrote: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! :)
But your latest reply makes me think that so long as units remain alive, I don't need to reopen LOS after clearing the map, because it should happen automatically...
pipfromslitherine wrote:You don't need to OPEN any LOS for active units. That will always happen every time the LOS gets updated. You only need to zero out any tiles which you do not still want to be visible.
What am I missing? :oops:
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

pipfromslitherine
Site Admin
Site Admin
Posts: 8977
Joined: Wed Mar 23, 2005 10:35 pm

Re: Switching off line of sight for dead units?

Post by pipfromslitherine » Wed Jun 12, 2013 10:21 pm

Any call the SetTileLOS will force all the units to recalc their LOS - that is the circle around them. Each time you call it actually, which is why it is slow, but you need do nothing.

I would recommend you just try clearing the map to see what happens, esp after moving some units around. It's not especially complex.

Cheers

Pip
follow me on Twitter here

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Wed Jun 12, 2013 10:48 pm

From autodocs...
//set the los of a tile. Values are: 0=hide, 1=show
SetTileLOS(x, y, side, los)

I'd assumed if I set los=0 it would be forced to be hidden, and if I set los=1 it would be shown... But can I leave the los value blank so that it just reverts to default?

I'll try...

Code: Select all

 for(x=16;x<80;x++)
      {
         for(y=16;y<79;y++)
         {
           SetTileLOS(x,y,0,0)
         }
      }
...and see what happens when a unit dies...

Thanks Pip!
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Wed Jun 12, 2013 11:44 pm

Sorry Pip, Still not working...

Wherever I see a DestroyUnit call in CombatTools or MoraleTools, I've inserted the code below to SetTileLOS to 0, to (hopefully) force LOS to reset, as you suggest. But it doesn't appear to do anything...

I can still kill a German unit, and then immediately move into the LOS of that dead unit, and other German units will still fire at me in reaction (even though I shouldn't be seen if the SetTileLOS has worked)...

Is this because the syntax of my SetTileLOS call is incorrect somehow?

Or because BA still considers the 'dead' unit live at the point of the DestroyUnit call, so it hasn't removed LOS from the 'dead' unit yet?

ARGH!! I hate computers, sigh... probably almost as much as you must hate users, lol...

Thanks for all and any thoughts Pip!

Code: Select all

//AddVizFunctionCall("DestroyUnit",unit, killMask) ;
		DestroyUnit(unit, killMask) ;
		AddVizAnim(unit,"DIE", killMask) ;

		// ATTEMPT TO FORCE CLEAR LOS AFTER A UNIT DIES
		int mapx;
		int mapy;

		for(mapx=16;mapx<80;mapx++)
			{
			for(mapy=16;mapy<80;mapy++)
				{
				SetTileLOS(mapx,mapy,0,0);
				SetTileLOS(mapx,mapy,1,0);
				}
			}
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

pipfromslitherine
Site Admin
Site Admin
Posts: 8977
Joined: Wed Mar 23, 2005 10:35 pm

Re: Switching off line of sight for dead units?

Post by pipfromslitherine » Thu Jun 13, 2013 3:26 pm

Are you sure that the units shooting at you cannot still see you? (In debug mode I think you can press, errrmmm, V to see what the AI sees).

You should see a visual change if the LOS is being cleared correctly (that is, the tiles only the dying unit can see would be cleared too).

From my checking, the unit is dead as soon as DestroyUnit is called, so I don't think that is the issue.

It might take some experimentation to get the timing right on this, as it's fairly advanced stuff.

Cheers

Pip
follow me on Twitter here

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Thu Jun 13, 2013 8:31 pm

pipfromslitherine wrote:Are you sure that the units shooting at you cannot still see you? (In debug mode I think you can press, errrmmm, V to see what the AI sees).
I'm pretty sure that enemy units can still see me, but they they shouldn't be able to because they have no other units except the newly killed one nearby. I've entered DEBUGMODE 1 into USER.TXT, but pressing V doesn't seem to change the view in MP games. Am I doing something wrong?
pipfromslitherine wrote:You should see a visual change if the LOS is being cleared correctly (that is, the tiles only the dying unit can see would be cleared too).
There is a visual change when the turn switches from me to my MP opponent, but that is simple loss of LOS from the dead unit, which I suspect would happen anyway when it's my opponent's turn. The problem is enemy LOS, which I assume governs enemy reaction fire during my turn. Actually, maybe I'm overthinking this? Is reaction fire definitely limited to zones where the enemy actually has LOS?
pipfromslitherine wrote:From my checking, the unit is dead as soon as DestroyUnit is called, so I don't think that is the issue.
It might take some experimentation to get the timing right on this, as it's fairly advanced stuff.
If DestroyUnit is definitely linked to killing units, and presumably dead units losing their LOS... maybe it would be smarter to drop my SetTileLOS code inside the DestroyUnit function. Please could you help me to find the DestroyUnit function... Let's give it a try! :D

Code: Select all

		// ATTEMPT TO FORCE CLEAR LOS AFTER A UNIT DIES
		int mapx;
		int mapy;

		for(mapx=16;mapx<80;mapx++)
			{
			for(mapy=16;mapy<80;mapy++)
				{
				SetTileLOS(mapx,mapy,0,0);
				SetTileLOS(mapx,mapy,1,0);
				}
			}
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

pipfromslitherine
Site Admin
Site Admin
Posts: 8977
Joined: Wed Mar 23, 2005 10:35 pm

Re: Switching off line of sight for dead units?

Post by pipfromslitherine » Thu Jun 13, 2013 8:41 pm

The V key doesn't work in MP. Most debug keys that could be used for cheating are disabled in MP.

I'm getting confused. When your unit dies, how would that affect the enemy LOS? The only logic would be that when YOUR unit dies, YOU stop being able to see enemy units near it.

DestroyUnit is an intrinsic function in code. Your hooks (assuming they are being called, which I assume you have checked with Log() calls) are in the correct place for this.

Cheers

Pip
follow me on Twitter here

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Thu Jun 13, 2013 8:59 pm

Thanks Pip, Sorry for confusing... Let me try to explain again... :D

Simplistically, here's the challenge. By default, BA sets LOS for all units at the beginning of each turn. So, if I kill an enemy unit during MY turn, that enemy unit will continue to pass back full LOS of any movements that I make around the position where that enemy unit died. Using that 'dead unit LOS', the enemy team will fire in reaction at all of my movements in that area.

It would seem smarter that if I can kill an enemy unit, then the enemy team should be immediately deprived of LOS from the dead unit.

So, what I'm trying to do is wholly related to removing LOS from dead enemy units, to prevent reaction fire that is being spotted only by dead enemy units...

Hope that makes more sense? :?
Last edited by GottaLove88s on Thu Jun 13, 2013 10:08 pm, edited 2 times in total.
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Thu Jun 13, 2013 9:05 pm

Err... sorry, I don't know what a 'hook' is...

I'm still wearing 'L' plates for code, so my simplistic solution has been to add the code below (which I assume would clear LOS from newly dead units, but reset LOS for live units) immediately after all of the DestroyUnit calls in CombatTools and MoraleTools...

Code: Select all

		// ATTEMPT TO FORCE CLEAR LOS AFTER A UNIT DIES
		int mapx;
		int mapy;

		for(mapx=16;mapx<80;mapx++)
			{
			for(mapy=16;mapy<80;mapy++)
				{
				SetTileLOS(mapx,mapy,0,0);
				SetTileLOS(mapx,mapy,1,0);
				}
			}
I'm assuming that all cases of units dying should be covered by those DestroyUnit calls...

But I may be oversimplifying??? :oops:
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

pipfromslitherine
Site Admin
Site Admin
Posts: 8977
Joined: Wed Mar 23, 2005 10:35 pm

Re: Switching off line of sight for dead units?

Post by pipfromslitherine » Thu Jun 13, 2013 11:32 pm

The best place to put your code (as I think I said earlier) is probably in the KILL_CALLBACK function in callbacks.bsf, but you should put a Log call in your code to make sure it is actually being called.

I'm not sure this is the best thing to graduate from your Learners permit on, given that I can't even immediately see how to do it :) But if you continue then be sure to add lots of debug Log calls so you can make sure things are actually happening as you expect.

Cheers

Pip
follow me on Twitter here

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Fri Jun 14, 2013 7:19 am

Thanks Pip, Yes, you mentioned reaction callbacks, but it's good of you to suggest KILL_CALLBACK directly... I've just taken a look... It appears to be a function that checks if a dying unit is a transport and then unloads transports immediately before they die... so it's a wise place to drop in code to clear LOS... I will try it out tonight (yes, with Log calls, that tell me that it's happening :D )

Unless I'm completely misunderstanding that (i) SetTileLOS forces a LOS recalc for a tile, (ii) dead units are assigned LOS=0 on death (although this is not updated to the battle map until the next turn begins), then it feels like a simple project just to drop in a loop in to force the map to recalc earlier.

The only hard part seems to be figuring out where to drop the LOS recalc so that (i) it always happens when any unit dies, and (ii) it only happens after the dying unit has been marked as dead (so that it's 'deadness' will actually affect the default LOS calculations of SetTileLOS). MoraleTools and CombatTools didn't work, so, fingers crossed, Kill_Callback will be a better place.

But to be 100% sure that I'm understanding your comments on SetTileLOS, SetTileLOS (x, y, side, LOS of 0 or 1) doesn't actually set that tile's LOS to the specified 0 or 1? It only forces BA to recalculate whether it should be 0 or 1 based on the live/dead objects on the map? So whether I put 0 or 1 in the actual call doesn't matter... I just want to be certain that I'm using the critical function correctly, because that seems to be what you're saying...

Thanks Pip! That helps heaps.
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

pipfromslitherine
Site Admin
Site Admin
Posts: 8977
Joined: Wed Mar 23, 2005 10:35 pm

Re: Switching off line of sight for dead units?

Post by pipfromslitherine » Fri Jun 14, 2013 1:23 pm

No. SetTileLOS actually sets the tile LOS value for that side. The recalc is a side effect.

Cheers

Pip
follow me on Twitter here

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Fri Jun 14, 2013 1:46 pm

Doh!, sorry Pip, my turn to be confused...

So... SetTileLOS does indeed set the LOS for a defined x, y square and team side.

But if recalc is a side effect, which squares does it affect? Neighbouring squares? Or the whole map?

If I SetTileLOS for a single square, maybe one off map, like 15, 15, will the rest of the map recalc as a side effect? That would be perfect...
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

pipfromslitherine
Site Admin
Site Admin
Posts: 8977
Joined: Wed Mar 23, 2005 10:35 pm

Re: Switching off line of sight for dead units?

Post by pipfromslitherine » Fri Jun 14, 2013 3:00 pm

It does a recalc of the whole map.

Cheers

Pip
follow me on Twitter here

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Fri Jun 14, 2013 5:06 pm

Awesome! So I don't need any of the 'for mapx', 'for mapy' nonsense...?
I just need to make a SetTileLOS call, in Kill_Callback, for a single square off map, say 15,15...
And the rest of the map will autorecalc...
Heading home to try it out!
THANKS PIP :D
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

pipfromslitherine
Site Admin
Site Admin
Posts: 8977
Joined: Wed Mar 23, 2005 10:35 pm

Re: Switching off line of sight for dead units?

Post by pipfromslitherine » Fri Jun 14, 2013 5:27 pm

No. The tile data (e.g. whether a tile is visible to a side) doesn't change when the recalc is done. Only the visible shroud, and all units add in any new tiles they can see. You need to reset a tile specifically if you want to (e.g.) stop it being visible to a side.

That is: on a recalc all units work out what tiles they can or cannot see, but any already visible tiles are not touched.

Cheers

Pip
follow me on Twitter here

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Fri Jun 14, 2013 6:00 pm

Thanks again Pip,

That makes sense, I think.

So I should use the SetTileLOS call to zero anything that I don't want players to see (or everything for simplicity) and the automatic recalc will override that and make visible anything that either players' units should actually be able to see...

Phew! :D

PS. Presumably each StartNewTurn must do approximately the same... zeroing everything... and then making a SetTileLOS (or equivalent) call to put genuine LOS back again...
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

pipfromslitherine
Site Admin
Site Admin
Posts: 8977
Joined: Wed Mar 23, 2005 10:35 pm

Re: Switching off line of sight for dead units?

Post by pipfromslitherine » Fri Jun 14, 2013 7:57 pm

Correct, that is essentially what happens at the start of a new turn.

Cheers

Pip
follow me on Twitter here

GottaLove88s
Lieutenant-General - Do 217E
Lieutenant-General - Do 217E
Posts: 3151
Joined: Fri Apr 06, 2012 6:18 pm
Location: Palau

Re: Switching off line of sight for dead units?

Post by GottaLove88s » Fri Jun 14, 2013 9:31 pm

THANK YOU PIP!!

Problem solved... I gave up trying to achieve this via tying into a death notification... and just added it to MOVE.BSF instead...

I figured that the concept was to prevent dead enemy units reporting movements... so, if I cleared and recalculated LOS when moving... dead units can't see any more...

Voila, no more reaction fire directed by dead units... Way cool... I love it!
SCENARIO LINKS
Seelow'45 -> www.slitherine.com/forum/viewtopic.php?f=313&t=55132
Normandy'44 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42094
Dieppe'42 -> www.slitherine.com/forum/viewtopic.php?f=87&t=42347

Post Reply

Return to “Battle Academy : Modders Corner ”