Skip to content
Draft
23 changes: 22 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

argtable3 library
======================
Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann
Expand Down Expand Up @@ -36,6 +35,15 @@ All rights reserved.

This code is derived from software contributed to The NetBSD Foundation
by Dieter Baron and Thomas Klausner.
=======


fixedptc library
======================


Copyright (c) 2010-2012 Ivan Voras <[email protected]>
Copyright (c) 2012 Tim Hartrick <[email protected]>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
Expand All @@ -46,6 +54,7 @@ are met:
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

<<<<<<< HEAD
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
Expand Down Expand Up @@ -168,3 +177,15 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=======
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
12 changes: 6 additions & 6 deletions src/controller/ai_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ int get_enemy_range(const controller *ctrl) {
object *o_enemy =
game_state_find_object(ctrl->gs, game_state_get_player(ctrl->gs, h->player_id == 1 ? 0 : 1)->har_obj_id);

int range_units = fabsf(o_enemy->pos.x - o->pos.x) / 30;
int range_units = fixedpt_toint(fixedpt_abs(o_enemy->pos.fx - o->pos.fx)) / 30;
switch(range_units) {
case 0:
case 1:
Expand Down Expand Up @@ -1477,7 +1477,7 @@ void set_selected_move(controller *ctrl, af_move *selected_move) {
a->move_str_pos = str_size(&selected_move->move_string) - 1;
object *o_enemy =
game_state_find_object(ctrl->gs, game_state_get_player(ctrl->gs, h->player_id == 1 ? 0 : 1)->har_obj_id);
a->move_stats[a->selected_move->id].last_dist = fabsf(o->pos.x - o_enemy->pos.x);
a->move_stats[a->selected_move->id].last_dist = fixedpt_toint(fixedpt_abs(o->pos.fx - o_enemy->pos.fx));
a->blocked = 0;
// log_debug("AI selected move %s", str_c(&selected_move->move_string));
}
Expand Down Expand Up @@ -1605,7 +1605,7 @@ int ai_block_har(controller *ctrl, ctrl_event **ev) {
har *h_enemy = object_get_userdata(o_enemy);

// XXX TODO get maximum move distance from the animation object
if(fabsf(o_enemy->pos.x - o->pos.x) < 100 && h_enemy->executing_move && smart_usually(a)) {
if(fixedpt_abs(o_enemy->pos.fx - o->pos.fx) < fixedpt_fromint(100) && h_enemy->executing_move && smart_usually(a)) {
if(har_is_crouching(h_enemy)) {
a->cur_act = DOWNBACK;
controller_cmd(ctrl, a->cur_act, ev);
Expand Down Expand Up @@ -1648,7 +1648,7 @@ int ai_block_projectile(controller *ctrl, ctrl_event **ev) {
if(object_get_direction(o_prj) == OBJECT_FACE_LEFT) {
pos_prj.x = object_get_pos(o_prj).x + ((cur_sprite->pos.x * -1) - size_prj.x);
}
if(fabsf(pos_prj.x - o->pos.x) < 120) {
if(abs(pos_prj.x - object_get_pos(o).x) < 120) {
a->cur_act = DOWNBACK;
controller_cmd(ctrl, a->cur_act, ev);
return 1;
Expand Down Expand Up @@ -1770,9 +1770,9 @@ void handle_movement(controller *ctrl, ctrl_event **ev) {
// double jump
controller_cmd(ctrl, ACT_DOWN, ev);
}
if(o->vel.x < 0) {
if(o->vel.fx < 0) {
controller_cmd(ctrl, ACT_UP | ACT_LEFT, ev);
} else if(o->vel.x > 0) {
} else if(o->vel.fx > 0) {
controller_cmd(ctrl, ACT_UP | ACT_RIGHT, ev);
} else {
controller_cmd(ctrl, ACT_UP, ev);
Expand Down
10 changes: 5 additions & 5 deletions src/formats/af.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ int sd_af_load(sd_af_file *af, const char *filename) {
// Header
af->file_id = sd_read_uword(r);
af->exec_window = sd_read_uword(r); // Always 10
af->endurance = sd_read_udword(r) * 1.0f;
af->endurance = sd_read_dword(r);
af->unknown_b = sd_read_ubyte(r); // Always 1 or 2
af->health = sd_read_uword(r);
af->forward_speed = sd_read_dword(r) / 256.0f;
af->reverse_speed = sd_read_dword(r) / 256.0f;
af->jump_speed = sd_read_dword(r) / 256.0f;
af->fall_speed = sd_read_dword(r) / 256.0f;
af->forward_speed = sd_read_dword(r);
af->reverse_speed = sd_read_dword(r);
af->jump_speed = sd_read_dword(r);
af->fall_speed = sd_read_dword(r);
af->unknown_c = sd_read_ubyte(r); // Always 0x32 ?
af->unknown_d = sd_read_ubyte(r); // Always 0x14 ?

Expand Down
22 changes: 11 additions & 11 deletions src/formats/af.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
* Contains information about a single HAR (combat robot).
*/
typedef struct {
uint16_t file_id; ///< File ID
uint16_t exec_window; ///< Move execution window (?)
float endurance; ///< HAR Endurance
uint8_t unknown_b; ///< Unknown value
uint16_t health; ///< HAR Health
float forward_speed; ///< HAR fwd speed
float reverse_speed; ///< HAR bwd speed
float jump_speed; ///< HAR jump speed
float fall_speed; ///< HAR fall speed
uint8_t unknown_c; ///< Unknown value
uint8_t unknown_d; ///< Unknown value
uint16_t file_id; ///< File ID
uint16_t exec_window; ///< Move execution window (?)
int32_t endurance; ///< HAR Endurance
uint8_t unknown_b; ///< Unknown value
uint16_t health; ///< HAR Health
int32_t forward_speed; ///< HAR fwd speed
int32_t reverse_speed; ///< HAR bwd speed
int32_t jump_speed; ///< HAR jump speed
int32_t fall_speed; ///< HAR fall speed
uint8_t unknown_c; ///< Unknown value
uint8_t unknown_d; ///< Unknown value

sd_move *moves[MAX_AF_MOVES]; ///< All HAR moves.
char soundtable[30]; ///< All sounds used by the animations in this HAR file.
Expand Down
22 changes: 11 additions & 11 deletions src/game/game_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ int game_state_get_assertion_operand(rec_assertion_operand *op, game_state *gs)
har *har = object_get_userdata(obj);
switch(op->value.attr.attribute) {
case ATTR_X_POS:
return obj->pos.x;
return fixedpt_toint(obj->pos.fx);
case ATTR_Y_POS:
return obj->pos.y;
return fixedpt_toint(obj->pos.fy);
case ATTR_X_VEL:
return obj->vel.x;
return fixedpt_toint(obj->vel.fx);
case ATTR_Y_VEL:
return obj->vel.y;
return fixedpt_toint(obj->vel.fy);
case ATTR_STATE_ID:
return har->state;
case ATTR_ANIMATION_ID:
Expand All @@ -99,10 +99,10 @@ int game_state_get_assertion_operand(rec_assertion_operand *op, game_state *gs)
case ATTR_OPPONENT_DISTANCE: {
object *obj_opp = game_state_find_object(
gs, game_player_get_har_obj_id(game_state_get_player(gs, abs(op->value.attr.har_id - 1))));
return fabsf(obj->pos.x - obj_opp->pos.x);
case ATTR_DIRECTION:
return object_get_direction(obj);
return abs(fixedpt_toint(obj->pos.fx - obj_opp->pos.fx));
}
case ATTR_DIRECTION:
return object_get_direction(obj);
default:
abort();
}
Expand Down Expand Up @@ -141,16 +141,16 @@ bool game_state_check_assertion_is_met(rec_assertion *ass, game_state *gs) {

switch(ass->operand1.value.attr.attribute) {
case ATTR_X_POS:
obj->pos.x = operand2;
obj->pos.fx = fixedpt_fromint(operand2);
return true;
case ATTR_Y_POS:
obj->pos.y = operand2;
obj->pos.fy = fixedpt_fromint(operand2);
return true;
case ATTR_X_VEL:
obj->vel.x = operand2;
obj->vel.fx = fixedpt_fromint(operand2);
return true;
case ATTR_Y_VEL:
obj->vel.y = operand2;
obj->vel.fy = fixedpt_fromint(operand2);
return true;
case ATTR_HEALTH:
har->health = operand2;
Expand Down
16 changes: 8 additions & 8 deletions src/game/gui/trn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ static void trnmenu_layout(component *c, int x, int y, int w, int h) {
}

static vec2f center(component *c) {
return vec2f_create(c->x + c->w / 2, c->y + c->h / 2);
return vec2f_create(fixedpt_fromint(c->x + c->w) / 2, fixedpt_fromint(c->y + c->h) / 2);
}

static vec2f rcenter(component *c) {
return vec2f_create(c->x + c->w, c->y + c->h / 2);
return vec2f_create(fixedpt_fromint(c->x + c->w), fixedpt_fromint(c->y + c->h) / 2);
}

static vec2f lcenter(component *c) {
return vec2f_create(c->x, c->y + c->h / 2);
return vec2f_create(fixedpt_fromint(c->x), fixedpt_fromint(c->y + c->h) / 2);
}

static int find_next_button(component *c, int act) {
Expand All @@ -184,7 +184,7 @@ static int find_next_button(component *c, int act) {
sizer_begin_iterator(c, &it);

component *cur = sizer_get(c, m->selected);
float best_dist = 9999.0f;
fixedpt best_dist = FIXEDPT_MAX;
int best_idx = -1;
int idx_now = 0;
foreach(it, tmp) {
Expand All @@ -196,7 +196,7 @@ static int find_next_button(component *c, int act) {
switch(act) {
case ACT_LEFT:
if(t->x < cur->x) {
float tdist = vec2f_dist(rcenter(t), lcenter(cur));
fixedpt tdist = vec2f_dist(rcenter(t), lcenter(cur));
if(tdist < best_dist) {
best_dist = tdist;
best_idx = idx_now;
Expand All @@ -205,7 +205,7 @@ static int find_next_button(component *c, int act) {
break;
case ACT_RIGHT:
if(t->x > cur->x) {
float tdist = vec2f_dist(lcenter(t), rcenter(cur));
fixedpt tdist = vec2f_dist(lcenter(t), rcenter(cur));
if(tdist < best_dist) {
best_dist = tdist;
best_idx = idx_now;
Expand All @@ -214,7 +214,7 @@ static int find_next_button(component *c, int act) {
break;
case ACT_UP:
if(t->y < cur->y) {
float tdist = vec2f_dist(center(t), center(cur));
fixedpt tdist = vec2f_dist(center(t), center(cur));
if(tdist < best_dist) {
best_dist = tdist;
best_idx = idx_now;
Expand All @@ -223,7 +223,7 @@ static int find_next_button(component *c, int act) {
break;
case ACT_DOWN:
if(t->y > cur->y) {
float tdist = vec2f_dist(center(t), center(cur));
fixedpt tdist = vec2f_dist(center(t), center(cur));
if(tdist < best_dist) {
best_dist = tdist;
best_idx = idx_now;
Expand Down
5 changes: 5 additions & 0 deletions src/game/objects/arena_constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
#define ARENA_RIGHT_WALL 300
#define ARENA_FLOOR 190

// fixed point versions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably we should remove the non fixed point versions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARENA_FLOOR is important for object rendering, and we render in pixels-- not fixedpt fractions of pixels.
The arena walls can be fixedpt only, sure.

#define ARENA_LEFT_WALLF fixedpt_fromint(ARENA_LEFT_WALL)
#define ARENA_RIGHT_WALLF fixedpt_fromint(ARENA_RIGHT_WALL)
#define ARENA_FLOORF fixedpt_fromint(ARENA_FLOOR)

#endif // ARENA_CONSTRAINTS_H
Loading
Loading