|
| 1 | +/* |
| 2 | + * Copyright (C) 2026 Michael Binder and contributors |
| 3 | + * |
| 4 | + * This file is part of OpenShadowFlare. |
| 5 | + * |
| 6 | + * OpenShadowFlare is free software: you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License as published by the Free |
| 8 | + * Software Foundation, either version 3 of the License, or (at your option) |
| 9 | + * any later version. |
| 10 | + * |
| 11 | + * OpenShadowFlare is distributed in the hope that it will be useful, but |
| 12 | + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 | + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | + * details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along |
| 17 | + * with OpenShadowFlare. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +#include "game/generic_effect_actor.h" |
| 21 | + |
| 22 | +#include "game/movement.h" |
| 23 | + |
| 24 | +#include <limits.h> |
| 25 | +#include <string.h> |
| 26 | + |
| 27 | +static int32_t sf_generic_effect_resource(int32_t effect_number) { |
| 28 | + static const int32_t resources[8] = {0, 1, 2, 3, 0, 0, 4, 0}; |
| 29 | + return effect_number >= 0 && effect_number < 8 |
| 30 | + ? resources[effect_number] : -1; |
| 31 | +} |
| 32 | + |
| 33 | +static SfObjectBounds sf_generic_effect_judgement(int32_t effect_number) { |
| 34 | + if (effect_number == 6) |
| 35 | + return (SfObjectBounds) {-160, -160, 159, 159}; |
| 36 | + return (SfObjectBounds) {-30, -30, 30, 30}; |
| 37 | +} |
| 38 | + |
| 39 | +static bool sf_generic_effect_position( |
| 40 | + const SfCombatEffectRequest *request, SfWorldPoint resolved_source, |
| 41 | + SfWorldPoint *position) { |
| 42 | + SfWorldPoint offset; |
| 43 | + int64_t x; |
| 44 | + int64_t y; |
| 45 | + if (request->owner_kind == 0 && request->has_explicit_origin) { |
| 46 | + *position = request->origin; |
| 47 | + return true; |
| 48 | + } |
| 49 | + if (request->constructor_values_16_to_22[ |
| 50 | + SF_COMBAT_EFFECT_CONSTRUCTOR_21] < 0) return false; |
| 51 | + if (!sf_movement_vector_at_distance( |
| 52 | + request->direction_vector, |
| 53 | + (uint32_t) request->constructor_values_16_to_22[ |
| 54 | + SF_COMBAT_EFFECT_CONSTRUCTOR_21], &offset)) return false; |
| 55 | + x = (int64_t) resolved_source.x + offset.x; |
| 56 | + y = (int64_t) resolved_source.y + offset.y; |
| 57 | + if (x < INT32_MIN || x > INT32_MAX || |
| 58 | + y < INT32_MIN || y > INT32_MAX) return false; |
| 59 | + *position = (SfWorldPoint) {(int32_t) x, (int32_t) y}; |
| 60 | + return true; |
| 61 | +} |
| 62 | + |
| 63 | +bool sf_generic_effect_actor_build( |
| 64 | + const SfCombatEffectRequest *request, SfWorldPoint resolved_source, |
| 65 | + SfGenericEffectActor *actor) { |
| 66 | + const SfWorldPoint zero = {0, 0}; |
| 67 | + int32_t resource; |
| 68 | + if (!actor) return false; |
| 69 | + memset(actor, 0, sizeof(*actor)); |
| 70 | + if (!request || !request->valid) return false; |
| 71 | + resource = sf_generic_effect_resource(request->effect_number); |
| 72 | + if (resource < 0 || request->effect_number == 2) return false; |
| 73 | + if (!sf_generic_effect_position(request, resolved_source, &actor->position)) |
| 74 | + return false; |
| 75 | + actor->packet = request->packet; |
| 76 | + actor->direction_vector = request->direction_vector; |
| 77 | + actor->judgement = sf_generic_effect_judgement(request->effect_number); |
| 78 | + actor->effect_number = request->effect_number; |
| 79 | + actor->resource_id = resource; |
| 80 | + actor->owner_kind = request->owner_kind; |
| 81 | + actor->source_character_number = request->source_character_number; |
| 82 | + actor->target_kind = request->target_kind; |
| 83 | + actor->target_identifier = request->target_identifier; |
| 84 | + actor->travel_speed = request->constructor_value_6; |
| 85 | + actor->display_height = request->constructor_value_7; |
| 86 | + actor->lifetime = -1; |
| 87 | + actor->target_collision_start = 0; |
| 88 | + actor->contact_effect_number = request->effect_number == 6 ? 21023 : -1; |
| 89 | + actor->animation_chart = 0; |
| 90 | + actor->animation_direction = request->effect_number == 1 ? 8 : |
| 91 | + request->packet_kind == 8 |
| 92 | + ? sf_movement_direction(zero, request->direction_vector) |
| 93 | + : request->packet_kind; |
| 94 | + actor->target_audio_sample = 20u; |
| 95 | + actor->valid = true; |
| 96 | + actor->home_toward_target = |
| 97 | + request->constructor_values_16_to_22[ |
| 98 | + SF_COMBAT_EFFECT_CONSTRUCTOR_20] == 1 && request->effect_number != 1; |
| 99 | + actor->collide_with_environment = true; |
| 100 | + actor->expire_on_environment_collision = true; |
| 101 | + actor->expire_on_target = true; |
| 102 | + actor->remember_targets = request->constructor_values_16_to_22[ |
| 103 | + SF_COMBAT_EFFECT_CONSTRUCTOR_22] == 1; |
| 104 | + actor->has_packet = request->has_packet; |
| 105 | + return true; |
| 106 | +} |
0 commit comments