Skip to content

Commit

Permalink
Use object ID constants everywhere instead of magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
rollerozxa committed Jan 21, 2024
1 parent 01f0761 commit 87b00fb
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/src/absorber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ absorber::step()
/* do we have any entity pending removal? */
if (pending_fixtures.size() > 0) {
entity *e = static_cast<entity*>(pending_fixtures.front()->GetUserData());
if ((g_id == 0 || e->g_id == g_id) && G->absorb(e)) {
if ((g_id == O_PLANK || e->g_id == g_id) && G->absorb(e)) {
W->events[WORLD_EVENT_ABSORB] ++;

G->play_sound(SND_ABSORB, this->get_position().x, this->get_position().y, rand(), 1.f);
Expand Down
9 changes: 9 additions & 0 deletions src/src/adventure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ handle_input_action(const tms::event *ev, const enum input_action ia)
case IA_BTN_LAYER_DOWN:
G->handle_ingame_object_button(GW_LAYER_DOWN);
return EVENT_DONE;

default:
break;
}
} else if (ev->type == TMS_EV_KEY_DOWN) {
static const float aim_mod = 0.0075;
Expand All @@ -354,6 +357,9 @@ handle_input_action(const tms::event *ev, const enum input_action ia)
adventure::player->get_weapon()->set_arm_angle_raw(cur_aim-aim_mod);
}
return EVENT_DONE;

default:
break;
}
} else if (ev->type == TMS_EV_KEY_UP || ev->type == TMS_EV_POINTER_UP) {
switch (ia) {
Expand Down Expand Up @@ -394,6 +400,9 @@ handle_input_action(const tms::event *ev, const enum input_action ia)
case IA_SELF_DESTRUCT:
adventure::kill_player = false;
break;

default:
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/src/beam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class beam_ray_cb : public b2RayCastCallback
this->result_point = pt;
}
ret = fraction;
} else if (r->get_layer() == ignore->get_layer()+1 || (r->g_id == 151 && r->get_layer() == ignore->get_layer()-1)
} else if (r->get_layer() == ignore->get_layer()+1 || (r->g_id == O_LASER_BOUNCER && r->get_layer() == ignore->get_layer()-1)
/* && (r->group == 0 ||
r->group != ignore->group
)*/) { /* XXX */
Expand Down
2 changes: 1 addition & 1 deletion src/src/chunk.hh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class level_chunk : public entity
this->set_flag(ENTITY_ALLOW_CONNECTIONS, true);
this->set_flag(ENTITY_IS_STATIC, true);
this->set_flag(ENTITY_IS_ZAPPABLE, true);
this->g_id = 197;//O_CHUNK;
this->g_id = O_CHUNK;
this->set_mesh((struct tms_mesh*)0);
this->set_material(&m_tpixel);
this->generate_phase = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/src/chunk_preloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ chunk_preloader::unload(level_chunk *chunk)
}

connection *extra_conn = 0;
if (en->g_id == 16) extra_conn = &((pivot_1*)en)->dconn;
else if (en->g_id == 19) extra_conn = &((damper_1*)en)->dconn;
else if (en->g_id == 95) extra_conn = &((rubberband_1*)en)->dconn;
if (en->g_id == O_OPEN_PIVOT) extra_conn = &((pivot_1*)en)->dconn;
else if (en->g_id == O_DAMPER) extra_conn = &((damper_1*)en)->dconn;
else if (en->g_id == O_RUBBERBAND) extra_conn = &((rubberband_1*)en)->dconn;

