Author Topic: Newbe needs info on where to find what in code  (Read 38810 times)

Offline Callahan

  • Captain
  • ***
  • Posts: 61
    • View Profile
Newbe needs info on where to find what in code
« on: March 21, 2018, 11:34:39 am »
Hi all !

I seek to disable the "mutual sighting" code that prevents reaction fire if the actor does see the spotter, as this is not part of the original engine in my DOS versions of UFO/TFTD.
Now the code can be quite confusing if read for the first time, so please tell me where exactly this check is located in the code. That would save me big time searching and figuring what does what.
This one is really important to me.

Secondly, I want to rework the resource loading to store only the path of extra sprites and music/sounds in a dynamic char array, to be able to quick load them when they get used only.
The piratez mod does use way too much memory for my system and there is no need for all stuff to be loaded at game day 1.
This way, I could get any mod running, no matter the size.

Thanks for any help.

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9108
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #1 on: March 21, 2018, 12:59:26 pm »
I seek to disable the "mutual sighting" code that prevents reaction fire if the actor does see the spotter, as this is not part of the original engine in my DOS versions of UFO/TFTD.
Now the code can be quite confusing if read for the first time, so please tell me where exactly this check is located in the code. That would save me big time searching and figuring what does what.
This one is really important to me.

I will answer this later, first I need to understand what you're talking about... still need to do some reading in the other thread.

Secondly, I want to rework the resource loading to store only the path of extra sprites and music/sounds in a dynamic char array, to be able to quick load them when they get used only.
The piratez mod does use way too much memory for my system and there is no need for all stuff to be loaded at game day 1.
This way, I could get any mod running, no matter the size.

Thanks for any help.

I am very skeptical about the performance, and even feasibility, of this approach.
1. loading each sprite only when needed will bring the application to a crawl
2. pre-determining (and pre-caching) what sprites are really needed (e.g. at a start of a mission) is basically impossible
3. figuring out what can be removed from memory (e.g. after mission ends) can also be very tricky... and without it, your cache would quickly grow to full size

But maybe you have just some specific stuff in mind (e.g. ufopedia backgrounds only)... that falls into the realms of "doable".

As for help... the paths to resources are already mostly available:
I did a screen recently where you can see some sprite and sound resource paths (see attachment).

Relevant code for what you see on the screenshot is here:
https://github.com/MeridianOXC/OpenXcom/blob/oxce3.5-plus-proto/src/Ufopaedia/StatsForNerdsState.cpp#L1108
and here:
https://github.com/MeridianOXC/OpenXcom/blob/oxce3.5-plus-proto/src/Ufopaedia/StatsForNerdsState.cpp#L1142

As for the place, where the sprites and sounds are loaded now, it's in Mod.cpp:
https://github.com/MeridianOXC/OpenXcom/blob/oxce3.5-plus-proto/src/Mod/Mod.cpp#L3604

Good luck.

Offline The Reaver of Darkness

  • Commander
  • *****
  • Posts: 1512
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #2 on: March 21, 2018, 03:12:12 pm »
You want to disable mutual surprise? I don't think openxcom has anything to do that, but if it does, Meridian would know about it.

But the old X-Com did have mutual surprise. When you see the alien and they see you at the same time, whether it's your turn or theirs, reaction fire is suppressed. This is functionality from vanilla X-Com. I've played a few old versions but I don't think I have played one without mutual surprise.

There is an old discussion on the topic, however they hadn't discovered or reached a proper solution.
Disabling mutual surprise rule


I can think of another solution to make it easier to live with mutual surprise. Of course you can avoid letting your own soldiers take advantage of it if you wish, by going around corners without strafing. But you can also use corners to prevent aliens from gaining mutual surprise. Openxcom enables you to sidestep around a corner, but the aliens will never do this. There are some positions in which the aliens will never get mutual surprise against you.


P.S.: This post belongs in the Help forum.
« Last Edit: March 21, 2018, 03:18:02 pm by The Reaver of Darkness »

Offline Callahan

  • Captain
  • ***
  • Posts: 61
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #3 on: March 21, 2018, 04:21:29 pm »
Well, to tell the thing about "mutal surprise" as I see it, I tell you a short story of "Lucky Luke", the soldier with 100+ reaction who is faster than his shadow.

I'd like to mention that I use to play DOS xcom 1/2/3 with reaction fire only for years now, so I got alot of experience with that DOS reaction stuff.

