version 1.7 | | version 1.8 |
---|
| | |
/* | | /* |
* static char *rcsid_anim_c = | | * static char *rcsid_anim_c = |
* "$Id: anim.c,v 1.7 2001/07/14 04:04:53 mwedel Exp $"; | | * "$Id: anim.c,v 1.8 2001/11/02 18:39:23 michtoen Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
LOG(llevDebug,"done. got (%d)\n", num_animations); | | LOG(llevDebug,"done. got (%d)\n", num_animations); |
} | | } |
| | |
static int anim_compare(Animations *a, Animations *b) { | | static int anim_compare(const void *a, const void *b) { |
return strcmp(a->name, b->name); | | return strcmp(((Animations*)a)->name,((Animations*) b)->name); |
} | | } |
| | |
/* Tries to find the animation id that matches name. Returns an integer match | | /* Tries to find the animation id that matches name. Returns an integer match |
| | |
| | |
search.name = name; | | search.name = name; |
| | |
| | #ifdef WIN32 |
| | match = (Animations*)bsearch(&search, animations, (num_animations+1), |
| | sizeof(Animations), anim_compare); |
| | #else |
match = (Animations*)bsearch(&search, animations, (num_animations+1), | | match = (Animations*)bsearch(&search, animations, (num_animations+1), |
sizeof(Animations), (int (*)())anim_compare); | | sizeof(Animations), (int (*)())anim_compare); |
| | #endif |
| | |
| | |
if (match) return match->num; | | if (match) return match->num; |
| | |
void animate_object(object *op) { | | void animate_object(object *op) { |
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=op->direction; | | int dir; |
| | register object *oph = op; |
| | |
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"); |
| | |
} | | } |
++op->state; /* increase draw state */ | | ++op->state; /* increase draw state */ |
| | |
if (op->head) dir=op->head->direction; | | /* when we change to "one arch/one png, we must use this also for */ |
| | /* the code above ... only the head then has an animation */ |
| | /* which gets updated one time when this is called per tick */ |
| | if(op->head) /* we want always the head */ |
| | oph=op->head; |
| | |
| | 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 |
* animations. Otherwise, we can use all the animations. | | * animations. Otherwise, we can use all the animations. |
| | |
} | | } |
else if (NUM_FACINGS(op)==8) { | | else if (NUM_FACINGS(op)==8) { |
if (dir==0) base_state=0; | | if (dir==0) base_state=0; |
else base_state = (dir-1)*(NUM_ANIMATIONS(op)/4); | | else base_state = (dir-1)*(NUM_ANIMATIONS(op)/8); /* was 4 before - typo? */ |
| | } |
| | /* thats the new extended animation: base_state is */ |
| | /* 0: we are paralyzed, sleep, etc. */ |
| | /* 1: we are stading or guarding */ |
| | /* 2-9: we are attacking in dir+1 */ |
| | /* 10-17: we are moving in dir+9 */ |
| | else if (NUM_FACINGS(op)==18) { |
| | /* first: test for an effect */ |
| | if(QUERY_FLAG(oph, FLAG_SLEEP)|| QUERY_FLAG(oph, FLAG_PARALYZED )) |
| | { |
| | dir = 0; |
| | } |
| | /* 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 */ |
| | if (!dir) /* special case, same spot will be mapped to other */ |
| | dir = 4; /* 4 for iso, 5 for flat - do it automatically later */ |
| | dir++; |
| | |
| | } |
| | else if (oph->anim_moving_dir != -1)/* test of moving */ |
| | { |
| | if(!dir) /* ok, object is going to a position */ |
| | dir = 1; |
| | dir+=9; |
| | } |
| | else /* if nothing to do: object do nothing */ |
| | { |
| | dir = 1; |
| | } |
| | base_state = dir*(NUM_ANIMATIONS(op)/18); |
} | | } |
| | |
/* If beyond drawable states, reset */ | | /* If beyond drawable states, reset */ |