Need Help on adapting code

Castor_Troy

Warlord
Joined
Jun 4, 2007
Messages
145
Location
Romania
Hello, I recently moved onto the SDK since it open immense new features to Civ gameplay, but as I am not a C++ knower I got stuck a bit on a problem.It is related to the FFH2 code about CreateUnitOnCombat. Copy and pasteing the code isnt enough since I dont have a Alive system, nor the hidden nationality promotion, nor a immunity to capture so the red lines i think can dissapear as for the yellow I think that has to be changed to something that says check the xml to see what type of unit to create (my guess).
I would apreciate if any of the experienced / knowers of C++ can take a look and suggest the changes. The code im reffering too is in the spoiler:

Spoiler :
Code:
 if (m_pUnitInfo->getUnitCreateFromCombat() != NO_UNIT)
    {
[COLOR="Red"]        if (!pLoser->isImmuneToCapture() && pLoser->isAlive() && GC.getUnitInfo((UnitTypes)pLoser->getUnitType()).getEquipmentPromotion() == NO_PROMOTION[/COLOR])
        {
            if (GC.getGameINLINE().getSorenRandNum(100, "Create Unit from Combat") <= m_pUnitInfo->getUnitCreateFromCombatChance())
            {
                pUnit = GET_PLAYER(getOwnerINLINE()).initUnit((UnitTypes)m_pUnitInfo->getUnitCreateFromCombat(), plot()->getX_INLINE(), plot()->getY_INLINE());
[COLOR="Yellow"]                pUnit->setDuration(getDuration());[/COLOR]
[COLOR="Red"]                if (isHiddenNationality())
                {
                    pUnit->setHasPromotion((PromotionTypes)GC.getDefineINT("HIDDEN_NATIONALITY_PROMOTION"), true);
                }
                iUnit = NO_UNIT;[/COLOR]
            }
        }
    }

Thank you for your time and patience!
 
I'm not very knowledgeable either, so I can't help you out. But a couple of general issues that would help others, and maybe even myself to figure out how to assist you:
First, put your code in [code]codeFoo[/code] tags. The [code] tags allow others to read things more easily as whitespace is retained. Secondly you are asking some pretty specific questions relating to Fall From Heaven which many of us just wol't understand. I have no idea what you're trying to do after reading your post, so it's impossible for me to help, even if I did understand how; it generally helps to be very precise, concise, and specific in this forum.
 
unless your mod has the spellcasting system from FFH you can also remove the duration line.
 
Phungus420: Thank you very much for the advices you are right, I didnt paied enough attention when posting I guess being tired took its tool, now that i read it Its quind of a babelfish english, also wrapped in code now.