In DOS, Lucky Luke and 3 fellows guard a UFO door from ahead, no blind angle. Alien opens the door and gets shot by one or more of Lucky Luke's squad instantly. Works every single time with reactions high enough.
Just tested this again yesterday to be sure about it.
I would bet it was the same in my DOS TFTD. I will edit some soldiers to super stats and make qick test of this today, by placing a few soldiers in plain sight of a alien sub door.

Now in open xcom, the story develops otherwise. Lucky Luke points his gun toward the UFO door, it opens, and an ARMED, HOSTILE????? Alien steps out. Now Lucky Luke and his squad are completely puzzled, he expected Ghandi to step out and invite him over to a cup of tea. And while Mr. Luke is still pondering this thought, a Sectiod with whimpy 26 Reaction rating is blasting him to hell.
Every damned single time without any chance for him to shoot faster than Mr. "Sloooow" Sectiod.

In my DOS UFO, reaction was a way to take away the initiative from an enemy, in open xcom it is merely just a factor for how fast you retaliate an attack.
"Mutual" surprise should mean the one with higher score does act first, but open xcom always favours the side who has it's turn.

Thanks for all the links, Meridian. That's alot to learn for me.
For the resources, I do not think I will fill up RAM that quickly. Most of the stuff, guns, armors, are not available at start.
I use to have a blitter function like this in all of my programs:

if ( !pSurface)
LoadSurface() ;
if ( !pSurface)
return; //Failed

Blt(..) ;

Of course RAM is filled over time, but only with stuff you actually use. That gives you a speed and RAM efficiency boost at programm start and a few tiny delays while stuff is loaded as needed.
Mostly, when loading smaller bitmaps, I do not even notice any delay, and my system is ancient. (2001)
« Last Edit: March 21, 2018, 04:23:14 pm by Callahan »

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9108
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #4 on: March 21, 2018, 05:08:25 pm »
I seek to disable the "mutual sighting" code that prevents reaction fire if the actor does see the spotter, as this is not part of the original engine in my DOS versions of UFO/TFTD.
Now the code can be quite confusing if read for the first time, so please tell me where exactly this check is located in the code. That would save me big time searching and figuring what does what.
This one is really important to me.

I can't say for sure how it worked in the original... I asked Warboy... maybe he will remember and will shed some light on the internal organs of vanilla.

In the meantime, this is the function that checks for reaction fire:
https://github.com/MeridianOXC/OpenXcom/blob/oxce3.5-plus-proto/src/Battlescape/TileEngine.cpp#L1665

It is called from all places listed in: https://www.ufopaedia.org/index.php/Reaction_fire_triggers

Opening doors is (besides other places!) part of walking state:
https://github.com/MeridianOXC/OpenXcom/blob/oxce3.5-plus-proto/src/Battlescape/UnitWalkBState.cpp#L335

And it is done AFTER the reaction checks:
https://github.com/MeridianOXC/OpenXcom/blob/oxce3.5-plus-proto/src/Battlescape/UnitWalkBState.cpp#L214

Now this doesn't mean it's wrong, the state's think() method is called many many times, so it might be the next call of this method that is supposed to process it... or not, depending on Warboy's answer to the original question.

I can't tell you where would be the best/correct place to put reaction checks for Lucky Luke...
... I put it in the place as shown on the screenshot, and Lucky Luke did shoot before a floater who just opened the door could say "we come in peace".

I recommend carefully studying the code before you decide to make the change... take my example only as inspiration, there's a 99% chance it's not complete and 75% chance it's wrong :)

Thanks for all the links, Meridian. That's alot to learn for me.
For the resources, I do not think I will fill up RAM that quickly. Most of the stuff, guns, armors, are not available at start.
I use to have a blitter function like this in all of my programs:

if ( !pSurface)
LoadSurface() ;
if ( !pSurface)
return; //Failed

Blt(..) ;

I know what you mean.

You'll understand what I mean after you read the code... everything's doable, some things are just not worth the effort. You may be able to find a feasible compromise though... let us know when/if you do.

Offline Callahan

  • Captain
  • ***
  • Posts: 61
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #5 on: March 21, 2018, 07:21:11 pm »
Meridian, I really have to say I grow to love your answers. Perfectly on point, containing all the info regarding the topic with precision and even offering a solution to help understand the mechanics. Just amazing, honestly.

