// Calculates the distance between two vectors in 3 dimensions. Allows
// catapults to work with hills
float Get3DDistance(vector v1, vector v2)
{
return sqrt((v2.x - v1.x) * (v2.x - v1.x) +
(v2.y - v1.y) * (v2.y - v1.y) +
(v2.z - v1.z) * (v2.z - v1.z));
}
// Applies damage from a catapult hit. This gets around the fact that a catupult
// has a caster level of 0, so its fireballs do 0d6 damage.
void ApplyDamage(vector center)
{
// Using GetFirstObjectInShape crashes the game (I think when the shape
// crosses into an invalid area. Instead, use GetFirstObjectInArea
// and check distances
object hit = GetFirstObjectInArea();
while (GetIsObjectValid(hit))
{
// Damage in a 5m radius sphere
if ((OBJECT_TYPE_CREATURE == GetObjectType(hit)) && // TODO: Currently only damages creatures (for speed). Remove this line to damage placeables as well
(Get3DDistance(center, GetPosition(hit)) < 10.0)) // TODO: This is the blast radius, feel free to tweak it
{
// Damage minus a reflex save
int damage = d10(); // TODO: Change this value to whatever you want