Game Programming and Development Tools

Basic AI, and Movement Generalization problems. – Mene-Mene

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Ok, I've written a little RTS game which you have 4 classes of characters you can recruit, which are automated. Its 1d, and very simple. I've got almost everything worked out, but my characters don't move seprately.

I've used the For...Each Loop to make each character, but say the AI says move this Elf + 2 Location, it moves all 3 Elves! When I recruit a new Elf, I want that elf at the starting position, but instead it resets all the elves. My problem might lie in the fact that I created a Elf which is global without the for loop so it could be global. In other words, I'm kind of not really knowing what I'm doing. (Kind of Not really? What does this kid think he is?)

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto

SSquared

Member

Posts: 654
From: Pacific Northwest
Registered: 03-22-2005
In what language is this written? Knowing this will really help in explaining it. Someone who is familiar with the language may also be able to give a code example.

It sounds like you will need to maintain some type of collection (array) to hold all of your characters. Rather than making the Elf global, the collection is global. Going through the loop will just require you to iterate through the collection.

Each Elf should be created only when it is necessary. When it's created, simply add it to the collection. Your Elf must also have something unique to differentiate it from all the others. Somehow, you will need to know which one is selected. The unique value can just be the current position, assuming no other Elf can occupy the same spot. When someone clicks on an Elf, you loop through the Elf collection until you find the match.

Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Hi mene-mene! Hmm this is tricky, with so little information given but it sounds like that you are using the foreach loop not just to create the elves but also to move them?

------------------
1Jo 2:9-10 He that saith he is in the light, and hateth his brother, is in darkness even until now. 10 He that loveth his brother abideth in the light, and there is none occasion of stumbling in him.
Joh 17:26 And I have declared unto them thy name, and will declare it: that the love wherewith thou hast loved me may be in them, and I in them.

[VoHW] (Help needed) [Blog] - Truedisciple (mp3)

Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
Firstly this is in BB. Here's a summary:

Set up types
This says for the Elf
Global Elf.Character = New Character

Help function
Difficulty
This says
For a (Random Variable this just makes it go around the horn 2 times) = 1 to 2
Elf.Character = New Character
Next

MainMenu Function
Update Function
Update2 Function
Recruit Function

This says if player chooses Elf, Elf.Character = New Character.

Update PAI function This I will give you the exact code, don't worry about the other things except for the Elf, once I got the understanding, I can do the rest.


Function UpdatePAI()

For MC.Character = Each Character

If MC\Name$ = "Elf A."

For EC.Enemy = Each Enemy

If MC\Move = True

If EC\Name$ = "Wolf S."

If MC\Location =< (EC\Location + 5) And MC\Location => (MC\Location - 5)

EC\HP = EC\HP - MC\RA

Print "Informer: An Elf of yours attacked a Wolf of theirs."
MC\Move = False

Else

If MC\Location < 10

MC\Location = MC\Location + MC\Moves

Print "Informer: An Elf of yours moved closer to their cave."
MC\Move = False

EndIf


Else

If MC\Location => 10

Enemy\WallHP = Enemy\WallHP - MC\RA

Print "Informer: An Elf of yours attacked their cave."

MC\Move = False

Else

If MC\Location < 10

MC\Location = MC\Location + MC\Moves

Print "Informer: An Elf of yours moved closer to their cave."
MC\Move = False

EndIf

EndIf

EndIf
EndIf

EndIf
Next


ElseIf MC\Name$ = "Dwarf B."

If Player\WallHP < 100

Player\WallHP = Player\WallHP + MC\B

Print "Informer: A Dwarf Builder of yours repaired some of your wall."

EndIf

ElseIf MC\Name$ = "Dwarf D."

If MC\Name$ = "Wolf S."

If MC\Location = -15

MC\HP = MC\HP - MC\MA

Print "Informer: A Dwarf Defender of yours attacked a Wolf of theirs."

EndIf

EndIf

ElseIf MC\Name$ = "Man I."

If MC\Name$ = "Wolf S."

If MC\Location = MC\Location

MC\HP = MC\HP - MC\MA

Print "Informer: A Infantry Man of yours attacked a Wolf of theirs."

Else

If MC\Location = 15

Enemy\WallHP = Enemy\WallHP - MC\MA
Print "Informer: An Infantry Man of yours attacked their cave."

Else

MC\Location = MC\Location + MC\Moves
Print "Informer: An Infantry Man of yours moved closer to their cave."

EndIf

EndIf

EndIf

EndIf

Next


End Function

I hope this helps.

------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.
"Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto