Author Topic: Faction societal effects effectively ignored  (Read 1735 times)

0 Members and 1 Guest are viewing this topic.

Offline scient

Faction societal effects effectively ignored
« on: March 21, 2019, 06:45:24 AM »
So induktio mentioned to me that they noticed a bug where the faction defined societal priority / opposition effects are completely disabled. While working on the read_faction() function I've come across where the actual issue is in the code. I vaguely remember seeing posts or reading about this issue awhile ago. I don't recall who or where since it's all a jumble in my brain at this point. Maybe kyrub or Yitzi addressed this already via patching?

Just to outline the issue, inside Player structure there are 6 values. The read_faction function initializes both the categories and effects as -1 and model to 0. Inside the faction editor, category and model priority are determined by social ideology. Opposition is determined by anti-ideology (not sure where I came up with term opposition, I may rename code variable names). The bugged value is referenced as emphasis or socPriorityEffect below. It looks like you can't directly set anti-emphasis via faction editor nor is it directly referenced at all in the code. I haven't dug into indirect references other than read_faction().

An example from gaians.txt:
  Economics, Green, PLANET
  Economics, Free Market, nil

struct Player {
...
int socPriorityCategory; // Gaians will be Economics
int socOppositionCategory; // " "
int socPriorityModel; // Gaians will be Green
int socOppositionModel; // Gaians will be Free Market
int socPriorityEffect; // Gaians should be PLANET, vanilla code sets to -1 or disabled
int socOppositionEffect; // unused/padding/ignored
};

void __cdecl read_faction(Player *player, int type) {
...
   for (int i = 0; i < 2; i++) { // first priority, then opposition
      *(&player->socPriorityCategory + i) = -1;
      *(&player->socPriorityModel + i) = 0;
      *(&player->socPriorityEffect + i) = -1;
       <parse and set societal categories; all correct>
       <parse and set societal models; all correct>

      LPSTR socEffect = text_item();
      for (int j = 0; j < MaxSocialEffectNum; j++) {
         if (!_strcmpi(SocialEffect[j].set1, socEffect)) {
            *(&player->socPriorityEffect + i) = -1;
            break;
         }
      }
   }

So the issue is, rather than setting it to j it sets it to -1. I couldn't find anything stating this mechanic was suppose to be disabled versus something like the freefac value under #FACILITIES. It is actually referenced in two functions: communicate() and social_ai(). After skimming direct references, communicate() doesn't seem that interesting but there is a large section of code that gets skipped in social_ai() if socPriorityEffect is -1. So perhaps fixing this will improve the AI in some ways or at least make them act more as they were intended.

Comments, thoughts?
« Last Edit: March 21, 2019, 07:03:06 AM by scient »

Offline scient

Re: Faction societal effects effectively ignored
« Reply #1 on: March 21, 2019, 03:21:09 PM »
I went through and pulled out the emphasis effect value from each faction text file. Nothing too surprising.
Angels: PROBE
Believers: PROBE
Caretakers: PLANET
Cybernetic Consciousness: GROWTH
Drones: INDUSTRY
Gaians: PLANET
Hive: POLICE
Morgan: ECONOMY
Peacekeepers: GROWTH
Pirates: SUPPORT
Planet Cult: PLANET
Spartans: MORALE
University: RESEARCH
Usurpers: PLANET

Also, planning on renaming my internal variable names to be in line with faction editor. While combing through game files and my notes, I think I just arbitrarily picked Priority/Opposition naming convention.

Offline Induktio

Re: Faction societal effects effectively ignored
« Reply #2 on: March 21, 2019, 03:39:40 PM »
So yeah, debugger indicates both of these soc_effect values are set to -1 which means they are undefined. Were you able to decipher what is the purpose of the code in social_ai that refers to these values and what is the actual offset to that code? That kind of functionality could be replicated in Thinker if it does something meaningful but first we would need to patch the config parser to achieve that.

Offline scient

Re: Faction societal effects effectively ignored
« Reply #3 on: March 21, 2019, 04:09:20 PM »
Only a cursory look. It is a good chunk of code at least for social_ai() function. Communicate I believe is pretty simple. Both reference one of the few internal structures I haven't done a lot of work on. I believe it's a more robust Player/Faction structure that keeps internal data about current game (Player *, diplomacy, tech discovered, credits, etc). As I start adding other areas to dll, I plan to start mapping this out more.

void __cdecl communicate(int factionID, int, int);
...
.text:0055013C                 mov     ebx, Players.socPriorityEffect[ebx]
.text:00550142                 test    ebx, ebx // checking if emphasis value is -1
.text:00550144                 jl      short loc_55018D // skip if disabled
<couple more checks>
.text:00550186                 add     g_DIPLO_current_likeablity, 3 // my guess is that if both factions have same social emphasis, you get boost to likability score
<continue on>

void __cdecl social_ai(int factionID, int, int, int, int, int *);
.text:005B4B5B                 mov     eax, Players.socPriorityEffect[eax]
.text:005B4B61                 test    eax, eax // checking if emphasis value is -1
.text:005B4B63                 jl      short loc_5B4B90 // skip if disabled (BOOL stays FALSE)
<more checks>
.text:005B4B8B                 mov     edi, 1 // set BOOL to TRUE
.text:005B4B90                 test    edi, edi // checking if BOOL is TRUE/FALSE
.text:005B4B92                 jnz     loc_5B5481
.text:005B4B98                 mov     ecx, [ebp+var_78] // start of social emphasis code
....
.text:005B5481                 mov     edi, [ebp+var_28] // end
<code continues>

 

* User

Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Select language:

* Community poll

SMAC v.4 SMAX v.2 (or previous versions)
-=-
24 (7%)
XP Compatibility patch
-=-
9 (2%)
Gog version for Windows
-=-
103 (32%)
Scient (unofficial) patch
-=-
40 (12%)
Kyrub's latest patch
-=-
14 (4%)
Yitzi's latest patch
-=-
89 (28%)
AC for Mac
-=-
3 (0%)
AC for Linux
-=-
6 (1%)
Gog version for Mac
-=-
10 (3%)
No patch
-=-
16 (5%)
Total Members Voted: 314
AC2 Wiki Logo
-click pic for wik-

* Random quote

Abort, Retry, Fail?' was the phrase some wormdog scrawled next to the door of the Edit Universe project room. And when the new dataspinners started working, fabricating their worlds on the huge organic comp systems, we'd remind them: if you see this message, always choose 'Retry.
~Bad'l Ron, Wakener, Morgan Polysoft

* Select your theme

*
Templates: 5: index (default), PortaMx/Mainindex (default), PortaMx/Frames (default), Display (default), GenericControls (default).
Sub templates: 8: init, html_above, body_above, portamx_above, main, portamx_below, body_below, html_below.
Language files: 4: index+Modifications.english (default), TopicRating/.english (default), PortaMx/PortaMx.english (default), OharaYTEmbed.english (default).
Style sheets: 0: .
Files included: 45 - 1228KB. (show)
Queries used: 37.

[Show Queries]