Problem with Waypoint plugin functions (FIXED)

Started by Besh, Tue 11/04/2006 22:06:31

Previous topic - Next topic

Besh

I have a problem with the WAYPOINT functions.
This an example code that print on screen the waypoints:

Code: ags
if (pEngine->GetCharacter(i)->walking > 0) {
   BITMAP *myscreen = pEngine->GetScreen();
   long wx, wy, num = pEngine->GetMovementPathWaypointCount(pEngine->GetCharacter(i)->walking);

   for (int cw = 0; cw < num; cw++) {
      pEngine->GetMovementPathWaypointLocation(pEngine->GetCharacter(i)->walking, cw, &wx, &wy);
      circle(myscreen, wx * game_scale, wy * game_scale, 2, makecol(255,0,0));
   }
					}


if I click during the character is walking the engine crash.
Moreover when character starts to moving the walking variable assume different values before assuming a steady value (in my example 21).
"Spread our codes to the stars,
You can rescue us all"
- Muse

Pumaman

Ah ok I might have made a mistake in the docs.

What happens if you change this:

if (pEngine->GetCharacter(i)->walking > 0) {

to this:

if ((pEngine->GetCharacter(i)->walking > 0) && (pEngine->GetCharacter(i)->walking < 1000)) {

does that then work?

Besh

#2
OK, now works fine.

The least significant digit remain the same (21) also when the variable assumes values > 1000 (eg. 1021 or 3021).
Is this value a fixed one??? (like the x y speed values)


EDIT:
Code: ags

int walknum = pEngine->GetCharacter(i)->walking;

// adjust
while (walknum >= 1000)
Ã,  Ã, walknum -= 1000;

if (walknum > 0) {
Ã,  Ã, long wx, wy, num = pEngine->GetMovementPathWaypointCount(walknum);

Ã,  Ã, for (int cw = 0; cw < num; cw++) {
Ã,  Ã,  Ã,  pEngine->GetMovementPathWaypointLocation(walknum, cw, &wx, &wy);
Ã,  Ã,  Ã,  // circle( ... );
Ã,  Ã, }
}


What do you think about this???
"Spread our codes to the stars,
You can rescue us all"
- Muse

Pumaman

#3
Yes, that should work as a workaround; I'll fix it properly in the next beta.

Edit by strazer:

AGS v2.72 RC 1:
* Fixed plugin API waypoint functions crashing when the path id was > 1000

Besh

#4
I have noticed that the variable walking assumes values > 1000 when the character changes loop.
If the two things are connected it would be a useful info.

CIAO


EDIT:
The engine calc the wp speed when the path is generated. How I can change the wp speed while the character is walking?
"Spread our codes to the stars,
You can rescue us all"
- Muse

Scorpiorus

Quote from: Besh on Wed 26/04/2006 15:48:34The engine calc the wp speed when the path is generated. How I can change the wp speed while the character is walking?

My thoughts...

According to the AGS manual you can't change characters' speed while their moving. You have to stop them first, then change the speed and run the pathfinder (MoveCharacter) once again.

So I'm not certain you are supposed to change waypoint speeds either. I believe that's how the pathfinder works.

The GetMovementPathWaypointSpeed() function returns x/y velocities; so even if it were possible to alter them, both speed components should proportionately be changed at once in order to keep direction of the speed vector intact (so that a character could reach the next waypoint).

My guess is, the pathfinder uses character speed property and walkable area mask as input parameters to construct a path, and thus the waypoints and a set of speedX/speedY are result (output) of calculation. Therefore, you need to tweak input parameters and tell it to recalculate a path, if you want a different speed of movement.

Also, there is a related entry I've found on the tracker: http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=247

Pumaman

Yes, if walking is >= 1000 then the character is currently turning rather than moving.

You can't change the speed while the character is moving, as Scorpious has explained.

Besh

OK, Thank you very much.

If it is possible, in which way the value >= 1000 are related to the character turning???

Thanks again,
CIAO
"Spread our codes to the stars,
You can rescue us all"
- Muse

Pumaman


int walkingValue = character->walking;

int is_turning_anticlockwise = walkingValue / 10000;
walkingValue %= 10000;

int number_of_loops_left_to_turn = walkingValue / 1000;

SMF spam blocked by CleanTalk