if (extra_conn) {
connections.insert(extra_conn);
Expand Down
7 changes: 4 additions & 3 deletions src/src/emitter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void
emitter::step()
{
int g_id = this->properties[1].v.i;
if (g_id == 0 && this->size != 2) return;
if (g_id == O_PLANK && this->size != 2) return;

this->time += G->timemul(WORLD_STEP);

Expand Down Expand Up @@ -639,8 +639,9 @@ emitter::copy_properties(entity *e)
char *s;

/* special case for boxes and mini emitter, accept boxes but force their size to 0 */
if (this->size == TYPE_MINI && (e->g_id == 108 || e->g_id == 93 || e->g_id == O_CYLINDER || e->g_id == O_INTERACTIVE_CYLINDER
|| e->g_id == O_PLASTIC_BOX) && x == 0) {
if (this->size == TYPE_MINI &&
(e->g_id == O_INTERACTIVE_BOX || e->g_id == O_BOX || e->g_id == O_CYLINDER || e->g_id == O_INTERACTIVE_CYLINDER || e->g_id == O_PLASTIC_BOX)
&& x == 0) {
uint32_t i_saved = e->properties[x].v.i;
e->properties[x].v.i = 0;
s = e->properties[x].stringify();
Expand Down
18 changes: 9 additions & 9 deletions src/src/entity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ class sidecheck_cb : public b2RayCastCallback
entity *e = static_cast<entity*>(f->GetUserData());

if (e && e != this->ignore && e->get_layer() == ignore->get_layer() && e->allow_connections()) {
if ((e->g_id == 95 || e->g_id == 96) &&
(this->ignore->g_id == 95 || this->ignore->g_id == 96)) {
if ((e->g_id == O_RUBBERBAND || e->g_id == O_RUBBERBAND_2) &&
(this->ignore->g_id == O_RUBBERBAND || this->ignore->g_id == O_RUBBERBAND_2)) {
entity *other = NULL;

if (e->g_id == 95) {
if (e->g_id == O_RUBBERBAND) {
rubberband_1 *r1 = static_cast<rubberband_1*>(e);
other = r1->dconn.get_other(r1);
} else {
Expand Down Expand Up @@ -488,12 +488,12 @@ entity::gather_connected_entities(std::set<entity*> *entities, bool include_cabl
if (include_custom_conns) {
entity *other = 0;

if (this->g_id == 16) other = ((pivot_1*)this)->dconn.o;
else if (this->g_id == 69) other = ((pivot_2*)this)->p1;
else if (this->g_id == 19) other = ((damper_1*)this)->dconn.o;
else if (this->g_id == 67) other = ((damper_2*)this)->d1;
else if (this->g_id == 95) other = ((rubberband_1*)this)->dconn.o;
else if (this->g_id == 96) other = ((rubberband_2*)this)->d1;
if (this->g_id == O_OPEN_PIVOT) other = ((pivot_1*)this)->dconn.o;
else if (this->g_id == O_OPEN_PIVOT_2) other = ((pivot_2*)this)->p1;
else if (this->g_id == O_DAMPER) other = ((damper_1*)this)->dconn.o;
else if (this->g_id == O_DAMPER_2) other = ((damper_2*)this)->d1;
else if (this->g_id == O_RUBBERBAND) other = ((rubberband_1*)this)->dconn.o;
else if (this->g_id == O_RUBBERBAND_2) other = ((rubberband_2*)this)->d1;

if (other && entities->find(other) == entities->end()) {
other->gather_connected_entities(entities, include_cables, include_custom_conns, include_static, select_through_layers, layer);
Expand Down
7 changes: 4 additions & 3 deletions src/src/entity.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "material.hh"
#include "types.hh"
#include "const.hh"
#include "object_factory.hh"

#include <set>
#include <map>
Expand Down Expand Up @@ -563,12 +564,12 @@ class entity : public tms::entity
* a wireless frequency. */
inline bool is_wireless()
{
return (this->g_id == 123 || this->g_id == 124 || this->g_id == 139);
return (this->g_id == O_RECEIVER || this->g_id == O_TRANSMITTER || this->g_id == O_MINI_TRANSMITTER);
}

inline bool is_item()
{
return (this->g_id == 186);
return (this->g_id == O_ITEM);
}

inline bool is_prompt_compatible()
Expand All @@ -590,7 +591,7 @@ class entity : public tms::entity
inline bool is_interactive() { return this->flag_active(ENTITY_IS_INTERACTIVE); }
inline bool is_composable() { return this->flag_active(ENTITY_IS_COMPOSABLE); }
inline bool is_wheel() { return (this->type == ENTITY_WHEEL || this->type == ENTITY_GEAR); }
inline bool is_gearbox() { return (this->g_id == 18); }
inline bool is_gearbox() { return (this->g_id == O_GEARBOX); }
inline bool allow_connections() { return this->flag_active(ENTITY_ALLOW_CONNECTIONS); }
inline bool has_tracker() { return this->flag_active(ENTITY_HAS_TRACKER); }
virtual bool is_locked() { return this->flag_active(ENTITY_IS_LOCKED); }
Expand Down
18 changes: 9 additions & 9 deletions src/src/game-gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ game::delete_entity(entity *e)
* have selected. After that, we can move on to the regular
* object deletion code.
**/
if (e->g_id == 16 || e->g_id == 69) { /* Pivot */
if (e->g_id == O_OPEN_PIVOT || e->g_id == O_OPEN_PIVOT_2) { /* Pivot */
pivot_1 *p1 = 0;
pivot_2 *p2 = 0;
entity *other = 0;

if (e->g_id == 16) {
if (e->g_id == O_OPEN_PIVOT) {
p1 = static_cast<pivot_1*>(e);
other = p1->dconn.o;
if (other && other != p1)
Expand Down Expand Up @@ -300,12 +300,12 @@ game::delete_entity(entity *e)
delete p2;

return 3;
} else if (e->g_id == 19 || e->g_id == 67) { /* Damper */
} else if (e->g_id == O_DAMPER || e->g_id == O_DAMPER_2) { /* Damper */
damper_1 *d1 = 0;
damper_2 *d2 = 0;
entity *other = 0;

if (e->g_id == 19) {
if (e->g_id == O_DAMPER) {
d1 = static_cast<damper_1*>(e);
other = d1->dconn.o;
if (other && other != d1)
Expand Down Expand Up @@ -339,12 +339,12 @@ game::delete_entity(entity *e)
delete d2;

return 3;
} else if (e->g_id == 95 || e->g_id == 96) { /* Rubberband */
} else if (e->g_id == O_RUBBERBAND || e->g_id == O_RUBBERBAND_2) { /* Rubberband */
rubberband_1 *r1 = 0;
rubberband_2 *r2 = 0;
entity *other = 0;

if (e->g_id == 95) {
if (e->g_id == O_RUBBERBAND) {
r1 = static_cast<rubberband_1*>(e);
other = r1->dconn.o;
if (other && other != r1)
Expand Down Expand Up @@ -1248,11 +1248,11 @@ game::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
/* FIXME: Damper, Open pivot and Rubberband can't be moveable right now. fix sometime */
case GW_TOGGLE_MOVEABLE:
if (G->selection.e) {
if (G->selection.e->g_id == 16 || G->selection.e->g_id == 69) {
if (G->selection.e->g_id == O_OPEN_PIVOT || G->selection.e->g_id == O_OPEN_PIVOT_2) {
ui::message("Can't set the Pivot to moveable.");
} else if (G->selection.e->g_id == 19 || G->selection.e->g_id == 67) {
} else if (G->selection.e->g_id == O_DAMPER || G->selection.e->g_id == O_DAMPER_2) {
ui::message("Can't set the Damper to moveable.");
} else if (G->selection.e->g_id == 95 || G->selection.e->g_id == 96) {
} else if (G->selection.e->g_id == O_RUBBERBAND || G->selection.e->g_id == O_RUBBERBAND_2) {
ui::message("Can't set the Rubberband to moveable.");
} else {
G->selection.e->get_property_entity()->set_moveable(!G->selection.e->get_property_entity()->is_moveable());
Expand Down
2 changes: 1 addition & 1 deletion src/src/magconn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ magsock::on_touch(b2Fixture *a, b2Fixture *b)
if (a == this->sensor) {
entity *e = (entity*)b->GetUserData();

if (e && e->g_id == 36) {
if (e && e->g_id == O_MAGNETIC_PLUG) {
this->connected = b;
this->plug = static_cast<magplug*>(e);
this->plug->sock = this;
Expand Down
2 changes: 1 addition & 1 deletion src/src/motor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ motor::connection_create_joint(connection *c)
if (c->o->type == ENTITY_PLANK && !c->o->gr) {
rjd.localAnchorB = c->o->world_to_body(this->get_position(), c->f[1]);
rjd.localAnchorB.y = 0.f;
} else if (c->o->type == ENTITY_WHEEL || c->o->g_id == 18) {
} else if (c->o->type == ENTITY_WHEEL || c->o->g_id == O_GEARBOX) {
/* get the centroid of the object */
rjd.localAnchorB = c->o->local_to_body(b2Vec2(0.f,0.f), c->f[1]);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/src/objectfield.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void
objectfield::on_touch(b2Fixture *my, b2Fixture *other)
{
entity *e;
if ((e = static_cast<entity*>(other->GetUserData())) && (!other->IsSensor() || e->g_id == 109 || e->g_id == 2 || e->g_id == 6)) {
if ((e = static_cast<entity*>(other->GetUserData())) && (!other->IsSensor() || e->g_id == O_INTERACTIVE_BALL || e->g_id == O_BALL || e->g_id == O_METAL_BALL)) {
switch (this->object_type) {
case OBJECT_FIELD_ID:
if (this->properties[2].v.i == e->id) {
Expand Down Expand Up @@ -196,7 +196,7 @@ objectfield::on_untouch(b2Fixture *my, b2Fixture *other)
if (this->object_type == OBJECT_FIELD_TARGET_SETTER) return;

entity *e;
if ((e = static_cast<entity*>(other->GetUserData())) && (!other->IsSensor() || e->g_id == 109 || e->g_id == 2 || e->g_id == 6)) {
if ((e = static_cast<entity*>(other->GetUserData())) && (!other->IsSensor() || e->g_id == O_INTERACTIVE_BALL || e->g_id == O_BALL || e->g_id == O_METAL_BALL)) {
switch (this->object_type) {
case OBJECT_FIELD_ID:
if (this->properties[2].v.i == e->id) {
Expand Down
3 changes: 3 additions & 0 deletions src/src/robot_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4474,6 +4474,9 @@ robot_parts::base_spear::step()
this->state = SPEAR_RETRACTING;
}
break;

case SPEAR_IDLE:
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/src/wmotor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ wmotor::connection_create_joint(connection *c)
if (c->o->type == ENTITY_PLANK && !c->o->gr) {
rjd.localAnchorB = c->o->world_to_body(this->get_position(), c->f[1]);
rjd.localAnchorB.y = 0.f; /* XXX */
} else if (c->o->type == ENTITY_WHEEL || c->o->g_id == 18) {
} else if (c->o->type == ENTITY_WHEEL || c->o->g_id == O_GEARBOX) {
/* get the centroid of the object */
rjd.localAnchorB = c->o->local_to_body(b2Vec2(0.f,0.f), c->f[1]);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/src/world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2365,9 +2365,9 @@ world::save_partial(std::set<entity*> *entity_list, const char *name, uint32_t p

/* special case for pivots, dampers, etc, YUCK! */
connection *extra_conn = 0;
if (en->g_id == 16) extra_conn = &((pivot_1*)en)->dconn;
else if (en->g_id == 19) extra_conn = &((damper_1*)en)->dconn;
else if (en->g_id == 95) extra_conn = &((rubberband_1*)en)->dconn;
if (en->g_id == O_OPEN_PIVOT) extra_conn = &((pivot_1*)en)->dconn;
else if (en->g_id == O_DAMPER) extra_conn = &((damper_1*)en)->dconn;
else if (en->g_id == O_RUBBERBAND) extra_conn = &((rubberband_1*)en)->dconn;

if (extra_conn) {
connections.insert(extra_conn);
Expand Down

0 comments on commit 87b00fb

Please sign in to comment.