Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permanently enable mountain signs #6

Open
aaeberharter opened this issue Dec 28, 2020 · 3 comments
Open

Permanently enable mountain signs #6

aaeberharter opened this issue Dec 28, 2020 · 3 comments

Comments

@aaeberharter
Copy link

Without diving too deep into your project I wanted to know if it is possible to always show the mountain signs from the beginning of the game and never have them decay, thus rendering the geologist obsolete.
If it is possible could you outline the steps necessary to achieve this effect? I would gladly implement them myself!

Randomly searching on the mountains slows the game down and I could enjoy the game more if I don't need to do that. I intend to use it in single player only.

@nyfrk
Copy link
Owner

nyfrk commented Dec 28, 2020

Interesting idea. I pushed a commit on branch dev-mapaccess that should allow you to do this. I haven't tested any features of that branch so its likely that it needs some fixes / polishing. Here is how i would do it:

  1. Install and use a tick listener
  2. On first Tick: Iterate all map fields (using the new features on dev-mapaccess, get the size of the map with MapSize)
  3. If a map field is a mountain (LandscapeGetType) check resources (LandscapeGetResource) at that field (using the new features on dev-mapaccess)
  4. Depending on the resource and its level spawn a sign using MapAddDecoObject script function
  5. Unregister the tick listener

Signs spawned this way should never despawn since the MapAddDecoObject should not register a removal event to the event engine. Also I do not know the id of the signs that are needed for the MapAddDecoObject function yet.

@aaeberharter
Copy link
Author

Thanks for your fast answer. It kind of works:
signs

2 Problems:
I can only add 2960 signs (more or less) before it crashes. I cannot investigate the crash because the debug build of the S4ModApi exhibits an unrelated crash at CMouseHook::OnMouse. Does the debug build of the mapaccess branch work for you?

The signs still despawn. I think the best workaround would be to lookup whether a sign is there and add one if it isn't. Is there a way to do this lookup?

@nyfrk
Copy link
Owner

nyfrk commented Dec 30, 2020

I can only add 2960 signs (more or less) before it crashes. I cannot investigate the crash because the debug build of the S4ModApi exhibits an unrelated crash at CMouseHook::OnMouse.

Probably some problem with the precompiled code. I will push the missing code. That already caused problems in the past.

Does the debug build of the mapaccess branch work for you?

It may be possible that it does not work. But that is not intended. I may have a look at it later. I hope it gets fixed when building without the precompiled code that i just pushed.

The signs still despawn. I think the best workaround would be to lookup whether a sign is there and add one if it isn't. Is there a way to do this lookup?

You could try LandscapeGetObject which should return the entity id of the object at a specific position. If there is no object it should return 0. Pass the entity id to EntityDecoGetType to get the deco type of the deco object (eg. it would be 199 for gold3 sign)

However i think the game optimizes the signs a little. There seems to only exist one entity for all signs of the same type. I am not sure if the game actually writes the signs entity id to the map that LandscapeGetObject accesses. But its worth a try.

If you cannot fix the crash it may be worth looking into how the game spawns the signs. The method that lets a geologist spawn a sign is at S4_Main.exe + 0x17b1b0. It is a method of the CGeologistRole class that takes a single argument (that probably is a pointer to the geologist entity). The spawning of the sign (in that method) happens probably at S4_Main.exe + 0x17b2ba and/or S4_Main.exe + 0x17b2c8. The first 3 arguments of both these functions is x, y, and the deco id (eg. 199 for gold3). The other arguments are constants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants