Military Advisor

like the code - thx EF. I'm just going to run thru my logic so that you can get a laugh and correct me. BTW - set() sounds great!
  • I have a unit that player A can build ... UnitA (think horse archer).
  • I also have set of units that player B can build.
  • Now, I want to display UnitA if that unit (or any of the units that UnitA upgrades to) is not in the set that B can build.
  • So if the set of units that B can build contains a chopper, then no horse archer.
There are obviously a number of ways of doing this but here is how I was thinking of approaching it.

pseudo code...
Code:
AllPlayerAs_Units = getCanTrain(PlayerA)
AllPlayerBs_Units = getCanTrain(PlayerB)

for UnitA in AllPlayerAs_Units
  UpgradeSet_UnitA = get_set_of_units_to_check(UnitA)
  if len(UpgradeSet_UnitA & AllPlayerBs_Units) > 0:
    add UnitA button

def getCanTrain(PlayerA)
I already have this

def get_set_of_units_to_check(UnitA)
I will be looking at your code to build this
 
That looks great. Part of the code is done above for you:

PHP:
for UnitA in AllPlayerAs_Units
  UpgradeSet_UnitA = get_set_of_units_to_check(UnitA)
  if len(UpgradeSet_UnitA & AllPlayerBs_Units) > 0:
    add UnitA button
becomes

PHP:
for UnitA in AllPlayerAs_Units
  if not self.isObsolete(UnitA, AllPlayerBs_Units):
    add UnitA button
 
Here is my code ... basically EFools with some variable renaming so it wasn't as confusing for me

PHP:
	def PrintUpgrades(self):

		if len(self.FutureUnitsByUnitClass) == 0:
			self.buildFutureUnitsByUnitClass()

		for u in (self.FutureUnitsByUnitClass):
			sDummy = "Unit Upgrade (%s): " % (gc.getUnitInfo(u).getDescription())

			upgrades = self.FutureUnitsByUnitClass[u]
			for k in upgrades:
				sDummy += " %s" % (gc.getUnitInfo(k).getDescription())
		
			print sDummy
		return



	def buildFutureUnitsByUnitClass(self):
		NUM_UNITS = gc.getNumUnitInfos()
		
		# Create graph of single-step upgrades (Swordsman to Maceman)
		self.FutureUnitsByUnitClass = {}
		self.UnitsAlreadyMapped = set()
		for iUnitA in range(NUM_UNITS):
			infoA = gc.getUnitInfo(iUnitA)
			upgrades = set()
			self.FutureUnitsByUnitClass[iUnitA] = upgrades  # <-- creates a link between these two items
			for iUnitB in range(NUM_UNITS):
				infoB = gc.getUnitInfo(iUnitB)
				if infoA.getUpgradeUnitClass(infoB.getUnitClassType()):
					upgrades.add(iUnitB)   # also adds iUnitB to FutureUnitsByUnitClass array
		
		# Now add all transitive upgrades (Swordsman to Rifleman)
		for iUnit in self.FutureUnitsByUnitClass.iterkeys():
			self.buildFutureArray_Closure(iUnit)   # just starting the recursive call

	def buildFutureArray_Closure(self, iUnit):
		upgrades = self.FutureUnitsByUnitClass[iUnit]
		if iUnit not in self.UnitsAlreadyMapped:
			nextUpgrades = set()
			for iNextUnit in upgrades:
				nextUpgrades |= self.buildFutureArray_Closure(iNextUnit)  # note recursive call
			upgrades |= nextUpgrades
			self.UnitsAlreadyMapped.add(iUnit)
		return upgrades

... and here are the results of that print ...

Spoiler :

