You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
52 lines
1.7 KiB
#include "entityacts.h"
|
|
#include "../Textures/animationHandler.h"
|
|
#include "../MapObject/building.h"
|
|
|
|
void BuilderAct(Game *game, Entity *entity){
|
|
Building *target = (Building *) entity->task->target;
|
|
|
|
// Hat noch keine Baustelle oder die Baustelle wurde fertiggestellt
|
|
if(entity->task->target == 0 || !target->isBaustelle){
|
|
AnimationChangeType(entity->animationHandler, AN_ENTITY_IDLE);
|
|
|
|
if(entity->hasDestination == 1){
|
|
entity->hasDestination = 0;
|
|
}
|
|
|
|
// Prüft, ob eine Baustelle existiert
|
|
Building *current = game->buildings->head;
|
|
while(current != 0){
|
|
if(current->isBaustelle){
|
|
entity->hasDestination = 1;
|
|
entity->destX = current->sprite->x;
|
|
entity->destY = current->sprite->y;
|
|
|
|
entity->task->target = current;
|
|
entity->task->progress = 0;
|
|
break;
|
|
}
|
|
current = current->next;
|
|
}
|
|
}
|
|
else if(entity->hasDestination == 1){
|
|
EntityMoveToDestination(entity);
|
|
}
|
|
else{
|
|
// Is beim target angekommen
|
|
if(entity->task->progress == 0){
|
|
// Angekommen, noch nicht mit arbeiten begonnen
|
|
AnimationChangeType(entity->animationHandler, AN_ENTITY_ARBEITEN);
|
|
target->progress += 0.01;
|
|
}
|
|
else if(target->progress >= 1.0){
|
|
// Fertig mit arbeiten, Animation zu Idle zurück
|
|
AnimationChangeType(entity->animationHandler, AN_ENTITY_IDLE);
|
|
BuildingFinishConstruction(game, (Building *) entity->task->target);
|
|
entity->task->target = 0;
|
|
}
|
|
else{
|
|
target->progress += 0.2 * GetFrameTime();
|
|
}
|
|
}
|
|
}
|