summaryrefslogtreecommitdiff
path: root/src/game/rocket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/rocket.cpp')
-rw-r--r--src/game/rocket.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/game/rocket.cpp b/src/game/rocket.cpp
index e88f599..a03b169 100644
--- a/src/game/rocket.cpp
+++ b/src/game/rocket.cpp
@@ -19,29 +19,13 @@ along with Minitrem. If not, see <http://www.gnu.org/licenses/>.
namespace game {
-/*
- class rocket_t : public game::entity_t {
- unit_t *shooter;
- v2f_t v;
-
- public:
- rocket_t(game::state_t *game, v2f_t x, v2f_t v, unit_t *shooter_);
- void render_to(render::state_t *render);
- void render_late_to(render::state_t *render) {};
-
- void on_think(void);
- void on_spawn(void) {};
- void on_wake(void) {};
- void damage(int points, unit_t *attacker) {};
- }
-*/
-
const v2f_t rocket_radius(1.0f, 1.0f);
-rocket_t::rocket_t(game::state_t *game, v2f_t x_, v2f_t v_, unit_t *shooter_) : entity_t(game, ET_ROCKET)
+rocket_t::rocket_t(game::state_t *game, v2f_t x_, v2f_t target_, unit_t *shooter_) : entity_t(game, ET_ROCKET)
{
x = x_;
- v = v_;
+ target = target_;
+ v = (target - x).norm() * 10.0f;
shooter = shooter_;
size = rectf_t(v2f_t(-0.1f, -0.1f), v2f_t(0.1f, 0.1f));
@@ -51,15 +35,31 @@ rocket_t::rocket_t(game::state_t *game, v2f_t x_, v2f_t v_, unit_t *shooter_) :
wake();
}
+void rocket_t::on_spawn(void)
+{
+ aim_marker = std::make_unique<fx_aim_marker_t>(game, target);
+}
+
void rocket_t::on_think(void)
{
+ float Ds, ds;
v2f_t end;
world::trace_t trace;
- end = x + v * game->dt;
- trace = world->ray_v_all(x, end, CF_SOLID|CF_BODY|CF_BODY_SMALL, shooter);
- if (trace.frac < 1.0f) {
- game->explosion(x);
+ Ds = (target - x) * v.norm();
+ ds = v.len() * game->dt;
+
+ if (Ds > ds) {
+ end = x + v * game->dt;
+ trace = world->ray_v_all(x, end, CF_SOLID|CF_BODY|CF_BODY_SMALL, shooter);
+ } else {
+ end = target;
+ trace = world->ray_v_all_p3d(x, end, CF_SOLID|CF_BODY|CF_BODY_SMALL, -1, nullptr);
+ trace.hit = true;
+ }
+
+ if (trace.hit) {
+ game->explosion(trace.end);
delete this;
return;
}