PHP:
Unit Upgrade (Lion): 
Unit Upgrade (Bear): 
Unit Upgrade (Panther): 
Unit Upgrade (Wolf): 
Unit Upgrade (Settler): 
Unit Upgrade (Worker): 
Unit Upgrade (Fast Worker): 
Unit Upgrade (Scout):  Explorer
Unit Upgrade (Explorer): 
Unit Upgrade (Spy): 
Unit Upgrade (Cereal Mills Executive): 
Unit Upgrade (Sid's Sushi Executive): 
Unit Upgrade (Std Ethanol Executive): 
Unit Upgrade (CreateCon Executive): 
Unit Upgrade (Mining Inc Executive): 
Unit Upgrade (AlumCo Executive): 
Unit Upgrade (Civ Jewels Executive): 
Unit Upgrade (Jewish Missionary): 
Unit Upgrade (Christian Missionary): 
Unit Upgrade (Islamic Missionary): 
Unit Upgrade (Hindu Missionary): 
Unit Upgrade (Buddhist Missionary): 
Unit Upgrade (Confucian Missionary): 
Unit Upgrade (Taoist Missionary): 
Unit Upgrade (Warrior):  Vulture Dog Soldier Maceman Samurai Berserker Spearman Impi Holkan Pikeman Landsknecht Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry Axeman Phalanx
Unit Upgrade (Quechua):  Machine Gun Axeman Phalanx Vulture Dog Soldier Maceman Samurai Berserker Spearman Impi Holkan Pikeman Landsknecht Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Mechanized Infantry
Unit Upgrade (Swordsman):  Maceman Samurai Berserker Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Jaguar):  Maceman Samurai Berserker Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Gallic Warrior):  Maceman Samurai Berserker Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Praetorian):  Maceman Samurai Berserker Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Axeman):  Maceman Samurai Berserker Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Phalanx):  Maceman Samurai Berserker Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Vulture):  Maceman Samurai Berserker Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Dog Soldier):  Maceman Samurai Berserker Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Maceman):  Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Samurai):  Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Berserker):  Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Spearman):  Pikeman Landsknecht Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Impi):  Pikeman Landsknecht Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Holkan):  Pikeman Landsknecht Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Pikeman):  Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Landsknecht):  Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Musketman):  Infantry SAM Infantry Mobile SAM Mechanized Infantry Rifleman Redcoat
Unit Upgrade (Musketeer):  Infantry SAM Infantry Mobile SAM Mechanized Infantry Rifleman Redcoat
Unit Upgrade (Janissary):  Infantry SAM Infantry Mobile SAM Mechanized Infantry Rifleman Redcoat
Unit Upgrade (Oromo Warrior):  Infantry SAM Infantry Mobile SAM Mechanized Infantry Rifleman Redcoat
Unit Upgrade (Rifleman):  Mechanized Infantry Infantry SAM Infantry Mobile SAM
Unit Upgrade (Redcoat):  Mechanized Infantry Infantry SAM Infantry Mobile SAM
Unit Upgrade (Grenadier):  Mechanized Infantry Infantry SAM Infantry Mobile SAM Machine Gun
Unit Upgrade (Anti-Tank):  Mechanized Infantry
Unit Upgrade (Infantry):  Mechanized Infantry SAM Infantry Mobile SAM
Unit Upgrade (SAM Infantry):  Mobile SAM
Unit Upgrade (Mobile SAM): 
Unit Upgrade (Marine): 
Unit Upgrade (Navy SEAL): 
Unit Upgrade (Paratrooper): 
Unit Upgrade (Mechanized Infantry): 
Unit Upgrade (Archer):  Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry Longbowman Crossbowman Cho-Ko-Nu
Unit Upgrade (Skirmisher):  Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry Longbowman Crossbowman Cho-Ko-Nu
Unit Upgrade (Bowman):  Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry Longbowman Crossbowman Cho-Ko-Nu
Unit Upgrade (Longbowman):  Infantry SAM Infantry Mobile SAM Mechanized Infantry Rifleman Redcoat
Unit Upgrade (Crossbowman):  Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Cho-Ko-Nu):  Rifleman Redcoat Grenadier Infantry SAM Infantry Mobile SAM Machine Gun Mechanized Infantry
Unit Upgrade (Chariot):  Knight Camel Archer Cataphract Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (War Chariot):  Knight Camel Archer Cataphract Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (Immortal):  Knight Camel Archer Cataphract Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (Horse Archer):  Knight Camel Archer Cataphract Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (Numidian Cavalry):  Knight Camel Archer Cataphract Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (Keshik):  Knight Camel Archer Cataphract Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (Knight):  Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (Camel Archer):  Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (Cataphract):  Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (Conquistador):  Gunship Cavalry Cossack
Unit Upgrade (Cuirassier):  Gunship Cavalry Cossack
Unit Upgrade (Cavalry):  Gunship
Unit Upgrade (Cossack):  Gunship
Unit Upgrade (War Elephant):  Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (Ballista Elephant):  Conquistador Cuirassier Cavalry Cossack Gunship
Unit Upgrade (Tank):  Modern Armor
Unit Upgrade (Panzer):  Modern Armor
Unit Upgrade (Modern Armor): 
Unit Upgrade (Gunship): 
Unit Upgrade (Catapult):  Mobile Artillery Cannon Artillery
Unit Upgrade (Hwacha):  Mobile Artillery Cannon Artillery
Unit Upgrade (Trebuchet):  Mobile Artillery Cannon Artillery
Unit Upgrade (Cannon):  Mobile Artillery Artillery
Unit Upgrade (Machine Gun):  Mechanized Infantry
Unit Upgrade (Artillery):  Mobile Artillery
Unit Upgrade (Mobile Artillery): 
Unit Upgrade (Work Boat): 
Unit Upgrade (Galley):  Transport Galleon East Indiaman
Unit Upgrade (Trireme):  Frigate Destroyer Missile Cruiser Stealth Destroyer Attack Submarine Caravel Carrack
Unit Upgrade (Caravel):  Frigate Destroyer Missile Cruiser Stealth Destroyer Attack Submarine
Unit Upgrade (Carrack):  Frigate Destroyer Missile Cruiser Stealth Destroyer Attack Submarine
Unit Upgrade (Galleon):  Transport
Unit Upgrade (East Indiaman):  Transport
Unit Upgrade (Privateer):  Stealth Destroyer Destroyer Missile Cruiser
Unit Upgrade (Frigate):  Stealth Destroyer Destroyer Missile Cruiser
Unit Upgrade (Ship of the Line):  Stealth Destroyer Destroyer Missile Cruiser
Unit Upgrade (Ironclad):  Stealth Destroyer Destroyer Missile Cruiser
Unit Upgrade (Transport): 
Unit Upgrade (Destroyer):  Stealth Destroyer Missile Cruiser
Unit Upgrade (Battleship):  Missile Cruiser
Unit Upgrade (Missile Cruiser): 
Unit Upgrade (Stealth Destroyer): 
Unit Upgrade (Submarine): 
Unit Upgrade (Attack Submarine): 
Unit Upgrade (Carrier): 
Unit Upgrade (Airship):  Fighter Jet Fighter
Unit Upgrade (Fighter):  Jet Fighter
Unit Upgrade (Jet Fighter): 
Unit Upgrade (Bomber):  Stealth Bomber
Unit Upgrade (Stealth Bomber): 
Unit Upgrade (Guided Missile): 
Unit Upgrade (Tactical Nuke): 
Unit Upgrade (ICBM): 
Unit Upgrade (Great Prophet): 
Unit Upgrade (Great Artist): 
Unit Upgrade (Great Scientist): 
Unit Upgrade (Great Merchant): 
Unit Upgrade (Great Engineer): 
Unit Upgrade (Great General): 
Unit Upgrade (Great Spy):