Sephi: I see so that line can go also and what remains will do the creating unit on combat victory. I`ll try it
 
Are you trying to create a unit like a slave after a combat win? There are several pure python mods which do this. You are starting with vanilla code. It may be easier to add a pure python mod, rather than starting with FFH code and then removing all the FFH parts. Searching "slave" in the download database gives this, this, and this as possible starting points.
 
Yes that was my purpose to find a quind of Enslavement mod, I knew about the python but I thought I would try something more cleaner and XML editalbe and also adding some more stuff to the .DLL, but it seems it only left me with a bugged .DLL and now all that work to merge jUnitSpace and some other FFH promotions was wasted since i didnt mark all the things i imported from FFH and have to start on a clean version and add them again.

Also I got another question its related to the Defense scenario that Civ IV comes with i selected the bits used by the Zombie Unit to spawn more zombies but i cant get it to spawn the units of barbarian nationality. Here is the code(CvEventManager):
Spoiler :
Code:
	def onCombatResult(self, argsList):
		'Combat Result'
		pWinner,pLoser = argsList
		playerX = PyPlayer(pWinner.getOwner())
		unitX = PyInfo.UnitInfo(pWinner.getUnitType())
		playerY = PyPlayer(pLoser.getOwner())
		unitY = PyInfo.UnitInfo(pLoser.getUnitType())

########ZOMBIE START#############
		if pWinner.getUnitType() == CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(), "UNIT_ZOMBIE"):
			self.spawnUnit( [COLOR="Red"]1[/COLOR],"UNIT_ZOMBIE", pWinner.getX() ,pWinner.getY(), UnitAITypes.UNITAI_ATTACK)
########ZOMBIE END##############
The number seems to be tied to the player so if i put 0 i get myself, 1 seems to be for the next player. How do i make it Barbarian owned?
And this part is at the end of the file:
Spoiler :
Code:
###### ZOMBIE START ######
	def spawnUnit(self, Player, unit, X, Y, AIType):
		gc.getPlayer(Player).initUnit(CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(), unit), X, Y, AIType, DirectionTypes.NO_DIRECTION)
###### ZOMBIE END ########


EDIT: Nvm my question I found the answer since the dll usned a 50 civs it was 50 and not 18 as i tried the 1st time, so scratch the question.
 
Better than using 50 or 18, use the MAX_CIV_PLAYERS variable itself. Then if your mod ever changes to a max other than 50, this corrects itself.
I see, thanks its far more efficient that way. Also I would require a bit of help on this part of the code(Defensive scenario) it was the Samurai unit that deals damage to adjacented plots. I adapted it to come with a promotion but there seems to be a problem with it. When I use a unit that has the BESERKER promotion on an enemy the AOE damage it should deal to the enemy doesnt insted it hits my own units. When an enemy uses a unit with that promotion everything is ok he damages all of my units adjacented to the targeted one. Can someone help me and change the code for me so that this wont happen, I think its a simple change around the NO_PLAYER if it would be very complicated then dont bother as I dont want anyone to take too much of his time with this.
Here is the code in 2 parts(CvGameUtils):
Code:
	def doCombat(self,argsList):
		pSelectionGroup, pDestPlot = argsList
		iNumUnits = pSelectionGroup.getNumUnits()

####BESERKER START####
		for i in range( iNumUnits ):
			pUnit = pSelectionGroup.getUnitAt(i)
			
			if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BESERKER')):

		#####if pUnit.getUnitType() == CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(), "UNIT_SAMURAI"):########

				pPlot = pUnit.plot()
				self.doAEDamage( pDestPlot.getX( ), pDestPlot.getY( ) )
####BESERKER END######


Code:
	#######Beserker START#######

	def doAEDamage( self, iX, iY ):
		self.doPlotPlayerDamage( 5, iX-1, iY )
		self.doPlotPlayerDamage( 5, iX-1, iY-1 )		
		self.doPlotPlayerDamage( 5, iX, iY-1 )
		self.doPlotPlayerDamage( 5, iX+1, iY-1 )
		self.doPlotPlayerDamage( 5, iX+1, iY )
		self.doPlotPlayerDamage( 5, iX+1, iY+1 )
		self.doPlotPlayerDamage( 5, iX, iY+1 )
		self.doPlotPlayerDamage( 5, iX-1, iY+1 )

	def doPlotPlayerDamage( self, iValue, iX, iY ):
		if gc.getMap( ).plot( iX , iY ).isUnit( ):
			numUnits = gc.getMap( ).plot( iX , iY ).getNumUnits( )
			for i in range( numUnits ):
				if gc.getMap( ).plot( iX , iY ).getUnit( i ).getOwner( ) == 0:
					 gc.getMap( ).plot( iX , iY ).getUnit( i ).changeDamage( iValue, [COLOR="Red"]PlayerTypes.NO_PLAYER[/COLOR] )
					 gc.getMap( ).plot( iX , iY ).getUnit( i ).NotifyEntity( MissionTypes.MISSION_GREAT_WORK )
	#######Beserker END##########

Ok because it seems my english is like a dog chaseing his tail sometimes i`ll explain one more time . The promotion doesnt fully workas it should meaning if I have a unit with this promotion it wont damage my enemies instead it will damage me, for my enemies when they are attacking me it works as it should, it works ok only vs the human player i think:confused:

Again thank you for your time and I hope there is a simple fix to this.
 
Your problem is here:

