Smart AI on Github

Ninakoru

A deity on Emperor
Joined
Nov 14, 2002
Messages
658
Location
Madrid, Spain, Europe
To everyone who may want to add some of the AI enhancements to their DLL mods, here you are.

I didn't use the tool before, but nothing too complicated :)

https://github.com/Ninakoru/Civ5-DLL

Forked from Gedemon CIV5-DLL, Added my modified files from the VS solution and modified the readme file to add all the methods witch I changed.
 
Please consider using C's #if defined() - #else - #endif pre-processor construct to make identifying and merging the code changes easier - see the top third of this post for how and why

Edit: And a plea, please don't auto-format the files. There are 1414 changed sections (not lines) in CvCity.cpp, 1402 of those are a consequence of blank lines being inserted/removed, trailing spaces being removed, leading spaces being replaced with tabs, leading tabs being added to "correctly" indent lines, (unnecessary) curly brackets being added around single statement ifs, etc, etc, etc.

TIA

W
 
Yeah, when I programmed that I didn't have in mind sharing the code, not that I didn't want to, just I didn't thought about it.

Still I tried to follow the messy (IMO) programation done by the original game devs, noted down every method I modified and created and add comments through the code to try to explain my changes.

Thanks for the information, I'm not used to C++, great to know about pre-processor intructions and code macros. I'll consider your recommendation.
 
Thanks for the code anyway :D

It's just that with the formatting changes (10,320 additions and 7,589 deletions), I think we'll need a merge tool that ignore formating, if that exists.

It reminds me when I've done a "replace in all files" PlayerID -> iPlayer in a solution in modbuddy with a lot of projects, to find out months after that now I'm a bit embarassed when comparing replaced files with the originals if I leave it that way :blush:

Don't get us wrong, the source code is welcome, and the readme will be usefull, it's just a bit frustrating.
 
That huge amount of changes is my fault, not that I changed so much code, I used AStyle Extension to tidy the code in most of the cpp pages I edited. Again I didn't take into acount merging :(

... (unnecessary) curly brackets being added around single statement ifs ...

BTW I also like to skip brackets on single statement if/elses, butto always include brackets is considered a good practice :p
 
BTW ,about merging changes: I have all the changes In my head and I like the idea of people merging this changes into their DLL (and if they give proper credit, much better :)).

This afternoon I'll take 20 minutes to make the changes again over the unformatted version, so is easier to track those changes.

Anyways remember the dll is on beta version: I try to make the assembly as universal as possible, but there are methods I still don't see a 100% integration into other people mods, and need a bit more work. Other methods aren't fully tested and maybe add secondary effects or return undesirable outputs.

Examples:

Universal 100% integrable:
--------------------------

The methods associated with the move + shot for mobile ranged are fully tested, performance tested, and I can't think of a situation in any type of mod you don't want the AI to perform better in that regard.

100% working but still need some refinement:
--------------------------------------------

Disbanding long obsolete units could mess up with some specific units on mods: Lets say a mod that focuses on WW2 and has 8 different eras, and there's an upgradeable tank that gets an upgrade 5 eras later. This will meet all requirements and start disbanding those "long obsolete" tanks without reason.

Not sure it's working/ not fully tested:
----------------------------------------

The social policies modifications. Theoretically AIs should have less focus on tradition/piety and get a bit more variety, but I don't see any real change in AI policy decisions. I have to test it even further.

All in all, if you want to add features I should make some further explanation on changes, states and impact.
 
always include brackets is considered a good practice :p

It is. But it's overridden by the "light touch" rule when changing other people's code.

I hate
Code:
if (cond)
{
  stmt 1;
}
else
{
  stmt 2;
}

and much prefer
Code:
if (cond) {
  stmt 1;
} else {
  stmt 2;
}

but you should never change from one to the other just for the sake of it - same with trailing spaces, blank lines, changing leading spaces into tabs, re-tabbing nested ifs, etc as it makes for a complete nightmare when comparing files. Even if you don't expect others to be merging your code, at some point in the future you will be merging your own changes back into the Firaxis code-base when they release the next patch.
 
All in all, if you want to add features I should make some further explanation on changes, states and impact.
Always good. But I wouldn't worry about other dll modders merging your changes blindly. They will most likely pick through and take what they understand and need. (At least that's what I do with Gedemon's and whoward69's dlls.) Giving credit of course. Good commenting and a nice clean diff file really help with this.

I would second whoward69's suggestion to use precompile instructions in your code:
Code:
#ifdef MYMOD_SOMETHING
	< new code >
#else
	< original code >
#endif
This really makes your life easier. For example, I started to build a "Leader Scene Bypass". What a nightmare! But it was very easy to back out of this effort by disabling the define in my EaModding.h file. So my incomplete and buggy code is still there (if I want to continue this quixotic quest sometime in the future) but it's not compiled. Basically, I can undo 100 of my own changes in the time it takes to type "//".

The other reason to do this is so that the < original code > lines are still there, completely unchanged, so they will show up in diff files when Firaxis updates the base dll again. You can see their changes (from 1.0.3.144 to next version) even in the code that you disabled, and adjust your code if needed.
 
It is. But it's overridden by the "light touch" rule when changing other people's code.

Heh, totally agree, all those changes were made with a tidy code tool, if I had merging on my head from the beginning, I would keep the code as intact as possible.

... at some point in the future you will be merging your own changes back into the Firaxis code-base when they release the next patch.

Ha! Precisely I've gone into AI modding because I lost all hope on further patches from Firaxis. I'm hoping to be mistaken though. Until now I only gone into xml and lua mods, specially xml because are easy to mantain, but now that i feel the game is "over", I can't stand the horrible state the AI still has.

Heh, you all seem a bit pissed, I gladly take into consideration your advices and I'll remake the repository with a merge-friendly code :)
 
Well, if you feed a bear...

But seriously, no one is pissed. Sometimes the help here may seem a little aggressive. I'm overjoyed that someone is actually doing something with AI, rather than just talking about it. Kudos!
 
Don't worry, no offense taken at all: was just my impression.

I've finally redone the repository branch and done the changes without auto-format. Is much more readable-mergeable now. Took a while, far more than 20 minutes.

I'll take a little break on the mod work, I actually want to play a few games with the mod and have some fun, until now was only observing autoplayed games :)
 
Thank you again :goodjob: (and please, add my apologies to the others for the impression we've given)

Some of this may be included in R.E.D WWII ASAP, like move and fire, that'll help the AI, there's a lots of artilleries in the mod...

Edit: speaking of which, that mods log the combats info in a table in Lua to give the AI a "memory", so it can use air sweeps and interception without "cheating", would it be difficult to use that kind of method in the DLL ? (not a request, just a theorical question, but I suppose it could help the tactical AI in other domains to have a memory)
 
Edit: speaking of which, that mods log the combats info in a table in Lua to give the AI a "memory", so it can use air sweeps and interception without "cheating", would it be difficult to use that kind of method in the DLL ? (not a request, just a theorical question, but I suppose it could help the tactical AI in other domains to have a memory)

Yes, that little "cheating" was on the original methods too as there's no memory of plane attacks and planes can be easily out of vision.

Shouldn't be a problem at all, all the dll continuosly read data from the database and store it into memory through class objects or structures. I'm not sure if it's treated always as static data, as is information that usually don't change over turns.

Anyways, there's a actually information from previous turns stored into memory: It is used to get the Tactical zones and postures for the previous turn, or the AI armies for example, this information of course is also stored into saved files and such. With enough time and testing, shouldn't be too hard to add some memory about plane attacks for example.
 
Top Bottom