If I’m thinking about it, there is perhaps a method to also solve this without using an AI:
Give us a height property, indicating the height for every tile on the map and also for the shadows on the map. Using that property the engine easily could determine the height of an actor. Only if the shadow is higher than the actor it needs to be applied.
It just needs to be a number value. Zero is the ground and everything greater than zero is located higher than the ground. If an actor e. g. is at height four and the shadow is only at height two it does not need to be applied.