adg5/Fireball.cpp
2025-04-22 11:38:20 +10:00

36 lines
1.2 KiB
C++

#include "libtcod.hpp"
#include "Fireball.h"
#include "Engine.h"
#include "Gui.h"
#include "Destructible.h"
#include "Actor.h"
Fireball::Fireball(float range, float damage)
: LightningBolt(range, damage) {
}
bool Fireball::use(Actor* owner, Actor* wearer) {
engine->gui->message(engine->gui->lightBlue, "Left-click a target tile for the fireball,\nor right-click to cancel.");
int x, y;
if (!engine->pickATile(&x, &y)) {
return false;
}
engine->gui->message(engine->gui->lightYellow, "The fireball explodes, burning everything within %g tiles!", range);
for (Actor** iterator = engine->actors.begin();
iterator != engine->actors.end(); iterator++) {
Actor* actor = *iterator;
if (actor->destructible && !actor->destructible->isDead()
&& actor->getDistance(x, y) <= range) {
engine->gui->message(engine->gui->lightYellow, "The %s gets burned for %g hit points.",
actor->name.c_str(), damage);
actor->destructible->takeDamage(actor, damage);
}
}
return Pickable::use(owner, wearer);
}
void Fireball::save(TCODZip& zip) {
zip.putInt(FIREBALL);
zip.putFloat(range);
zip.putFloat(damage);
}