Fog/Shroud Radius

Blitz3D Forums/Blitz3D Beginners Area/Fog/Shroud Radius

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I'm using the code below to create Fog of War/Shroud for an rts.

It waits for the friendly unit to actually be in the new grid unit before it shows enemy units.

Is there a way I could use the entities radius to allow visibility to multiple grid units?


;the Psuedo Grid (500,500) is equal to real world 0,0
;VALUES if =0 then invisable area, =1 then visbale
Dim mapgrid(1000,1000)
;This is how large each grid square will be in real XZ world values, play with this to see how it works
Global gridindex=20

;tree type
Type tree
Field entity
Field woodleft
Field Visable
End Type


;all units have these properties
Type Unit
Field Friendly
Field Visable
Field Entity
End Type



Graphics3D 640,480

;create friendly unit
U.unit=New unit
u\friendly=True
u\visable=True
u\entity=CreateCube()
EntityColor u\entity,0,0,200
PositionEntity u\entity,Rand(-20,20),0,Rand(-20,20)

;create a few enemies
For i=1 To 5
U.unit=New unit
u\friendly=False
u\visable=False
u\entity=CreateCube()
EntityColor u\entity,200,0,0
PositionEntity u\entity,Rand(-35,35),0,Rand(-35,35)
Next



;put some ground underneath it all
ground=CreatePlane()
EntityColor ground,0,100,0


For I=1 To 100
t.tree=New tree
T\entity=CreateCone()
PositionEntity t\entity,Rand(-100,100),0,Rand(-100,100)
EntityAlpha t\entity,.2
EntityColor t\entity,0,200,0
ScaleEntity t\entity,4,4,4
Next

;our camera
camera=CreateCamera()
temp=CreatePivot()
PositionEntity camera,10,40,40
PointEntity camera,temp
FreeEntity temp
CameraFogMode camera,1
CameraFogColor camera,100,100,100
CameraFogRange camera,25,190

;main loop
While Not KeyDown(1)
For u.unit=Each unit
checkgridarea(u)
;if unit is friendly we change grid he is in to
;visable, if unit is enemy we just check to see if he is
;inside of a visable area or invisable area, in in visable
;we change his alpha and visable state.
If u\friendly=True Then
MoveEntity u\entity,0,0,.1
TurnEntity u\entity,0,-.35,0
Else
MoveEntity u\entity,0,0,-.1
TurnEntity u\entity,0,.35,0
EndIf
Next
RenderWorld()
UpdateWorld()
Flip
Wend


Function CheckGridArea(cu.unit)
entity=cu\entity
Px=EntityX(entity,1)
Pz=EntityZ(entity,1)
gridX=Int((px/gridindex))+500
gridZ=Int((pz/gridindex))+500
If cu\friendly=True Then
If MapGrid(Gridx,Gridz)=0 Then
mapgrid(gridx,gridz)=1
;tree check not neccessary in a rts game as
;you cn usually see the terrain. You could get
;by with only unit checks. wich are fast.
For t.tree=Each tree
If t\visable=0 Then
If EntityDistance(t\entity,entity)<=GridIndex Then
t\visable=1
EntityAlpha t\entity,1
EndIf
EndIf
Next
EndIf
Else
;enemy/unfriendly unit check.. does not reveal map
;only reveals unit if map area is already explored
If mapgrid(gridx,gridz)=1 Then
cu\visable=1
EntityAlpha cu\entity,1
Else
cu\visable=0
EntityAlpha cu\entity,.1
EndIf
EndIf
End Function