401
Tutorials and Tips / information on binding.py and the Weapon list
« on: December 04, 2008, 06:28:12 AM »
So, what are these numbers in the weapons list contained in binding.py ?
This numbers are assumed to be the Identifier of your weapons.
Each time you lost one, it is removed from this list.
By default, when this list is empty the strategy is changed.
This mean
* if your list is empty, whatever your AI is, the strategy used should be the
one define in 'LostComponent' function.
* if you put number that do not correspond to Weapon Identifier (which is mostly the case if your write 1,2,3,...) you will keep your strategy even if you loose all your weapons for this list will never be empty
Usage of this list :
* to be sure that your list contains the good weapons identifier, you may fill it yourself after having a look at yotur bot with a gmf decompiler. You may also add this code to your activate function, it build a correct list of weapons Id :
For instance, here is an usage of this list :
Fields of investigation : does the lostcomponent function is called for each component lost or only for weapons ? What happens if one put Id of motors or other components in its self.weapons list ?
Code: [Select]
...,'weapons':(1,2,3,4,5,6,7,8,9)}))
This numbers are assumed to be the Identifier of your weapons.
Each time you lost one, it is removed from this list.
By default, when this list is empty the strategy is changed.
This mean
* if your list is empty, whatever your AI is, the strategy used should be the
one define in 'LostComponent' function.
* if you put number that do not correspond to Weapon Identifier (which is mostly the case if your write 1,2,3,...) you will keep your strategy even if you loose all your weapons for this list will never be empty
Usage of this list :
* to be sure that your list contains the good weapons identifier, you may fill it yourself after having a look at yotur bot with a gmf decompiler. You may also add this code to your activate function, it build a correct list of weapons Id :
Code: [Select]
def Activate(self, active):
if active:
...
goon = 1
i = 0
self.weapons = []
while goon == 1:
if i == self.GetNumComponents(): break # to verifiy if i == ... or i > ...
currentType = self.GetComponentType(i)
if currentType == "Weapon": self.weapons.append (i)
i = i+ 1
return AI.SuperAI.Activate(self, active)
For instance, here is an usage of this list :
Code: [Select]
def __init__(self, **args):
AI.SuperAI.__init__(self, **args)
self.SpinTrigger = "Spin"
self.ServoTrigger = "Servo"
...
def LostComponent(self, id):
# if we lose all our weapons, stop using the Engage tactic and switch to Shove
if id in self.weapons: self.weapons.remove(id)
if len(self.weapons) < 4 :
# i have 2 motors mounted on a tri-bar extender.
# the last bar contains a hammer.
# my self.weapons list contains the Id of the weapons.
# when only 3 weapons remains, i swith my controler
# to make my servomotor spin much like a normal motor
# so the AI that controls the servo become useless
# my bot turn to a 'normal spinner'
self.SpinTrigger = "Servo"
self.ServoTrigger = "NOP" # does nothing
self.SpinSpeed = 100
return AI.SuperAI.LostComponent(self, id)
Fields of investigation : does the lostcomponent function is called for each component lost or only for weapons ? What happens if one put Id of motors or other components in its self.weapons list ?