Naval Mines

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
I have created a naval mine in XML. The graphics appear to be good. :) I have given the naval mine attributes that are similar to the Privateer. The problem is: When I make the naval mine invisible, the enemy ships fail to enter into combat with the mine. :confused: I want to make the invisible naval mine explode any time an enemy ship passes through or stops on the sea plot, where the mine resides.

Any ideas?

Orion Veteran :cool:
 
The problem is: When I make the naval mine invisible, the enemy ships fail to enter into combat with the mine.

Well, that's what the invisibility is there for.

For the mechanis:
I would add some code after onUnitMove (okay, i would not really do that, because the AI does completly not understand it), where it's checked, if there's a mine on that tile, if you're in war with that civ, and then i would damage the unit by hand and destroy the mine.
 
Well, that's what the invisibility is there for.

For the mechanis:
I would add some code after onUnitMove (okay, i would not really do that, because the AI does completly not understand it), where it's checked, if there's a mine on that tile, if you're in war with that civ, and then i would damage the unit by hand and destroy the mine.

Yup. :yup: That's the Python method, which the AI won't understand. I was really hoping and looking for an XML answer. :sad:

Remember, I have given the naval mine attributes similar to the Privateer, which includes hidden nationality. In this way a naval mine could sink a ship from any civ without declaring to war. :mwaha: The invisible feature would make unexpected explosions happen and require a mine sweeper to be deployed to clear out the mines. Adding naval mines to the game would increase the potential for a lot of fun. :bounce:

Any other ideas before I attempt the Python method?

Orion Veteran :cool:
 
well this would be just perfect for ACW. I even have a tech called naval mines, and need to create a unit similar to this myself. I'll be watching this thread, hope you figure it out.
 
I'm having difficulty getting the Class for the moving pUnit in the function onUnitMove in CvEventManager. I can get the description or name, but not the class. I've tried everything I can think of for several hours and it still fails to show the class name in an Immediate Message. PyPlayer(pUnit.getUnitClass()) and getUnitClassType fails.

This works for the Name, but not the Class Name:
Code:
unitInfo = PyInfo.UnitInfo(pUnit.getUnitType())

CyInterface().addImmediateMessage(unitInfo.getDescription(), "").

I can't even get the type to work:

Code:
if pUnit.getUnitType() = gc.getInfoTypeForString("UNIT_DESTROYER"):

Any ideas for how I can get the Class Name or Unit type for pUnit?

Orion Veteran :cool:
 
OK, we are almost there. After many hours of work, I am able to identify an enemy mine, called pUnit1; and I have identified the unit that has stumbled upon the mine, called pUnit2.

My question is: Using Python, how can I force pUnit1 and pUnit2 to engage in combat?

Respectfully,

Orion Veteran :cool:
 
Easy answer: You can't, as far as i know :(.
Adding an unbuildable, but visible mine to the game, and replace the invisible with the visible one would maybe work.

Drat! :wallbash: OK then. I will just make the mine lethal and have it sink one ship in a stack. :yup:

It is all working! :) Now for the effects.

Question: How can I execute a Movie file and or a sound file, based upon a given path, using python? ...Not XML.


Orion Veteran :cool:
 
A graphical effect, and presumably a sound, can be triggered as we were just discussing in this adjacent thread.

Are you looking to trigger a movie when the mine explodes? I don't know how to do that. It may be that you want something like the popup you get when a random event happens. You can trigger a random event in python; you can see the details in the random event tutorial. There is also a modcomp which allows you to add a static image to the random event popups. I can give more details if this is what you want, and you cannot find from these brief mentions.
 
At first I wanted a video, but decided a good sound file will do just fine. I ended up using this line of code to run a WAV file that I created.

Code:
CyAudioGame().Play2DSound("AS2D_SHIP_EXPLOSION")

Next on my list is development of the Mine layer and sweeper ships. When I finish and publish the mod, I will post the final working version of the code here.

So without further do: Does anyone know of any predeveloped graphic files that might be ideal for the Mine Sweeper and Mine Layer ships?

Orion Veteran :cool:
 
So without further do: Does anyone know of any predeveloped graphic files that might be ideal for the Mine Sweeper and Mine Layer ships?

Any of these might do, based off a simple perusal of the download database. Of course, if a mine-laying/mine-sweeping ship is supposed to have different features than a typical destroyer/cruiser, then they might not work...
 
I found the perfect minesweeper graphic for you.

Spoiler Cuz it's that good! :
506x363-minesweeper.jpg
 
Aren't we being witty today. :)
 
I found the perfect minesweeper graphic for you.

Fortunately, the graphic I found looks like a ship. :lol:

On a serious note: I have an action button for the removal of a mine from a plot. I have two problems with it.

1. I want the execution of the action button to use up a movement point for the Minesweeper Ship.

2. I want the button to disappear after I click on it to remove the mine. Right now it stays visible until I use the mouse to put the focus on something else.

The Mineware mod is a huge project, but is developing nicely. :)

Orion Veteran :cool:
 
1. I want the execution of the action button to use up a movement point for the Minesweeper Ship.

pUnit.setMoves(pUnit.getMoves()-1)

2. I want the button to disappear after I click on it to remove the mine. Right now it stays visible until I use the mouse to put the focus on something else.

Did you modify CvMainInterface.py to draw the action button? Then you have some condition already, for whether the button should be drawn. For example, it should only be drawn for a minesweeper ship. So you can add more conditions. Do you already test to see whether there is a mine in the plot? If not, I think you can add that condition. In the redraw after the mine is gone, the condition should now fail.
 
I want the button to disappear after I click on it to remove the mine. Right now it stays visible until I use the mouse to put the focus on something else.

