SGOTM 17 - Plastic Ducks

I'm no C++ programmer and I can read the code on surface. Even sometimes scratch a little deeper. It just comes form enthusiasm and persistency. At some point, you get enough experience that you start to see repetitions after repetitions. The sections of code of interest for the player (I'm talking game mechanics not save game mechanics and stuff of that ilk, which is perhaps harder to understand) are often the simplest.

Most of what I encountered was a mash of conditional structures (if(){}) and data manipulations (setData, getData, etc).
Sometimes, there are new functions, but it often avers to be different functions for manipulation of mass data like map <arg1,arg2>.
 
...and I wish I could find anything in this mess called civ 4 code... it's just about as well documented as the scripts I write for personal use...

I never thought Civ4 code was hard to follow, personally I care of comments only if the case is truly non obvious. (Real Programmers don't comment their code. If it was hard to write, it should be hard to understand [1]) Civ4 is probably the most readable piece of (still) crap large code I've met.
It's pretty atrocious but it's extremely easily readable C code (very hard to call it C++ even). Some parts are admittedly terri-bad organized w/ my personal favorite: tech choice.
Overall, everything is inner loop into inner loop, no hashing (or trees, God forbid!) at any rate - close to no objects instead indexes into arrays (lacking type safety there) - similar to what I did when I was 8 or so, obviously data structures and algorithms are for com-sci drop outs :) The latter is a major part of the slow late game.

Yet, usually I can find the code in question in just 20-30sec.

Not to be totally negative it does make good use of asserts.

[1]: http://www.suslik.org/Humour/Computer/Langs/real_prog2.html

:lol::lol::lol:
Yep, I would have been kicked out of my c++ class back in my uni days for some of those monster functions :)
Definitely, it's not even a question of invitation; you're now an official Plastic Ducks Team Member Platinum Certified™ and are most welcome to join up in the future SGOTMs :high5:

By the way, this is definitely valid for our other new members :D
Great title, thanks :)
 
Ducks: I hope you've had fun playing both this and the other SGotMs, but if not - take consolation in the fact that someone at least enjoys watching. Congratulations for yet another impressive, and more importantly enjoyable, performance.
 
I discovered this about a month ago while I was "updating" the test game to check for teleportation.

It's a minor bug coming from BUG/BUFFY that gives you some information you shouldn't have prior to discovering Calendar or building Stonehenge.
ha, interesting! :cool:

Any words of wisdom about culture recess after city captures? (and why it takes a turn or two to re-adjust correctly)
Culture recess is tricky and rather difficult to predict.

Tiles within the culture range of a third player's city get forced to be unowned for the current plus the following turn (FORCE_UNOWNED_CITY_TIMER = 2 in GlobalDefines.xml), even if the conquering player out-cultures that third player on these tiles.

I'm not completely sure, but I think updating of the plot ownership is done in two steps, first for the whole culture radius and then again for the inner ring and it always works plotwise from SW -> NE.
The hole-filling algorithm mentioned above can produce really funny culture patterns, like here in Kaku's game:
Screenshots
Spoiler :

These artifactual remnants will get cleared directly after ending the turn. It should be possible to avoid them by following the direction SW -> NE during the conquest of cities, the order in which one acquires the cities definitely matters.
 
Question:

Shall we begin laying out roads/forts to access the north western barb city?
Spoiler :

btw, this wouldn't have worked :) (1W of Marble not adjacent to water)
and the forts don't need roads to function as canals, only to connect trade networks :old:
 
These artifactual remnants will get cleared directly after ending the turn. It should be possible to avoid them by following the direction SW -> NE during the conquest of cities, the order in which one acquires the cities definitely matters.
That's interesting. We certainly attacked from ~E --> W and ~N --> S in the cities we experienced culture problems with, that's true. Maybe that's the reason why KCD started us in the NE corner of the map :)
 
These artifactual remnants will get cleared directly after ending the turn. It should be possible to avoid them by following the direction SW -> NE during the conquest of cities, the order in which one acquires the cities definitely matters.

The surrounding ring of Qin culture in the screenshot you gave did indeed recede by the next turn.
 
The surrounding ring of Qin culture in the screenshot you gave did indeed recede by the next turn.
Sure, but you might want to move units on the same turn, so it's better to avoid it if possible.
 
The 2 plots in the very corners (SW and SE) of the map got assigned to English / Khmer culture when London and Yaso popped their borders.

The game fills culture holes when all adjacent plots in the cardinal directions are owned by the same player:

Spoiler :
Code:
PlayerTypes CvPlot::calculateCulturalOwner() const
    
	....
	
	if (eBestPlayer == NO_PLAYER)
	{
		bValid = true;

		for (iI = 0; iI < NUM_CARDINALDIRECTION_TYPES; ++iI)
		{
			pLoopPlot = plotCardinalDirection(getX_INLINE(), getY_INLINE(), ((CardinalDirectionTypes)iI));

			if (pLoopPlot != NULL)
			{
				if (pLoopPlot->isOwned())
				{
					if (eBestPlayer == NO_PLAYER)
					{
						eBestPlayer = pLoopPlot->getOwnerINLINE();
					}
					else if (eBestPlayer != pLoopPlot->getOwnerINLINE())
					{
						bValid = false;
						break;
					}
				}
				else
				{
					bValid = false;
					break;
				}
			}
		}

		if (!bValid)
		{
			eBestPlayer = NO_PLAYER;
		}
	}

	return eBestPlayer;

Gold again for the Ducks - Congratulations!
Does this account for the "ghost" culture you occasionally see after a civilization is destroyed? E.g. in the far SW corner of the map of our final save:

http://gotm.civfanatics.net/download.php?file=Plastic_Ducks_SG017_AD1520_01.CivBeyondSwordSave

...the plot falls under English control, despite containing 0% culture (their being dead and all).
 
Thanks Dan!
'suppose we just have to tag along 2 workers with stacks to make certain we don't lose too much time, there isn't much else we can do.

I noticed the forts to the north wouldn't work once I planned out the ones in the west. It didn't really matter at that point but I'll have to keep that in mind for the future if it is ever needed to plan again :o
EDIT: the roads suggestions were to avoid wasting too many worker turns: 1 worker goes ahead and places roads (-3 worker turns) but other workers don't waste time. As long as you've got 4+ working on forts, it's faster.

@Zherak_Khan
To me, SGOTM is the most enjoyable form of civ4 at this point. I usually end up losing sleep over it (even though I promise myself not to :lol:) because I obsess too much about the game.
 
That's interesting. We certainly attacked from ~E --> W and ~N --> S in the cities we experienced culture problems with, that's true. Maybe that's the reason why KCD started us in the NE corner of the map :)

You are giving me way too much credit if you think my understanding of the workings of the game are anything near this level.:blush:
 
You are giving me way too much credit if you think my understanding of the workings of the game are anything near this level.:blush:
Congratulations on your evil instincts then :D
 
No worries, it's T163 and Churchill's dead so we can all relax :D :sheep: Both mace and Geronimo were needed, also HA had to finally attack Nottingham as I lost a 97% battle there. Otherwise everything went really well :)

:band:

Never submitted a SGOTM win before. Is it the same as with a HOF win? Hit "wait, just one more turn :please:" and then submit?

:goodjob: UE and everyone

sorry for my silence for the past few days, but I spent the we in a place where Internet was completely absent.
I mean completely.
Nothing, nichts, niente, nada, rien, peau de balle
I was transported back into the early 90's. It's sad to see how much trouble it caused me....:borg::nono:


anyways, congrats to everyone again, and now I have a few thousand posts to catch up.


Quick question, before I start browsing the threads : where are the other teams at? Were we the last to finsih? If not, what are the current standings?
 
sorry for my silence for the past few days, but I spent the we in a place where Internet was completely absent.
I mean completely.
Space trip to the Moon? :D
Quick question, before I start browsing the threads : where are the other teams at? Were we the last to finsih? If not, what are the current standings?
TSR, Xteam, PR are still playing. We will get the gold for sure. TSR is at T161, still some turns to finish off Churchill, haven't touched Peter or Toku yet. Kaku finished T174 and they're looking good for silver, although it will be a close call with TSR, who still has to navigate their stack through the whole of Toku's maze. We'll see.
 
Does this account for the "ghost" culture you occasionally see after a civilization is destroyed? E.g. in the far SW corner of the map of our final save:

...the plot falls under English control, despite containing 0% culture (their being dead and all).
yes, the hole-filling function does not check whether the owner of the adjacent tiles is actually still alive ...
in extreme cases (e.g. conquest of a high culture city near the SW corner of a flat map) it will take the game several turns to chew away the artifactual culture remnants in the corner from the north and the east.
 
yes, the hole-filling function does not check whether the owner of the adjacent tiles is actually still alive ...
in extreme cases (e.g. conquest of a high culture city near the SW corner of a flat map) it will take the game several turns to chew away the artifactual culture remnants in the corner from the north and the east.
Thanks Dan. Not much one can do with that info, I think. :D But it's always nice to know the reason behind the rhyme.
 
yes, the hole-filling function does not check whether the owner of the adjacent tiles is actually still alive ...
in extreme cases (e.g. conquest of a high culture city near the SW corner of a flat map) it will take the game several turns to chew away the artifactual culture remnants in the corner from the north and the east.

I would like to know where are the functions in question.
 
as mentioned above the hole-filling code is in CvPlot::calculateCulturalOwner()

it gets called for each plot via CvMap::doTurn() -> CvPlot::doTurn() -> CvPlot::doCulture() -> CvPlot::updateCulture() -> CvPlot::setOwner()
starting at the origin of the map (SW corner)

CvCity::setCultureLevel() handles culture recess for the 'old' city called in CvCity::kill(), the latter function also triggers culture updates for the plots in the inner ring.

CvPlayer::acquireCity() has the code for setting plots that meet the conditions described earlier to ForceUnowned.

I guess there is more, e.g. CvCity::updateCultureLevel() might be relevant for the 'new' city during its initialization ... :)
 
Back
Top Bottom