• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[discussion] isSightClear development discussion thread

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,864
Solutions
12
Reaction score
1,940
Location
Poland
Hello.

If you regularly browse issues and pull requests of master branch you probably know about problems with isSightClear function (responsible for throwing items and attacks, ranged monster behaviour, and obstacle detection in area spells). Because all three problems are related to each other and there are already lots of PRs and issues referenced, I decided to post here instead of opening yet another one in github repo or causing unnecessary noise in existing PRs/issues.

I believe that all three problems can be fixed by reimplementing the isSightClear function.
I also believe that area spells could be slightly easier to process if we skip already checked tiles (will discuss that later in this post).


Summary of current problems:
1. isSightClear is far from rl (this is huge issue when a pvp fight happens in a narrow diagonal cave)
  • this causes throwing items and distance attacks different (also applies to area spells although the difference isn't big here)
  • this also causes weird positioning of ranged monsters during combat

2. There is some problem with area spells (they can't be cast in some scenarios)
- although I'm not entirely sure what is causing it, one of possible reasons for that might be weird behaviour of isSightClear when the points A and B are next to each other (eg. 1000,1000 and 1000,1001). Places to look at: combat.cpp, methods: Combat::doCombat(the one with caster, position params) and AreaCombat::getList


A quick rundown on the progress in developing the solution:
  • A potential solution for accurate lines of sight in a single floor: using xiaolin wu's algorithm
  • Early implementation with the consideration of throwing items between floors: link to pr
  • Code improvements and further research in Gigastar's PR, more suitable for tfs standards plus some corrections: link to pr
  • Continued research, small fixes and slightly more specific functions in MillhioreBT's PR: link to pr (sorry for abandoning the early code, I lacked time to work on it. I'm glad you all continue working on it though)

Now that the code is close to being finished, I've noticed the area spells performance could be improved in the future as well (image version here):
  • current area spells call isSightClear to every tile (notice the loop above this line)
  • a new function, something like getSightLine could be written to obtain the path between two points
  • an empty matrix could be used to draw obstacles and their shadows (between caster and most remote points) on it
  • a matrix with spell area could be used to compare it with the shadows to figure out available tiles
  • not really sure of it, but I have a feeling that this could even use gpu acceleration for vector operations assuming someone is turbobrain enough to code it
 
OP
zbizu

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,864
Solutions
12
Reaction score
1,940
Location
Poland
current problem of area spells:
  • let's say you cast ue
  • every single tile from spell area calls isSightClear

this means that tiles in exori range for ue spell call tile:hasFlag 4 or more times for a single cast

I've wrote a map generator in the past and one of concepts for it was copying existing fragment of map to use in generated area. The slowest part was accessing the data from the tiles. This is also why I dropped that idea the moment a huge lag hit my testing server.

I propose this solution:
  • scan area once to generate a matrix with obstacles
  • call checks for line of sight locally
  • skip already checked tiles

proof of concept:

edit: "final area" in linked code is the area the spell will avoid
 
Top