Пример #1
0
int main(int argc,char *argv[]) {
	bankAccount hisAcc;
	initialize(hisAcc);
	readF(&hisAcc,"DT.txt");	
	getInfo(&hisAcc);
	setType(&hisAcc);
	getMovements(&hisAcc);
	/*printf("%f \n",getTotalSpendings(hisAcc));
	int i;
	for (i=0; i<8; i++) {
		printSpending(i);
		printf(": %f€ qui représente ",getTotalSpendingType(hisAcc)[i]);
		printf(" %f pourcents des dépenses.\n",getStatsSpendings(hisAcc)[i]);
	} */
}
Пример #2
0
void BuddyPlayer::act( vector< Object * > * others, World * world, vector< Object * > * add ){
    Character::act(others, world, add);

    if (show_life > getHealth()){
        show_life--;
    }

    if (show_life < getHealth()){
        show_life++;
    }

    vector<Object *> enemies;

    if (getStatus() != Status_Ground && getStatus() != Status_Jumping){
        return;
    }

    filterEnemies(enemies, others);

    if (animation_current->Act()){
        animation_current->reset();
        // nextTicket();
        // animation_current = movements[ "idle" ];
        animation_current = getMovement("idle");
        animation_current->reset();
    }

    if (animation_current == getMovement("idle") ||
        animation_current == getMovement("walk") ){
        if (enemies.empty() && want_x == -1 && want_z == -1 && Util::rnd(15) == 0){
            // want_x = Util::rnd( 100 ) - 50 + furthestFriend( others, getAlliance(), this );
            want_x = Util::rnd(100) - 50 + (int) leader->getX();
            want_z = Util::rnd(world->getMinimumZ(), world->getMaximumZ());
        } else if (! enemies.empty()){
            const Object * main_enemy = findClosest(enemies);
            if ( main_enemy->getX() > getX() ){
                want_x = (int)(main_enemy->getX() - 20 - Util::rnd(20));
            } else {
                want_x = (int)(main_enemy->getX() + 20 + Util::rnd(20));
            }
            if (want_x < 1){
                want_x = Util::rnd(100) - 50 + (int) leader->getX();
            }
            want_z = (int)(Util::rnd(3) - 1 + main_enemy->getZ());
            faceObject(main_enemy);

            if (Util::rnd(35) == 0){
                vector<Util::ReferenceCount<Animation> > attacks;
                for (map<string, Util::ReferenceCount<Animation> >::const_iterator it = getMovements().begin(); it != getMovements().end(); it++){
                    Util::ReferenceCount<Animation> maybe = (*it).second;
                    if (maybe->isAttack() && maybe->getStatus() == Status_Ground && maybe->getName() != "special"){
                        attacks.push_back(maybe);
                    }
                }

                double attack_range = fabs( getX() - main_enemy->getX() );
                double zdistance = ZDistance( main_enemy );
                for (vector<Util::ReferenceCount<Animation> >::iterator it = attacks.begin(); it != attacks.end(); /**/){
                    Util::ReferenceCount<Animation> maybe = *it;
                    if (attack_range > maybe->getRange() || zdistance > maybe->getMinZDistance()){
                        it = attacks.erase(it);
                    } else {
                        it++;
                    }
                }

                if (!attacks.empty()){
                    animation_current = attacks[Util::rnd(attacks.size())];
                    world->addMessage(animationMessage());
                    nextTicket();
                    animation_current->reset();
                    return;
                } else {
                }
            }
        }

        if (want_x != -1 && want_z != -1){
            bool walk = false;
            if (want_x < 1){
                want_x = 1;
            }
            if (want_z < world->getMinimumZ()){
                want_z = world->getMinimumZ() + 1;
            }
            if (want_z >= world->getMaximumZ()){
                want_z = world->getMaximumZ() - 1;
            }
            if (getX() - want_x < -2){
                moveX(getSpeed());
                setFacing(FACING_RIGHT);
                walk = true;
            } else if (getX() - want_x > 2){
                setFacing(FACING_LEFT);
                moveX(getSpeed());
                walk = true;
            }

            if (getZ() < want_z){
                moveZ(getSpeed());
                walk = true;
            } else if (getZ() > want_z){
                moveZ(-getSpeed());
                walk = true;
            }

            if (walk){
                animation_current = getMovement("walk");
            }

            if (fabs(getX() - want_x) <= 2 &&
                fabs(getZ() - want_z) <= 2){
                want_x = -1;
                want_z = -1;
                animation_current = getMovement("idle");
            }
        }
    }
}