Tower Siege 2

Thx alot i’m having trouble with the log thing that shoots the rock its just not working lol!

You mean the arm? Make an IPO, please don’t hijack this thread, post in the discussion forum.

sorry…

OK guys I just had a major brain fart in python =/ too much scripting! I just need a tip on how to simplify this task. So I have my siege unit, kay? I click it and it sets the selected object to siege, kay? Now when I right click on a tile what I need to do is set the position of an empty to this grid block. Now I could get the object list and find the siege empty, but then if I have multiple ones they’d all move at the same time. What I could do is make a property with the object name in it and then set the prop to the object to setPosition, but that would be way to much. Any ideas?

New question… how would I go about setting the orientation of the object in relation to the mouse? Like it the mouse clicks behind it does a 180?

empty + track to?

You’re saying I should add an empty at the position of click? Wow, such a simple solution! I’d going ahead and making a huge algorithm for it, lol. Do you know the answer to my other question?

Quick queston:

Will the soldiers in the game be controlled as squads, or as individual soldiers? Aoe does individual soldiers ( exept for Aoe 3 which allows creation of units as squads), I personally prefer squads of soldiers, but thats just my opinion. Keep up the good work, I like the catapult. :slight_smile:

AoE 2 allows squads =P I think I’ll do individual units.

Yes, AOE 2 has squads, sometimes you need them for huge armies because there’s only so many you can select at once.

If and when I get the actual movement and pathfinding done I’ll see about multiple selections.

You must be talking about the expantion packs for Aoe2, anyway its been a long time since I’ve played 2.

No Gold edition =D

AoE 2 is the best in the series. It’s one of the best strategy game of all time, up there beside starcraft.

OK guys I just had a major brain fart in python =/ too much scripting! I just need a tip on how to simplify this task. So I have my siege unit, kay? I click it and it sets the selected object to siege, kay? Now when I right click on a tile what I need to do is set the position of an empty to this grid block. Now I could get the object list and find the siege empty, but then if I have multiple ones they’d all move at the same time. What I could do is make a property with the object name in it and then set the prop to the object to setPosition, but that would be way to much. Any ideas?

You could use a dictionary.
Something like this:

GameLogic.siegeEmpties = {} # the dictionary
//////
if siege_unit_added:
    spawner.setPosition([x,y,z])
    addObject.setObject['siege_unit']
    addObject.instantAddObject()
    unit = addObject.getLastCreatedObject()
    addObject.setObject['siege_empty']
    addObject.instantAddObject()
    empty = addObject.getLastCreatedObject()

    GameLogic.siegeEmpties[unit] = empty

That way, you can get the empty by doing this:

if move_unit:
    GameLogic.siegeUnits[GameLogic.selectedUnit].setPosition([x,y,z])

You will encounter some problems though, like when you add the siege unit you will have to add the armature, this will also add the mesh. But you probably do the selected units by getting the mesh that the mouse is over when its clicked, so you have to get the mesh, it can be done like this:

if unit_added:
    addObject.setObject('siege_arm')
    addObject.instantAddObject()
    arm = addObject.getLastCreatedObject()
    obl = GameLogic.getCurrentScene().getObjectList()
    obl.reverse()
    for obj in obl:
        if obj.name == 'OBsiege_mesh': mesh = obj

Then you can store the armatures and empties in different dictionaries.

GameLogic.siegeArms[siege_mesh] = siege_arm
GameLogic.siegeEmpties[siege_mesh] = siege_empty

Then again you could use a class to sort it all:

class SiegeUnit:
    def __init__(self, mesh, arm, empty):
        self.mesh = mesh
        self.arm = arm
        self.empty = empty

# if you wanted it to follow some blender style you can add some methods:

    def getMesh(self):
        return(self.mesh)

    def getArmature(self):
        return(self.arm)

    def getEmpty(self):
        return(self.empty)

This way when you add a siege unit it would look like this:

if unit_added:
    addObject.setObject('siege_arm')
    addObject.instantAddObject()
    arm = addObject.getLastCreatedObject()
    obl = GameLogic.getCurrentScene().getObjectList()
    obl.reverse()
    for obj in obl:
        if obj.name == 'OBsiege_mesh': mesh = obj
    addObject.setObject['siege_empty']
    addObject.instantAddObject()
    empty = addObject.getLastCreatedObject()

    GameLogic.siegeUnits[mesh] = SiegeUnit(mesh, arm, empty)

Question answered?

The siege is controlled by an empty, if I add the empty everything else gets added. And oh my god, I can’t believe I never thought of using dicts! is the GameLogic.selectedUnit so it’s global?

Any attribute of GameLogic is global, so yes. And dictionaries can be so helpful, you should use them whenever possible.

Also I have another issue, how do I make children detect collisions?

this creates a new problem, the reason is because the object is always the same name (in this case SiegeUnit1 so it keeps overriding SiegeUnit1 entry in the dictionary with a new ID (how I’m telling them apart) Here’s what I was planning on doing:


		if lmb.isPositive() and own.activeObject == "siege" and own.timer >= 1:
			pos = own.getPosition()
			addObject.setObject("SiegeUnit1")
			addObject.instantAddObject()
			obj = addObject.getLastCreatedObject()
			objname = obj.getName()
			obj.setPosition([pos[0],pos[1],0.500])
			

			obj.ID = random.random()
			print obj.ID
			GameLogic.siegeUnits[random.objname] = obj.ID
			print GameLogic.siegeUnits

this is really frustrating!

Don’t use the name as the dictionary key, instead use the object itself, so:

GameLogic.siegeUnits[obj] = whatever