Normally you would find in CvMainInterface where your action button is drawn. Then find where that function is called in the same file. There's a function that has what is essentially a long switch statement checking each dirty bit and calling the appropriate draw function. You just need to set the dirty bit that is responsible for calling the button-drawing function.

And here's the answer:

Code:
CyInterface().setDirty(InterfaceDirtyBits.[B]SelectionButtons_DIRTY_BIT[/B], True)

These dirty bits tell the engine to update various portions of the screen on the next update cycle. It allows many things to cause a portion of the screen to need a redraw without slowing the game down by redrawing that portion for each change.
 
OK the setDirty command works great. However, the line to reduce the number of movement point on the minesweeper failed to work. See red lines:

Here are my functions:

Spoiler :

Code:
def handleInput (self, inputClass):
# Mine Warfare Mod
	EliminateMines=CvEventInterface.getEventManager()
		
	# Eliminates Mines from plot
	if (inputClass.getNotifyCode() == 11 and inputClass.getData1() == 777 and inputClass.getData2() == 777):
		self.pPushedButtonUnit = g_pSelectedUnit
		iX = self.pPushedButtonUnit.getX()
		iY = self.pPushedButtonUnit.getY()
		pPlot = CyMap().plot(iX, iY)
		iOwner = g_pSelectedUnit.getOwner()
		iUnitID = g_pSelectedUnit.getID()			
		pPlayer = gc.getPlayer(iOwner)
		pUnit = pPlayer.getUnit(iUnitID)
		[COLOR="red"][B]pUnit.setMoves(pUnit.getMoves()-1)[/B][/COLOR]
		MineWarfare.doMineSweep(pUnit )
		CyInterface().setDirty(InterfaceDirtyBits.SelectionButtons_DIRTY_BIT, True)			
			
# End Mine Warfare Mod
	
	return 0


Spoiler :

Code:
				if (CyInterface().canDeleteGroup()):
					screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_BUTTONS_SPLITGROUP").getPath(), 0, WidgetTypes.WIDGET_DELETE_GROUP, -1, -1, False )
					screen.show( "BottomButtonContainer" )
						
					iCount = iCount + 1
						
# Mine Warfare Mod
#				# ##### Naval Mine Sweeper Unit Button ######
				pUnit = g_pSelectedUnit
				iUnitType = pUnit.getUnitType()
				iUnitOwner = pUnit.getOwner( )
				pUnitOwner = gc.getPlayer(pUnit.getOwner( ))
				iPlotX = pUnit.getX()
				iPlotY = pUnit.getY()
				pPlot = CyMap().plot(iPlotX, iPlotY)
				iUnitMineSweeper = gc.getInfoTypeForString("UNIT_NAVAL_MINE_SWEEPER")
					
				if pUnitOwner.isTurnActive( ):
					if iUnitType == iUnitMineSweeper:
						if not pPlot.isCity():
							if MineWarfare.hasEnemyNavalMine(pPlot, iUnitOwner):
								screen.appendMultiListButton( "BottomButtonContainer", ArtFileMgr.getInterfaceArtInfo("INTERFACE_RADAR_SCREEN").getPath(), 0, WidgetTypes.WIDGET_GENERAL, 777, 777, False )
								screen.show( "BottomButtonContainer" )
								iCount = iCount + 1
								return
# End Mine Warfare Mod		
		
	elif (CyInterface().getShowInterface() != InterfaceVisibility.INTERFACE_HIDE_ALL and CyInterface().getShowInterface() != InterfaceVisibility.INTERFACE_MINIMAP_ONLY):
		
		self.setMinimapButtonVisibility(True)

	return 0


Spoiler :

Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
from CvPythonExtensions import *
import CvUtil
import CvTechChooser
import traceback
import os
import sys
import PyHelpers
import pickle
import CvGameUtils
import CvEventInterface

# for C++ compatibility
false=False
true=True

# globals
gc = CyGlobalContext()
PyPlayer = PyHelpers.PyPlayer

def hasEnemyNavalMine(pPlot, ActivePlayer):
	iUnitNavalMine = gc.getInfoTypeForString("UNIT_NAVAL_MINE")
	EnemyMine = False
	
	for iUnitLoop in range (pPlot.getNumUnits()):
		xUnit = pPlot.getUnit(iUnitLoop)
		iPlayer = xUnit.getOwner()
		# Is this a mine?
		if xUnit.getUnitType() == iUnitNavalMine:
			# Is this an enemy mine?
			if iPlayer != ActivePlayer:
				#CyInterface().addImmediateMessage("Found Enemy Mine", "")
				EnemyMine = True
				break
	
	if EnemyMine:
		return True
	else:
		return False


def doMineSweep(pUnit):
	iPlayer = pUnit.getOwner( )	
	iUnitNavalMine = gc.getInfoTypeForString("UNIT_NAVAL_MINE")
	pPlot = CyMap( ).plot( pUnit.getX( ), pUnit.getY( ) )
			
	# Loop through all enemy mines on the plot and remove them
	for iUnitLoop in range (pPlot.getNumUnits()):
		pUnitX = pPlot.getUnit(iUnitLoop)
		# Is this a mine?
		if pUnitX.getUnitType() == iUnitNavalMine:
			# Is this an enemy mine?
			if pUnitX.getOwner() != pUnit.getOwner():
				pUnitX.kill( 0, -1 )				
				[COLOR="red"][B]pUnit.setMoves(pUnit.getMoves()-1)[/B][/COLOR]
				CyInterface().addImmediateMessage("You have removed an enemy mine!", "")
				CyAudioGame().Play2DSound("AS2D_SHIP_LOAD_MINE")				
				break


Orion Veteran :cool:
 
Back
Top Bottom