As for the learning curve: I sometimes even have problems to understand my own code after a while.
This will be learning by doing a lot.
By the way, do I need some stuff other than the source for compiling this? DLLs, some DirectX SDK, other things to include?
I'm still looking for a compiler that does on my system. My old C++ cannot even read the project file.
I expected a .dsw/.dsp format, but I'm probably stone age with that.

As for the internal organs, I just tested DOS TFTD, and the aliens did all die on exiting the subs in rain of bullets. If Warboy does just play a bit of xcom 1 & 2 in reaction fire only mode, there will qickly be some light shed on the differences between vanilla and open xcom.

And... just as a side note: Are the aliens no longer fireing at the furniture on attacking player bases?
I remember to have lost a few workshops in vanilla that way.

EDIT: Had a brainstorm. While I am trying to find/setup a compiler, and since you test compiled the "Lucky Luke" experimental exe - could I have it in 32 bit version? Incomplete and 75% wrong sounds quite seductive to me right now.
« Last Edit: March 21, 2018, 07:35:30 pm by Callahan »

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9108
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #6 on: March 21, 2018, 07:52:17 pm »
Meridian, I really have to say I grow to love your answers. Perfectly on point, containing all the info regarding the topic with precision and even offering a solution to help understand the mechanics. Just amazing, honestly.

Thx.

As for the learning curve: I sometimes even have problems to understand my own code after a while.
This will be learning by doing a lot.
By the way, do I need some stuff other than the source for compiling this? DLLs, some DirectX SDK, other things to include?
I'm still looking for a compiler that does on my system. My old C++ cannot even read the project file.
I expected a .dsw/.dsp format, but I'm probably stone age with that.

You need the following dependencies: https://www.ufopaedia.org/index.php/Compiling_(OpenXcom)#Dependencies

If you're using Visual Studio, pre-compiled dependencies for 2010, 2013, 2015 and 2017 are here: https://www.ufopaedia.org/index.php/Compiling_with_Microsoft_Visual_C%2B%2B_(OpenXcom)#Compiling_.28x32_Release.29

As for the internal organs, I just tested DOS TFTD, and the aliens did all die on exiting the subs in rain of bullets. If Warboy does just play a bit of xcom 1 & 2 in reaction fire only mode, there will qickly be some light shed on the differences between vanilla and open xcom.

I didn't mean "remembers from playing"... I meant "remembers from reading the decompiled code"... Warboy (and a few others) decompiled the entire original xcom and implemented OpenXcom (also) based on that.

And... just as a side note: Are the aliens no longer fireing at the furniture on attacking player bases?
I remember to have lost a few workshops in vanilla that way.

Yes, they do still fire at "base furniture" in OpenXcom :)
Btw. I know that only from reading the code... I never ever lost a facility in original xcom due to that... first time was in OpenXcom.

EDIT: Had a brainstorm. While I am trying to find/setup a compiler, and since you test compiled the "Lucky Luke" experimental exe - could I have it in 32 bit version? Incomplete and 75% wrong sounds quite seductive to me right now.

Sure, give me a moment.

--- posts merged. No one is safe! ---

Try this: 2018-03-21-OpenXcomExPlus-LuckyLukeEdition.zip
« Last Edit: March 21, 2018, 10:58:15 pm by Solarius Scorch »

Offline The Reaver of Darkness

  • Commander
  • *****
  • Posts: 1512
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #7 on: March 21, 2018, 10:57:20 pm »
In DOS, Lucky Luke and 3 fellows guard a UFO door from ahead, no blind angle. Alien opens the door and gets shot by one or more of Lucky Luke's squad instantly. Works every single time with reactions high enough.
According to your experience, the aliens did not incur mutual surprise against the player.
According to my experience, the player did incur mutual surprise against the aliens.

I think we can see how it must have worked. In openxcom (OXC), the big difference is that both sides get mutual surprise, instead of it just being the player benefiting in both cases. I think I agree with you here, mutual surprise is a bad idea. It was useful to use against the aliens in the original, since their reaction attribute was so absurdly high they would often drain their entire time unit bar reacting to a single move when your soldier has full time units. Also, the original reactions training only worked if you waited for the aliens to come to you. So it made sense for the player to benefit in both cases; anything else would have made the game unreasonably difficult.

But while I think mutual surprise is a bad idea, I think it was also a bad idea to give the aliens such high reactions. It leads to the player losing 3+ soldiers from unseen aliens just from exiting the craft on a terror mission unless they wait inside on the first turn--which works because the aliens don't use grenades on the first turn, but it's completely counter-intuitive.

