Author Topic: Guidelines on vision and projectiles  (Read 3307 times)

Offline navyseal

  • Squaddie
  • *
  • Posts: 2
    • View Profile
Guidelines on vision and projectiles
« on: May 09, 2017, 05:53:11 pm »
Greetings everyone,
I'm working in a personal project of mine which is a xcom based game.
Xcom is the game of my life and i play it until today, so i decided i wanted to create my own "XCOM"

So now im working on vision of the player, im searching the code on git and it would really help me out if you guys could give me some hints on how to simulate the xcom player vision. At start i was using a sort of "flashlight" to see whats visible and whats not, but i want to copy the xcom vision cause i find it more interesting. Any tips you could give me on how to decide whats visible and whats not?

Im planning on using vectors based on the character and facing the direction the character is facing. But i think once the height is added to the equation things might get a bit more complex than that. Plus there are the question of the flares lightining regions.

What about the projectiles and the hits on the walls is there any good algorithm to track that? Do you do the calculations over a grid in a matrix or is it more simple than that? Right now my shot is directly the colisions only exist in monsters.

Sorry for the questions but it would really help me if someone could explain a bit of the algorithm.

Finally i leave an old video of the game im working on if you are curious to check it out and yes, I did use some of xenonauts content while i was working on it, but the game took another road and there wont be a base anymore.

--EDIT--
I did found a useful png explaining some of the stuff, can you please confirm if this is how things are usually done?
https://i.imgur.com/eqnBg.gif
« Last Edit: May 09, 2017, 09:07:07 pm by navyseal »

Offline Stoddard

  • Colonel
  • ****
  • Posts: 485
  • in a fey mood
    • View Profile
    • Linux builds & stuff
Re: Guidelines on vision and projectiles
« Reply #1 on: May 09, 2017, 07:25:07 pm »
How the map is represented? I mean, data structures.

Without that your questions are too broad to answer.

Offline navyseal

  • Squaddie
  • *
  • Posts: 2
    • View Profile
Re: Guidelines on vision and projectiles
« Reply #2 on: May 09, 2017, 09:25:45 pm »
I'm using c#

My structure is a List<List<Tile>>  where a tile can have a child tile  which then can be stacked.

I know i should be structuring this in some other way but it was done long time ago... and it seemed simple enough
« Last Edit: May 09, 2017, 09:28:14 pm by navyseal »

Offline Stoddard

  • Colonel
  • ****
  • Posts: 485
  • in a fey mood
    • View Profile
    • Linux builds & stuff
Re: Guidelines on vision and projectiles
« Reply #3 on: May 09, 2017, 10:20:57 pm »
My structure is a List<List<Tile>>  where a tile can have a child tile  which then can be stacked.

Stacked as in z-levels? So it's more like List<List<Tile { ... List<Tile> }> ?

At the end of the day to emulate xcom vision you have to somehow:

  • assign 'transparency' to the tiles. in xcom it's just a boolean - can one see through?
  • write a crude raytracer that'll do
    • for any tile in the cone of vision,
    • the ray from the unit to the tile doesn't hit any non-transparent tiles
Xcom also has more fine-grained representation for line-of-fire checks, where each tile is represented as a 12x12x16 (IIRC) voxel set.

But the principle is the same - build a trajectory (ray for projectiles, parabola for thrown), check if it hits a opaque tile/solid voxel starting from the start, that's your limit of vision, or what you would hit. For the visibility check, mark tiles passed before that as visible.

Write an interface for querying a tile at arbitrary coordinates.

The actual algorithm - it can be anything, look up what people came up in raytracing after all this time, when the simplest approach of just doing an exhaustive search over all the tiles that are nearer than the visibility limit for every unit proves too slow.

IIRC, openxcom just does the exhaustive searches limited by the vision cone.





Offline Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: Guidelines on vision and projectiles
« Reply #4 on: May 10, 2017, 12:03:47 am »
I'm using c#

My structure is a List<List<Tile>>  where a tile can have a child tile  which then can be stacked.

I know i should be structuring this in some other way but it was done long time ago... and it seemed simple enough
I would suggest using single list (good thing that list in C# is equivalent to vector from C++, but best would be plain array), slowest operation on any modern computers is memory load from ram, I could even suggesting using Tile as struct but its error prone in C#.