Quote: "Nothing at this point. Just my one question above about what data the AI function should return and I'll go back and give it another shot!"
Well, this can be tricky. I'll have to put the events in a tentative list to get an idea of the flow:
I. Main Menu
II. Setup Environment/Level
III. In Game
A. Player movement control
i. attempt movement
ia. Collision with objects
1. Impassable
a) check x and z for sliding collision
and adjust player coordinates accordingly
b) check y and adjust y coordinate
i. Exterior
use matrix ground height
ii. Interior
use collision test with floor or set height
within the bounds of the house. Check for bounds
and height for upstairs vs downstairs
c) position player at new coordinates
2. Creature
a) Same as Impassable
3. Stairs
a) Adjust y height by collision, get x and z position
b) position player at calculated coordinates
4. Moveable objects
a) World physics application (TBD)
B. Creature movement control
i. Loop through creatures
ia. Hide any not in camera view, show any in camera view
ib. Check for Interior or Exterior
1. Exterior
a) check current state of collision or proximity to player
i. If colliding gosub i. Collision
b) Check current and/or next waypoint
c) Point creature towards next waypoint (incremental rotate?)
d) Get X and Z coordinates
e) test y with ground height
f) Attempt to position creature
i. Collision
ia. With Player
1. reset x,y,z to previous
2. point creature at player
3. move creature to minimum attack proximity
4. Give the player a chance to attack first
a) Gosub Player attack
5. Give the creature a chance to attack
b) Gosub Creature attack
ib. Impassable objects
1. Rotate creature 90 degrees relative y (random left right)
2. reset x,y,z to previous x,y,z
3. calculate next X Z based on creature speed and current
y angle
4. get y height based on new X Z
5. Position creature
2. Interior
a)Check Zone of Creature and Player
i. Same Zone
ia. Point creature towards player
ib. Get Y from interior ground collision test or from set
height based on interior bounds and floor
ic. move creature
id. Gosub i. Collision
ii. Different zone
ia. Path-find from creature to player or to door
of zone the player is in
ib. Get X Z from path finding calculations
ic. Get Y from interior ground collision test or from set
height based on interior bounds and floor
id. Gosub i. Collision
C. Player Attack
D. Creature Attack
E. Physics
F. Menu
After my list, it would seem that the AI function, per se, doesn't really return anything but rather calculates and moves the creature on the spot. Looking at the list, the thing to avoid is sending each creature a specific function one at a time as that would really slow things down. The idea would be to loop through all of the creatures at once in a single function or sub and in the midst of checking the creature for interior,exterior or collision, jump to the proper subroutines to handle this. If the player movement and the creature movement both have to access the same routines (like combat or physics for example) then they have to be global - meaning they would have to be subroutines.
The pathfinding could be in a function if it calculated all of the creatures at once. The problem would be when other triggers (like bumping into the player) occur and the program has to jump to code to deal with that. It can't do that from inside the function unless the subroutines are also contained within the function - or each creature calls pathfinding one at a time (which could really hinder performance as the function is called multiple times) and then the other triggers are tested based on what the creatures' next move would be.
Can the pathfinding be done without being in a function or a sub but rather code in a loop? The reason I'm trying to move the pathfinding out of a function or it's own subroutine is because those jumps back and forth take away performance in the long run. It's faster to run straight code than to jump, run code, and come back.
So the layout of the code might look like:
_ai:
for cloop = 1 to total creatures
if exterior
run exterior code
gosub collision tests
gosub battle
else it's interior
if out of zone
straight code for pathfinding current creature
collision tests
battle
else
straight code for in zone point and pursue
collision tests
battle
endif
endif
next cloop
The reason I have other subroutines to call is because other parts of the program would use them (like the player) whereas pathfinding is only being used by the creature so there's no reason to have it as an extra function or subroutine but rather as code that's part of the ai loop of creatures.
In the main outline at the top of the post, in the design of the creature ai, you can just leave spaces/rems for the collision and the combat subroutines. Your ai should be able to function without these and be able to move your creatures around. Later, simply by adding the appropriate gosub, your code should be able to handle the additional routines without a hickup or any rewrite.
Quote: "...transitioning from state to state (especially as the player moves from inside to out) that I'm trying to get a grip on."
Hmmmm... Maybe we should eliminate the player going outside. That may simplify things. That would eliminate how to keep the player from just running around outside all day and eliminate the coding needed to keep the player within the bounds of the scene. Of course another option would be to solely use pathfinding for everything so the monsters always try to find a path to the player from anywhere on the board. Though that might mean all of the creatures crowd around 1 window trying to get at the player! So maybe not! But it might be a good idea to eliminate the going outside part altogether.
Or perhaps there are dedicated creatures to pursue the player outside. The other creatures keep getting into the house. Once in the house the "break in" creatures path-find or track to the player, but if the player leaves, they stay where they are if they are inside, and keep breaking in if they are outside.
On the outside, may be there are 3 or 4 patrol creatures that are wandering around the exterior of the house and run after the player if they leave. I kinda like that idea. That way there no cross over needed for the different states of interior or exterior in terms of pursuing the player. There is actually dedicated ai for each and dedicated creatures for each.
The level increases and game progression will be determined by killing the break in creatures. The roving creates are always constant. So if one gets killed it is automatically respawed and starts making it's way to attack. They would need a waypoint path also for their wandering or just a couple of patrol locations to move back and forth between, or they could randomly scramble around until the player is outside.
Enjoy your day.