Which all looks pretty dang good to me. I think this is good to go.
 
MA status ...

  • hide threat index if cannot see power - could include comment "n/a"?
  • hide strategic resource information if no tech and resource trading - see if I can include comment
  • remove strategic units if player can build an upgrade of a unit - thx to EFool's great code for this
  • cycle thru cities so that all units possible are included
  • expose all text to XML for multi-language support
  • BUG: If you open the MA with the Sit-Rep tab displayed, switching to the Units tab doesn't draw the minimap

MA status for future release ...

  • free up the main sort criteria (currently unit combat type) so that the user can select what it is - need drop down, refresh button and auto-refresh check box <-- EmperorFool has stuck his hand up for this one - good luck!
  • glance screen
  • worst enemy icon (only when patch has been released)

Currently working on cycling thru all cities to pick up all units that can be built.
 
I'm getting a Python error with the latest version -- trying to modify a dictionary while iterating over its items. I see the problem and will attempt a quick fix. I've attached the save that causes it.
 
the other solution to that python error is not to fall behind in tech! Thx for fixing this EFool
 
Fixed. I also added the cycling through all cities when checking whether or not a unit can be built.

One thing I see that may be incorrect, but I'm not sure yet, is that only the single AND prerequisite tech is checked. It ignores the other techs. This is at the point where it's removing enemy units you shouldn't know about yet due to limited tech.

I'd say look at the code that draws the unit buttons in the city screen. It will draw a disabled button, meaning you can't build it due to resource restrictions, but you do know how to.
 
Thanks.

I also added the cycling through all cities when checking whether or not a unit can be built.
I knew is was dead easy - just didn't have time to do it. Anyway, thanks.

One thing I see that may be incorrect, but I'm not sure yet, is that only the single AND prerequisite tech is checked. It ignores the other techs. This is at the point where it's removing enemy units you shouldn't know about yet due to limited tech.

I'd say look at the code that draws the unit buttons in the city screen. It will draw a disabled button, meaning you can't build it due to resource restrictions, but you do know how to.
Good point. I'm not sure of the code regarding the other pre-reqs. Your suggestion is where I originally looked and that is covered by the canTrain() function. There are some parameters that control if you have the knowledge to train a unit (parameter 3 = true IIRC) and can train but are missing a resource or already have the max allowed (parameter 3 = false IIRC).

Thus I had to try and work out the tech thing manually.
 
MA status ...

  • hide threat index if cannot see power - could include comment "n/a"?
  • hide strategic resource information if no tech and resource trading - see if I can include comment
  • remove strategic units if player can build an upgrade of a unit - thx to EFool's great code for this
  • cycle thru cities so that all units possible are included
  • expose all text to XML for multi-language support
  • BUG: If you open the MA with the Sit-Rep tab displayed, switching to the Units tab doesn't draw the minimap

