[messages] [Module General Discussion] Some help with building custom code

capi3101 capi3101a at netscape.net
Wed Sep 4 06:51:52 MST 2013


Howdy.

I'm turning my attention now to another upcoming problem I've got with
my upcoming _Wing Commander Armada PNP_ mod. Right now, I'm trying to
see if it will be necessary to write a custom piece of Java code to
handle what I want to do or if VASSAL can handle it natively. Problem
I've got is that I'm not a Java programmer, though I do know Python and
I've been around the block enough to know working in another language is
a matter of just learning the necessary syntax.

Okay, so here's the issue: I've got VASSAL handling four Global
properties - Confederation Group Strength, Confederation Group Maneuver,
Kilrathi Group Strength and Kilrathi Group Maneuver. What I'd like to do
is tell the game which side is attacking and have it calculate the ratio
of the Strengths and the difference of the maneuvers from the attacker's
point of view. I figure I can do this with a pair of buttons on the
battle board. The return would be a text message which would then be
displayed on the battle board.

Here's how I'd do it in Python:

Code:

def sz_battleCalculate(self, ConStr, ConMan, KilStr, KilMan, Confed):
    strRatio = 0.0
    maneuver = 0
    ratioString = ""

    if (ConStr != 0) and (KilStr != 0):
        if ConStr > KilStr:
            strRatio = ConStr/KilStr
        elif Constr < Kilstr:
            strRatio = KilStr/Constr
        else:
            strRatio = 1.0

        if Confed == True:
            maneuver = ConMan - Kilman
            if ConStr > KilStr:
                ratioString = ("%.1f:1" % (strRatio))
            else:
                ratioString = ("1:%.1f" % (strRatio))
        else:
            maneuver = KilMan - Conman
            if KilStr > ConStr:
                ratioString = ("%.1f:1" % (strRatio))
            else:
                ratioString = ("1:%.1f" % (strRatio))

        return "Strength Ratio: " + ratioString + ", Maneuver Bonus :" +
str(maneuver)
        
    else:
        return "At least one player does not have their forces on the
Battle Board."




The routine accepts the four Global properties as arguments and a fifth
argument, Confed, is a Boolean that asks whether the Confederation side
is the attacker. After setting up dummy variables, the routine checks to
see if one side has a Strength of zero (i.e. they have no pieces on the
battle board), if that's the case, it says so right away - this avoids
the potential division by zero error. If both sides have pieces on the
board, it then calculates the strength ratio as a floating point
variable based on which side has the higher Strength value. It then
builds the ratio string and calculates the difference in Maneuver scores
based on who's attacking, and finally builds the final message to
return. Pretty straight forward.

So how about it? Can VASSAL do something like this natively? If so, how
(I've yet to figure out how to do conditional statements like this in
the engine)? If not, what's the Java equivalent?

_______________________________________________
Read this topic online here:
http://www.vassalengine.org/forum/viewtopic.php?p=41932#p41932


More information about the messages mailing list