if gc.getMap( ).plot( iX , iY ).getUnit( i ).getOwner( ) == 0:


getOwner() == 0 means you always check if it is the first player, which is the Human in a single player game. Instead, during doCombat you need to check who owns the berserker and ensure that you get a player number for that owner, then make sure that damage is dealt to all units EXCEPT those belonging to that player number.
 
I think im missing something here as the promotion wont work on anyone it should deal damage to the unit that are not belonging to pPlayer (theone with BERSERKER promotion.)
Code:
####BESERKER START####
		for i in range( iNumUnits ):
		pUnit = pSelectionGroup.getUnitAt(i)
			
			if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BESERKER')):
				[COLOR="Red"]pPlayer = gc.getPlayer( pUnit.getOwner( ) )[/COLOR]

				pPlot = pUnit.plot()
				self.doAEDamage( pDestPlot.getX( ), pDestPlot.getY( ) )
####BESERKER END######


Code:
	#######Beserker START#######

	def doAEDamage( self, iX, iY ):
		self.doPlotPlayerDamage( 5, iX-1, iY )
		self.doPlotPlayerDamage( 5, iX-1, iY-1 )		
		self.doPlotPlayerDamage( 5, iX, iY-1 )
		self.doPlotPlayerDamage( 5, iX+1, iY-1 )
		self.doPlotPlayerDamage( 5, iX+1, iY )
		self.doPlotPlayerDamage( 5, iX+1, iY+1 )
		self.doPlotPlayerDamage( 5, iX, iY+1 )
		self.doPlotPlayerDamage( 5, iX-1, iY+1 )

	def doPlotPlayerDamage( self, iValue, iX, iY ):
		if gc.getMap( ).plot( iX , iY ).isUnit( ):
			numUnits = gc.getMap( ).plot( iX , iY ).getNumUnits( )
			for i in range( numUnits ):
				if gc.getMap( ).plot( iX , iY ).getUnit( i ).[COLOR="red"]getOwner( ) != pPlayer[/COLOR]:
					 gc.getMap( ).plot( iX , iY ).getUnit( i ).changeDamage( iValue, PlayerTypes.NO_PLAYER )
					 gc.getMap( ).plot( iX , iY ).getUnit( i ).NotifyEntity( MissionTypes.MISSION_GREAT_WORK )
	#######Beserker END##########
 
Code:
	#######Beserker START#######

	def doAEDamage( self, iX, iY ):
		self.doPlotPlayerDamage( 5, iX-1, iY )
		self.doPlotPlayerDamage( 5, iX-1, iY-1 )		
		self.doPlotPlayerDamage( 5, iX, iY-1 )
		self.doPlotPlayerDamage( 5, iX+1, iY-1 )
		self.doPlotPlayerDamage( 5, iX+1, iY )
		self.doPlotPlayerDamage( 5, iX+1, iY+1 )
		self.doPlotPlayerDamage( 5, iX, iY+1 )
		self.doPlotPlayerDamage( 5, iX-1, iY+1 )

	def doPlotPlayerDamage( self, iValue, iX, iY ):
		if gc.getMap( ).plot( iX , iY ).isUnit( ):
			numUnits = gc.getMap( ).plot( iX , iY ).getNumUnits( )
			for i in range( numUnits ):
				if gc.getMap( ).plot( iX , iY ).getUnit( i ).[COLOR="red"]getOwner( ) != pPlayer[/COLOR]:
					 gc.getMap( ).plot( iX , iY ).getUnit( i ).changeDamage( iValue, PlayerTypes.NO_PLAYER )
					 gc.getMap( ).plot( iX , iY ).getUnit( i ).NotifyEntity( MissionTypes.MISSION_GREAT_WORK )
	#######Beserker END##########

Sorry if I'm disturbing this thread, but I think you can't do that in red because you haven't passed the variable to this "function". So your checking if the unit that needs to be damaged owner is different than the damaging unit's, without defining pPlayer first.
 
Good point. The original poster must not have python exceptions turned on. This makes it easier for the developer to catch simple errors like this, instead of requiring help from volunteers on the forum.
 
Top Bottom