MA status for future release ...

  • free up the main sort criteria (currently unit combat type) so that the user can select what it is - need drop down, refresh button and auto-refresh check box <-- EmperorFool has stuck his hand up for this one - good luck!
  • glance screen
  • worst enemy icon (only when patch has been released)

It seems that we are just working on tidy up bits. I should have the above all squared away by tomorrow and ready for a formal release.

Does anyone have a nice screenshot showing the sit-rep off?
 
Just posted about the BUG MA in the mod component thread as well as the Civ4 mod items announcement thread - will get specifically mentioned on the front page :D.
 
For the filtering checkboxes -- injured :yuck:, promotable (a star), can move :move:, upgradeable :strength: -- I'll need DDS graphics instead of the font glyphs. Is anyone particularly adept at The Gimp or some other graphics program and can make DDS versions (or find if they exist already) of these characters? If so, could you do the same for :food:, :hammers:, and :commerce:?
On second thought - I bet these are already available (ie they show up in the city bar and on the main interface). I'll try and track them down for you.
 
That would be great, thanks. For the Raw Yields changes to the city screen, the :traderoute: icon would also be helpful. :)

The deployment tab is coming along nicely. I completed the support code that will classify all units into any number of groupings. I have the four groupings listed above complete, except that promotions is only picking the first promotion. Shouldn't be too hard to make it do multiple.

The next step is getting that info into the window. One nice thing about the way I've coded it is that the list of units doesn't need to be reprocessed when you change groupings or filters; it will just redraw the list. Hopefully this will make the tab more usable.
 
Group selection is working great, and it's no slower than the original code. It still needs to process all units when you switch the leader selection, but I could do some work to change even that later.

I now have it drawing the list, so you can see the breakdowns and counts. I put counts on both groupings. Thus you'll see 11 units in enemy territory, as well as that 3 are Archer, 2 are Swordsman, etc.

Next is the selection code so you can limit which ones display on the minimap.

@Ruff - Do you have a sketched up layout for the dropdowns and buttons? I'm getting close to being ready to hook up some UI elements. :)
 
Look in 'C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Assets\XML\GameInfo\CIV4EmphasizeInfo.xml' for hammer, coin and food. These are pointers to the dds files that show the city manager buttons.

Still working on foot, unhealthy, arm and trade.
 
@Ruff - Do you have a sketched up layout for the dropdowns and buttons? I'm getting close to being ready to hook up some UI elements. :)
You posted something on the last page that looked ok to me ...

Code:
[-------- L E A D E R H E A D S ---------]

Group: [Menu1] [Menu2]    [--- L I S T ---]
Sort: [Menu]  [x Details]
[---- Filter Buttons ----]

[------- M A P --------]

Did we decide where you are putting the GG emergence bar?
 
Did we decide where you are putting the GG emergence bar?

I'll start with the bottom panel, between SIT-REP and EXIT since there's a lot of space there. We'll see how that looks.

As for the DEPLOYMENT tab, we are now at feature parity with the original MA insofar as the unit list has all the original features: drawing, selecting, and showing unit details.

I am now ready to hook up UI elements to allow you to change the groupings, sort and filters. I still need to code sorting and filtering, of course, but the original version doesn't have these either.

But first a lunch break. :) I'll commit the current version so people can play around with it.

Edit: I've committed it with Location and Unit Type as the default groupings. If you want to change these, go to lines 1193-4 in CvBUGMilitaryAdvisor.py and change the group keys:

PHP:
grouping1 = self.stats.getGrouping("loc")
grouping2 = self.stats.getGrouping("type")
Legal values are "loc", "type", "combat", and "promo". Remember, "promo" only shows the first promotion a unit has.
 
@Ruff:

Thanks for exposing to XML the text of MA, I've just translated it. :)
Can I ask you what "Def Packs" arel, so that I can translate that label accordingly? :blush:
Oh, and there is still a bit of text not in XML, that is the alert levels names.
Thaks again :)
 
Oh, and there is still a bit of text not in XML, that is the alert levels names.
DUH! Totally missed those. I'll XML (verb: to expose something to XML :D) them later today.
 
Defensive Pact: if you get attacked, I automatically declare war on your attacker.

Oh, yes thanks, I know what a Defensive PacT is, it was with a Defensive PacK that I had problems! :DDD
Ok, it may seem strange to you, but for a foreign guy like me it's not so easy to understand that a mistype is there (even when probably to you it's evident) in particular if it creates another valid word :blush:

Anyway, I translated it, and I also changed that "k" into a "t" for other languages. Thanks :)
 
Top Bottom