Ask a simple question, get a simple answer
- Eleven Warrior
- Posts: 752
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: Ask a simple question, get a simple answer
Found the potion Thanks
Re: Ask a simple question, get a simple answer
Is there any way to check how much the party object or tile underneath it is lit?
i.e. is it in the shade or in the sun?
I understand that there are dynamic shadows under the open sky during the day and it is difficult to implement. But i want to neglect this. Just having day and night. I want to find a way (maybe someone already has it) how to determine the degree of light in the dungeon? Let's say there is a monster. I can getSight its component brain then depending on getAllAroundSight() check if it is looking towards the party. And this functionality I want to extend. We can always check seesParty, so I want to reduce the Sight of all monsters in the level depending on the lighting of the party.
What I'm envisioning. I need to get all the light components in the level, and then depending on getType() check getDirection(), getRange() and maybe getSpotAngle(), getSpotSharpness(). I have no idea what the last two do.
But I hope that all this is needed and can be done in a simpler way. After all, the game somehow understands what part of the texture is illuminated.
i.e. is it in the shade or in the sun?
I understand that there are dynamic shadows under the open sky during the day and it is difficult to implement. But i want to neglect this. Just having day and night. I want to find a way (maybe someone already has it) how to determine the degree of light in the dungeon? Let's say there is a monster. I can getSight its component brain then depending on getAllAroundSight() check if it is looking towards the party. And this functionality I want to extend. We can always check seesParty, so I want to reduce the Sight of all monsters in the level depending on the lighting of the party.
What I'm envisioning. I need to get all the light components in the level, and then depending on getType() check getDirection(), getRange() and maybe getSpotAngle(), getSpotSharpness(). I have no idea what the last two do.
But I hope that all this is needed and can be done in a simpler way. After all, the game somehow understands what part of the texture is illuminated.
Test version of my Generations of Kings mod
https://drive.google.com/file/d/1DOTiuP ... drive_link
https://drive.google.com/file/d/1DOTiuP ... drive_link
- Eleven Warrior
- Posts: 752
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: Ask a simple question, get a simple answer
How do I stop the player from taking torches from the torch holder?
PS: I found it sorry.
PS: I found it sorry.
Re: Ask a simple question, get a simple answer
This is not a simple question. It is probably the most complicated question that has ever been asked in Grimrock modding. But I guess I might as well answer it here anyway.Slava wrote: ↑Tue Dec 17, 2024 11:59 am Is there any way to check how much the party object or tile underneath it is lit?
i.e. is it in the shade or in the sun?
I understand that there are dynamic shadows under the open sky during the day and it is difficult to implement. But i want to neglect this. Just having day and night. I want to find a way (maybe someone already has it) how to determine the degree of light in the dungeon? Let's say there is a monster. I can getSight its component brain then depending on getAllAroundSight() check if it is looking towards the party. And this functionality I want to extend. We can always check seesParty, so I want to reduce the Sight of all monsters in the level depending on the lighting of the party.
What I'm envisioning. I need to get all the light components in the level, and then depending on getType() check getDirection(), getRange() and maybe getSpotAngle(), getSpotSharpness(). I have no idea what the last two do.
But I hope that all this is needed and can be done in a simpler way. After all, the game somehow understands what part of the texture is illuminated.
You basically have two real options here, both of which are completely horrible. One is to use a umod (or equivalent) to execute native code that does additional render passes to get the lighting information you need (see here for an example of such an approach). Adding native code is necessary because there's nothing in Grimrock's Lua functions to copy the contents of render buffers or textures into main memory, nor to receive information from shaders. You will need to write 6 slightly different versions of a lot of this code (one each for D3D9 notebook renderer, D3D9 normal renderer, Windows OpenGL notebook, Windows OpenGL, Mac OpenGL notebook, Mac OpenGL).
The other option, which is worse in every way except portability, is to use the CPU to calculate how much light the party would theoretically receive. While this is easy in the notebook renderer, it's almost hopeless in normal rendering modes since those have shadows and you can't even access the shadow maps. You'll basically need to go through every shadow-casting model in your dungeon that's of significant size and choose a shape that approximates it and can be checked for collision with a ray very cheaply. Then, on any frame where you need this lighting information, cast a ray to the party from every light within range, checking for collision with all of those shapes in range. Oh, and you'll need to apply node transforms to the shapes for any animated models - you seem to want to include monsters in your dungeon, which are usually large, shadow-casting, and animated.
Other options that people may propose, which I do not consider real options:
3. designing your dungeon's levels, spells, monsters, etc. in such a way that whenever this lighting value would matter, it's just trivial to determine and can be baked into the tiles or whatever.
4. have your code just guess how much lighting the party is in and regularly get it completely wrong
I don't think these are real options because the only reason you'd consider adding this mechanic in the first place is that you want to actually do something with it, with moving light sources and shadows (rules out 3.) and the lighting value actually mattering to the player (rules out 4.)
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Ask a simple question, get a simple answer
In that case, thank you very much for your reply Minmay!It is probably the most complicated question that has ever been asked in Grimrock modding.
Unfortunately I don't have access to steam (don't want to) and don't have access to umod. I have seen the source code though, and a way to modify it without using umod. The whole thing really seems horrible to me. Despite being a bit of a programmer, I'm not a game developer. I have no idea how to implement this.One is to use a umod
I haven't found anything that allows raytracing to be used in a game or mod. Even if this functionality is there, I don't see a way to control it other than again climbing into the source code of the game.cast a ray to the party
I was also thinking about the third option. It seems more realistic to me. There is no problem to design a dungeon so that then manually set the light level. I see it the same way we draw a map of heights, noise and reflections.3. designing your dungeon's levels, spells, monsters, etc.
That's something I already agree with.4. have your code just guess how much lighting the party is in and regularly get it completely wrong
My goal is to add stels mechanics everywhere, not just where it may have been planned and programmed. I think that would be interesting for players.I don't think these are real options because the only reason you'd consider adding this mechanic in the first place is that you want to actually do something with it, with moving light sources and shadows (rules out 3.) and the lighting value actually mattering to the player (rules out 4.)
Anyway. I'll give it some thought. You've clarified the issue for me. Thanks again!
Test version of my Generations of Kings mod
https://drive.google.com/file/d/1DOTiuP ... drive_link
https://drive.google.com/file/d/1DOTiuP ... drive_link
Re: Ask a simple question, get a simple answer
I'm not talking about ray tracing, this is much more primitive than that: just checking if a ray would intersect any of the aforementioned shapes at a distance smaller than its distance to the party's position.
Grimrock has some functions for getting ray intersection distances already (isectRayTriangle, isectRayBox, isectRayPlane, isectRaySphere, Mesh:raycast()), but they aren't available in the scripting interface and you'd probably want to write more specialized code here for performance reasons anyway.
The intersection testing itself isn't complicated if you have a passing familiarity with linear algebra; you can get the distance at which a ray intersects a box/plane/sphere with a few dot products and comparisons, and if the shape is transformed you can just transform the ray to the shape's local space first. Most of the work would be in:
1. making sure every shadow-casting thing in your dungeon has appropriate shapes for this attached to it, and that you don't accidentally put them on any non-shadow-casting things - you can imagine ways to automate this, but those would themselves take time to design and still require a lot of manual refinement.
2. partitioning those shapes so that the performance is acceptable (no matter how optimized your ray intersection code is, if you're going through every shape on the map for every shadow-casting light source near the party, it probably won't be as fast as you'd like).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Ask a simple question, get a simple answer
For some reason, this works:
But this causes an exception saying addItem requires an ItemComponent:
I assume I messed something up with uModding, but maybe I'm just doing something dumb so I'm asking here. These are being called by a script_entity btw
edit:
huh but if I use
It works fine
Code: Select all
local altar = spawn("altar", self.go.level, self.go.x, self.go.y + dy, self.go.facing, self.go.elevation, "s_" .. "altar" .. "_" .. s)
altar.surface:addItem(spawn(item).item)
Code: Select all
for e in self.go.map:entitiesAt(self.go.x, self.go.y + dy) do
if e.surface then
print(e.id) -- it prints the id of the altar I just spawned
e.surface:addItem(spawn(item).item)
break
end
end
edit:
huh but if I use
Code: Select all
local altar = findEntity(altarId)
if altar then
altar.surface:addItem(spawn("blue_gem").item)
end
- Zo Kath Ra
- Posts: 940
- Joined: Sat Apr 21, 2012 9:57 am
- Location: Germany
Re: Ask a simple question, get a simple answer
What's the value of the "item" variable?7Soul wrote: ↑Tue Dec 24, 2024 7:37 pm But this causes an exception saying addItem requires an ItemComponent:Code: Select all
e.surface:addItem(spawn(item).item)
If the "item" variable has the wrong value, then the spawned entity will not have an item component.
Maybe add a "print(item)" to the loop?
Re: Ask a simple question, get a simple answer
It works if I spawn it outside of the loop. If I spawn the altar and then spawn the item on it it's fine. If I spawn the altar and then use entitiesAt to find the altar, it doesn't work. And as you can see in the code, the loop does find the altar and does call addItem but the function doesn't recognize the ItemComponentZo Kath Ra wrote: ↑Tue Dec 24, 2024 11:08 pmWhat's the value of the "item" variable?7Soul wrote: ↑Tue Dec 24, 2024 7:37 pm But this causes an exception saying addItem requires an ItemComponent:Code: Select all
e.surface:addItem(spawn(item).item)
If the "item" variable has the wrong value, then the spawned entity will not have an item component.
Maybe add a "print(item)" to the loop?
I also just noticed that I can't access the .name property of an object in the entitiesAt loop either:
Code: Select all
for obj in self.go.map:entitiesAt(self.go.x, self.go.y) do
print(obj.name, obj.id) -- prints nil, and the correct id of the obj
end
Code: Select all
local ob = spawn("blue_gem")
print(obj.name, obj.id) -- prints "blue_gem, blue_gem_1"
Re: Ask a simple question, get a simple answer
Try this
Code: Select all
local gem = "blue_gem"
for e in self.go.map:entitiesAt(self.go.x, self.go.y + dy) do
if e and e.surface then
local o = spawn(gem).item
e.go.surface:addItem(o)
break
end
end
Test version of my Generations of Kings mod
https://drive.google.com/file/d/1DOTiuP ... drive_link
https://drive.google.com/file/d/1DOTiuP ... drive_link