To really fix it, you have to change at least three things:
1.) remove mutual surprise
2.) reduce alien reaction attributes to be similar to humans (most importantly earlier aliens)
choice--one or both:
3a.) enable soldiers to train reactions by suppressing reaction fire as well as by using it
3b.) increase alien time units--their AI in OXC is very similar to vanilla AI, until you raise their TUs high enough to get to the next node, then suddenly they come out of hiding and try to attack you


- - - -

It would be awfully neat if OXCE+ had two new global variables:

friendlyMutualSurprise: true
enemyMutualSurprise: true
« Last Edit: March 21, 2018, 11:15:41 pm by The Reaver of Darkness »

Offline Callahan

  • Captain
  • ***
  • Posts: 61
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #8 on: March 22, 2018, 11:38:31 am »
Making the reaction system switchable is a must. There is no point in forcing anyone to play the one or other style. I would dump mutual surprise, as it  negates reaction in many a combat situation, but it is not everyones opinion.

As for turn 1, I always had in mind cutting the aliens initial TUs by some % to simulate arriving "during action". That should do for turn 1 without tampering with the vanilla alien stats.

Thanks for the exe, Meridian, as well as the explanations. Cool thing they managed to reverse engineer DOS xcom. I was always bound to observation of the game itself. I will try the Luky Luke edition as soon as I have hex edited it to work in Win 2000.

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9108
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #9 on: March 22, 2018, 11:43:53 am »
It would be awfully neat if OXCE+ had two new global variables:
friendlyMutualSurprise: true
enemyMutualSurprise: true

No.

Making the reaction system switchable is a must.

No.

PS: can you upload a vanilla save where I can test this behavior? I tried a bit, but I don't have soldiers with high enough reactions...

Offline Callahan

  • Captain
  • ***
  • Posts: 61
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #10 on: March 22, 2018, 04:16:53 pm »
Here is a vanilla savegame with some good soldiers. I had to copy them outta my tactical savegame into a newly started one, so don't be confused over them to be like that on day 1.
Should work in spite of the little cheat.

With those guys, you will see enemies left in your soldiers view at end of turn to be shot before they can take any action.

Offline The Reaver of Darkness

  • Commander
  • *****
  • Posts: 1512
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #11 on: March 22, 2018, 09:10:25 pm »
How do I use this folder as a save game? It's not in the same format.

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9108
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #12 on: March 22, 2018, 10:12:17 pm »
How do I use this folder as a save game? It's not in the same format.

Well, first, it's an xcom1994 save, not an OpenXcom save... but I assume you knew that?
It loads fine in xcom1994.

OpenXcom can load xcom1994 geoscape saves too... but only if they are 100% correct... this one was hexedited (or otherwise tempered with) and is slightly corrupted (contains soldiers that belong to non-existing bases)... so OpenXcom crashes when it tries to load it.
« Last Edit: March 22, 2018, 10:18:41 pm by Meridian »

Offline Callahan

  • Captain
  • ***
  • Posts: 61
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #13 on: March 23, 2018, 10:41:55 am »
Well, first, it's an xcom1994 save, not an OpenXcom save... but I assume you knew that?
It loads fine in xcom1994.

OpenXcom can load xcom1994 geoscape saves too... but only if they are 100% correct... this one was hexedited (or otherwise tempered with) and is slightly corrupted (contains soldiers that belong to non-existing bases)... so OpenXcom crashes when it tries to load it.

Guess I should have tested for that before. I will fix it.

Ran into trouble. Not for love or money I can load any vanilla save. Not even a fresh one from a fresh DOS install. Open xcom tells me something would be missing in my mod, but no word on what this might be in the log.
So I had to apply a fix by blind snapshot. Deleted all soldiers that may caused trouble. No idea if that does it. I'm unable to test that.
« Last Edit: March 23, 2018, 04:05:34 pm by Callahan »

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9108
    • View Profile
Re: Newbe needs info on where to find what in code
« Reply #14 on: April 01, 2018, 03:24:39 pm »
So after testing and investigating, I admit there is a yet-unidentified difference between OG and OpenXcom.

It is however beyond my current capabilities to find out what exactly it is.

PS: the difference is NOT in opening doors triggering reaction fire; and most likely also not in mutual surprise... it is very likely something very subtle that has quite big impact
PS2: that means that my "LuckyLuke experiment" was 100% wrong... although still might cover your taste :)
« Last Edit: April 01, 2018, 03:40:01 pm by Meridian »