Multi-Human Player Delema

You should be able to do everything using the basic code which already existed. I would imagine you customize yourself on a custom built python screen, with all options immediately presented to you?

If that is the case, then within the screen he has to handle the input actions you take. Find where those handles are made, and anywhere that he translates User Input to DLL Interface, change it to instead be a sendModNetMessage command. Then take the lines of code which talked with the DLL and define a new Python function for them which will be called by onModNetMessage, and run natively immediately after the sendMonNetMsg.


Something along these lines (PseudoCode):

Original:

Code:
if (userInput == Checkbox for iTrait clicked)
	pPlayer.changeTrait(iTrait, bCheckBoxChecked)
if (userInput == Civ Selected from DropDownList)
	CyGame.setCivilizationType(iPlayer, iChoiceFromDropDown)

New code would be something like:

Code:
if (userInput == Checkbox for iTrait clicked)
	sendModNetMessage(0, iPlayer, (int)bCheckBoxChecked, -1, -1)   #the 0 identifies this particular checkbox (Enumeration)
	ToggleCheckBox(0, iPlayer, (int)bCheckBoxChecked)
if (userInput == Civ Selected from DropDownList)
	sendModNetMessage(1, iPlayer, iCiv, -1, -1)  #The 1 indicates this particular Dropdown List (Enumeration)
	ChooseCivilization(iPlayer, iChoiceFromDropDown)

Then somewhere else in the same file you will create:
Code:
def ToggleCheckBox(self, iCheckBoxEnum, iPlayer, iChecked)
	if (iCheckBoxEnum == 0):
		if (iChecked == 1):
			pPlayer.changeTrait(iTrait, True)
		else:
			pPlayer.changeTrait(iTrait, False)

def ChooseCivilization(self, iPlayer, iChoiceFromDropDown)
	CyGame.setCivilizationType(iPlayer, iChoiceFromDropDown)

And in the onModNetMessage:
Code:
cp = CivPickerPythonFile().CivPickerPythonFile()
if (iData == 0)
	cp.ToggleCheckBox(0, iData2, iData3)
if (iData == 1)
	cp.ChooseCivilization(iData2, iData3)



Doing something like that, creating your own enumeration system to handle each possible user input option, will cover you for everything EXCEPT string values. ModNet can only really deal with Integers, and booleans and floats can be worked with if required, but doing a full string input would be difficult. I can't think of too many things where you should be able to use a string, so you should be fairly well set with this setup.


If the basic python file you are modding from has some areas where it tries to run multiple values at once (like assigning Civilization Colors and Flag choice all at once, total of 4 numbers), break it down into as few numbers as you can get away with for each individual call to the DLL. Since ModNet can only handle 5 numbers and you waste 2 of those identifying first WHAT to do, and next WHO to do it to. If forced to, you CAN send messages which store values in the local python's global variables temporarily until all of the required values have been gathered together, but this would run into issues if 2 computers attempt to manipulate those values at the same time (2 different players each attempt to select a specific flag). So instead you can try to predict combinations which will occur and pre-store those in a local array which can be referenced by a single integer (if flag 5 goes with colors 27, 147, 234 every time, you can store all 4 of those together in an array called Flag5, or as the 5th element in an array called FlagColors)


So the entire screen and all user input happens exactly how the original mod had it working. You just intercept where the python and the DLL attempt to talk and require that they include ModNetMsg in the conversation.
 
The screenshots show popups being used to make all the choices. For the traits, it has a button for each trait to toggle it on and off. One of the first requests was for buttons to remove all of that type of thing, i.e. remove all traits with one button.

From this you have 2 messages: Clear Traits and Toggle Trait. The second needs one parameter (the trait) while all messages require the player ID parameter. Just expand this example to the other popups as xienwolf explained above, and you should be set.
 
Actually followed the link this time. For the buildings/Units you would have to pass more variables.

(OperationEnum <tells ModNet you are working on Buildings/Units>, iPlayer, <Building/Unit>Class, <Building/Unit>Type <-1 for default>, -1 <because it isn't being used>)


The Leader selection and the Trait selection items shouldn't be too hard to manage.
 
So I just ran into a need to use onModNet myself today. I just now realized while getting ready to upload my changes that I hadn't written the code to work without using the message. So the sender of the message DOES also recieve it and obey what is written in onModNetMessage. No need to duplicate calls to a function for the code to work anywhere.
 
So I just ran into a need to use onModNet myself today. I just now realized while getting ready to upload my changes that I hadn't written the code to work without using the message. So the sender of the message DOES also recieve it and obey what is written in onModNetMessage. No need to duplicate calls to a function for the code to work anywhere.

Now that I have completed a couple of other tasks, it is time to once again turn my attention to this subject. I have one multiplayer question that I keep coming back to:

Question: Do I have to make all of the trait changes for every human player before the first player's turn or can the code wait and have each human player make their respective changes when their turn 1 actually starts?

I've always assumed all Civs had to be customised before the dawn of man popup came up for the first human player. Dales customiser makes all the changes on the first player, but does not work with multiplayer, as it repeats events. It would be interesting if the other human player changes were not dependent on the first human player, but can be performed separately at the beginning of each human player's turn. ...Not to mention, this could make the coding a whole lot easier. What do you and EmpererFool think?

Orion Veteran :cool:
 
I don't see how the information should have a significant impact on the other players, so you might be fairly safe waiting till each person's first turn. Main issue would be if they select a unique unit replacement for one of their starting units since all of those are already placed by the time the first player takes his turn.
 
Top Bottom