version 1.9 | | version 1.10 |
---|
| | |
/* | | /* |
* static char *rcsid_anim_c = | | * static char *rcsid_anim_c = |
* "$Id: anim.c,v 1.9 2001/11/04 20:22:55 michtoen Exp $"; | | * "$Id: anim.c,v 1.10 2001/11/28 04:44:41 michtoen Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
} | | } |
| | |
/* | | /* |
* animate_object(object) updates the face-variable of an object. | | * animate_object(object, count) updates the face-variable of an object. |
* If the object is the head of a multi-object, all objects are animated. | | * If the object is the head of a multi-object, all objects are animated. |
*/ | | */ |
| | |
void animate_object(object *op) { | | void animate_object(object *op, int count) { |
int max_state; /* Max animation state object should be drawn in */ | | int max_state; /* Max animation state object should be drawn in */ |
int base_state; /* starting index # to draw from */ | | int base_state; /* starting index # to draw from */ |
int dir; | | int dir; |
register object *oph = op; | | register object *oph = op; |
| | |
| | #ifdef DEBUG /* hm, should really not happens */ |
if(!op->animation_id || !NUM_ANIMATIONS(op)) { | | if(!op->animation_id || !NUM_ANIMATIONS(op)) { |
LOG(llevError,"Object lacks animation.\n"); | | LOG(llevError,"Object lacks animation.\n"); |
dump_object(op); | | dump_object(op); |
return; | | return; |
} | | } |
++op->state; /* increase draw state */ | | #endif |
| | |
| | /* a animation is not only changing by anim_speed. |
| | * If we turn the object by teleporter for example, its direction & facing can |
| | * change, outside the normal animation loop. |
| | * We have then to change the frame and not increase the state */ |
| | |
/* when we change to "one arch/one png, we must use this also for */ | | /* when we change to "one arch/one png, we must use this also for */ |
/* the code above ... only the head then has an animation */ | | /* the code above ... only the head then has an animation */ |
/* which gets updated one time when this is called per tick */ | | /* which gets updated one time when this is called per tick */ |
if(op->head) /* we want always the head */ | | if(op->head) |
oph=op->head; | | oph=op->head; |
| | |
| | op->state+=count; /* increase draw state (of the animation frame) */ |
| | if(!count) |
| | { |
| | /* object needs no update for moving */ |
| | if(oph->anim_enemy_dir == oph->anim_enemy_dir_last && |
| | oph->anim_moving_dir == oph->anim_moving_dir_last && |
| | oph->anim_last_facing == oph->anim_last_facing_last) |
| | return; /* no need to set the frame new */ |
| | } |
dir=oph->direction; | | dir=oph->direction; |
| | |
/* If object is turning, then max animation state is half through the | | /* If object is turning, then max animation state is half through the |
| | |
else base_state = (dir-1)*(NUM_ANIMATIONS(op)/8); /* was 4 before - typo? */ | | else base_state = (dir-1)*(NUM_ANIMATIONS(op)/8); /* was 4 before - typo? */ |
} | | } |
/* thats the new extended animation: base_state is */ | | /* thats the new extended animation: base_state is */ |
/* 0: we are paralyzed, sleep, etc. */ | | /* 0: thats the corpse */ |
/* 1: we are stading or guarding */ | | /* 1-8: guard/stand_still anim frames */ |
/* 2-9: we are attacking in dir+1 */ | | /* 9-16: move anim frames */ |
/* 10-17: we are moving in dir+9 */ | | /* 17-24: fight anim frames */ |
else if (NUM_FACINGS(op)==18) { | | /* TODO: allow different number of faces in each frame */ |
/* first: test for an effect */ | | |
if(QUERY_FLAG(oph, FLAG_SLEEP)|| QUERY_FLAG(oph, FLAG_PARALYZED )) | | else if (NUM_FACINGS(op)==25) { |
{ | | /* we have targeted an enemy and face him. when me move, we strave sidewards */ |
dir = 0; | | if(oph->anim_enemy_dir != -1 && (!QUERY_FLAG(op,FLAG_RUN_AWAY) && !QUERY_FLAG(op,FLAG_SCARED))) |
} | | |
/* we have targeted an enemy and follow him ? */ | | |
else if(oph->anim_enemy_dir != -1) | | |
{ | | { |
dir = oph->anim_enemy_dir; /* lets face to the enemy position */ | | dir = oph->anim_enemy_dir; /* lets face to the enemy position */ |
if (!dir) /* special case, same spot will be mapped to other */ | | oph->anim_enemy_dir_last = oph->anim_enemy_dir; |
dir = 4; /* 4 for iso, 5 for flat - do it automatically later */ | | oph->anim_moving_dir_last = -1; |
dir++; | | if (!dir) /* special case, same spot will be mapped to south dir */ |
| | dir = 4; |
| | oph->anim_last_facing = dir; |
| | oph->anim_last_facing_last = -1; |
| | dir +=16; |
} | | } |
else if (oph->anim_moving_dir != -1)/* test of moving */ | | else if (oph->anim_moving_dir != -1)/* test of moving */ |
{ | | { |
if(!dir) /* ok, object is going to a position */ | | dir = oph->anim_moving_dir; /* lets face in moving direction */ |
dir = 1; | | oph->anim_moving_dir_last = oph->anim_moving_dir; |
dir+=9; | | oph->anim_enemy_dir_last = -1; |
| | if (!dir) /* special case, same spot will be mapped to south dir */ |
| | dir = 4; |
| | oph->anim_last_facing = dir; |
| | oph->anim_last_facing_last = -1; |
| | dir +=8; |
} | | } |
else /* if nothing to do: object do nothing */ | | else /* if nothing to do: object do nothing. use original facing */ |
{ | | { |
dir = 1; | | dir = oph->anim_last_facing; /* lets face to last direction we had done something */ |
| | oph->anim_last_facing_last = dir; |
| | if (!dir) /* special case, same spot will be mapped to south dir */ |
| | dir = 4; |
| | |
} | | } |
base_state = dir*(NUM_ANIMATIONS(op)/18); | | |
| | base_state = dir*(NUM_ANIMATIONS(op)/25); |
} | | } |
| | |
/* If beyond drawable states, reset */ | | /* If beyond drawable states, reset */ |
| | |
} | | } |
#endif | | #endif |
if(op->more) | | if(op->more) |
animate_object(op->more); | | animate_object(op->more, count); |
/* update_object will also recursively update all the pieces. | | /* update_object will also recursively update all the pieces. |
* as such, we call it last, and only call it for the head | | * as such, we call it last, and only call it for the head |
* piece, and not for the other tail pieces. | | * piece, and not for the other tail pieces. |