Make objnum unsigned

This commit is contained in:
Kp 2015-06-13 22:42:15 +00:00
parent 61019b9dab
commit 9125ae32cd
7 changed files with 24 additions and 64 deletions

View file

@ -446,7 +446,7 @@ enum deres_type_t {
struct owned_remote_objnum
{
int8_t owner;
int16_t objnum;
uint16_t objnum;
};
extern int GetMyNetRanking();

View file

@ -1,10 +1,10 @@
#pragma once
#include "strictindex.h"
DEFINE_STRICT_INDEX_NUMBER(int16_t, objnum_t);
DEFINE_STRICT_INDEX_CONSTANT_TYPE(object_magic_constant_t, objnum_t, int16_t);
DEFINE_STRICT_INDEX_CONSTANT_NUMBER(object_magic_constant_t, -2, object_guidebot_cannot_reach);
DEFINE_STRICT_INDEX_CONSTANT_NUMBER(object_magic_constant_t, -1, object_none);
DEFINE_STRICT_INDEX_NUMBER(uint16_t, objnum_t);
DEFINE_STRICT_INDEX_CONSTANT_TYPE(object_magic_constant_t, objnum_t, uint16_t);
DEFINE_STRICT_INDEX_CONSTANT_NUMBER(object_magic_constant_t, 0xfffe, object_guidebot_cannot_reach);
DEFINE_STRICT_INDEX_CONSTANT_NUMBER(object_magic_constant_t, 0xffff, object_none);
DEFINE_STRICT_INDEX_CONSTANT_NUMBER(object_magic_constant_t, 0, object_first);
class object_signature_t

View file

@ -48,7 +48,6 @@ array<hostage_data, MAX_HOSTAGES> Hostages; // Data for each hostage in m
int hostage_is_valid( int hostage_num ) {
if ( hostage_num < 0 ) return 0;
if ( hostage_num >= MAX_HOSTAGES ) return 0;
if ( Hostages[hostage_num].objnum < 0 ) return 0;
if ( Hostages[hostage_num].objnum > Highest_object_index ) return 0;
if ( Objects[Hostages[hostage_num].objnum].type != OBJ_HOSTAGE ) return 0;
if ( Objects[Hostages[hostage_num].objnum].signature != Hostages[hostage_num].objsig ) return 0;

View file

@ -405,8 +405,7 @@ int ObjectSelectNextInMine()
int ObjectSelectPrevInMine()
{ int i;
for (i=0;i<MAX_OBJECTS;i++) {
Cur_object_index--;
if (Cur_object_index < 0 )
if (!(Cur_object_index --))
Cur_object_index = MAX_OBJECTS-1;
if ((Objects[Cur_object_index ].type != OBJ_NONE) && (Cur_object_index != (ConsoleObject-Objects)) ) {

View file

@ -1077,10 +1077,6 @@ void explode_object(const vobjptridx_t hitobj,fix delay_time)
obj->lifeleft = delay_time;
obj->ctype.expl_info.delete_objnum = hitobj;
#ifndef NDEBUG
if (obj->ctype.expl_info.delete_objnum < 0)
Int3(); // See Rob!
#endif
obj->ctype.expl_info.delete_time = -1;
obj->ctype.expl_info.spawn_time = 0;
@ -1141,12 +1137,6 @@ void do_explosion_sequence(const vobjptr_t obj)
//See if we should create a secondary explosion
if (obj->lifeleft <= obj->ctype.expl_info.spawn_time) {
int vclip_num;
if ((obj->ctype.expl_info.delete_objnum < 0) || (obj->ctype.expl_info.delete_objnum > Highest_object_index)) {
Int3(); // get Rob, please... thanks
return;
}
auto del_obj = vobjptridx(obj->ctype.expl_info.delete_objnum);
auto &spawn_pos = del_obj->pos;
Assert(del_obj->type==OBJ_ROBOT || del_obj->type==OBJ_CLUTTER || del_obj->type==OBJ_CNTRLCEN || del_obj->type == OBJ_PLAYER);
@ -1210,11 +1200,6 @@ void do_explosion_sequence(const vobjptr_t obj)
expl_obj->ctype.expl_info.delete_time = expl_obj->lifeleft/2;
expl_obj->ctype.expl_info.delete_objnum = del_obj;
#ifndef NDEBUG
if (obj->ctype.expl_info.delete_objnum < 0)
Int3(); // See Rob!
#endif
}
else {
maybe_delete_object(del_obj);

View file

@ -135,7 +135,7 @@ int multi_message_index = 0;
ubyte multibuf[MAX_MULTI_MESSAGE_LEN+4]; // This is where multiplayer message are built
static array<array<objnum_t, MAX_OBJECTS>, MAX_PLAYERS> remote_to_local; // Remote object number for each local object
static array<short, MAX_OBJECTS> local_to_remote;
static array<uint16_t, MAX_OBJECTS> local_to_remote;
array<sbyte, MAX_OBJECTS> object_owner; // Who created each object in my universe, -1 = loaded at start
unsigned Net_create_loc; // pointer into previous array
@ -337,8 +337,9 @@ objnum_t objnum_remote_to_local(uint16_t remote_objnum, int8_t owner)
owned_remote_objnum objnum_local_to_remote(objnum_t local_objnum)
{
// Map a local object number to a remote + owner
if ((local_objnum < 0) || (local_objnum > Highest_object_index)) {
return {owner_none, -1};
if (local_objnum > Highest_object_index)
{
return {owner_none, 0xffff};
}
auto owner = object_owner[local_objnum];
if (owner == owner_none)
@ -346,7 +347,7 @@ owned_remote_objnum objnum_local_to_remote(objnum_t local_objnum)
if (owner >= N_players || owner < -1)
throw std::runtime_error("illegal object owner");
auto result = local_to_remote[local_objnum];
if (result < 0)
if (result >= MAX_OBJECTS)
throw std::runtime_error("illegal object remote number"); // See Rob, object has no remote number!
return {owner, result};
}
@ -381,8 +382,6 @@ map_objnum_local_to_remote(int local_objnum, int remote_objnum, int owner)
void map_objnum_local_to_local(objnum_t local_objnum)
{
// Add a mapping for our locally created objects
Assert(local_objnum > -1);
Assert(local_objnum < MAX_OBJECTS);
object_owner[local_objnum] = Player_num;
@ -2131,7 +2130,6 @@ static void multi_do_play_sound(const playernum_t pnum, const ubyte *buf)
if (!Players[pnum].connected)
return;
Assert(Players[pnum].objnum >= 0);
Assert(Players[pnum].objnum <= Highest_object_index);
digi_link_sound_to_object( sound_num, vcobjptridx(Players[pnum].objnum), 0, volume);
}

View file

@ -317,7 +317,7 @@ struct multi_claim_robot
{
uint8_t pnum;
int8_t owner;
int16_t robjnum;
uint16_t robjnum;
};
DEFINE_MULTIPLAYER_SERIAL_MESSAGE(MULTI_ROBOT_CLAIM, multi_claim_robot, b, (b.pnum, b.owner, b.robjnum));
@ -361,7 +361,7 @@ multi_send_robot_frame(int sent)
for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
{
int sending = (last_sent+1+i)%MAX_ROBOTS_CONTROLLED;
if ( (robot_controlled[sending] != -1) && ((robot_send_pending[sending] > sent) || (robot_fired[sending] > sent)) )
if (robot_controlled[sending] != object_none && (robot_send_pending[sending] > sent || robot_fired[sending] > sent))
{
if (robot_send_pending[sending])
{
@ -644,7 +644,8 @@ void multi_do_claim_robot(const playernum_t pnum, const ubyte *buf)
multi_claim_robot b;
multi_serialize_read(buf, b);
auto botnum = objnum_remote_to_local(b.robjnum, b.owner);
if ((botnum > Highest_object_index) || (botnum < 0)) {
if (botnum > Highest_object_index)
{
return;
}
@ -676,7 +677,8 @@ void multi_do_release_robot(const playernum_t pnum, const ubyte *buf)
remote_botnum = GET_INTEL_SHORT(buf + 2);
auto botnum = objnum_remote_to_local(remote_botnum, buf[4]);
if ((botnum < 0) || (botnum > Highest_object_index)) {
if (botnum > Highest_object_index)
{
return;
}
@ -710,7 +712,8 @@ void multi_do_robot_position(const playernum_t pnum, const ubyte *buf)
remote_botnum = GET_INTEL_SHORT(buf + loc);
auto botnum = objnum_remote_to_local(remote_botnum, buf[loc+2]); loc += 3;
if ((botnum < 0) || (botnum > Highest_object_index)) {
if (botnum > Highest_object_index)
{
return;
}
@ -775,7 +778,7 @@ multi_do_robot_fire(const ubyte *buf)
fire.y = (fix)INTEL_INT((int)fire.y);
fire.z = (fix)INTEL_INT((int)fire.z);
if ((botnum < 0) || (botnum > Highest_object_index))
if (botnum > Highest_object_index)
{
return;
}
@ -876,7 +879,8 @@ multi_do_robot_explode(const ubyte *buf)
auto botnum = objnum_remote_to_local(b.robj_killed, b.owner_killed);
// Explode robot controlled by other player
int rval;
if ((botnum < 0) || (botnum > Highest_object_index)) {
if (botnum > Highest_object_index)
{
return;
}
@ -897,7 +901,7 @@ void multi_do_create_robot(const playernum_t pnum, const ubyte *buf)
objnum_t objnum;
objnum = GET_INTEL_SHORT(buf + 3);
if ((objnum < 0) || (fuelcen_num >= Num_fuelcenters) || (pnum >= N_players))
if (fuelcen_num >= Num_fuelcenters || pnum >= N_players)
{
Int3(); // Bogus data
return;
@ -939,11 +943,6 @@ void multi_do_boss_teleport(const playernum_t pnum, const ubyte *buf)
{
boss_teleport b;
multi_serialize_read(buf, b);
if ((b.objnum < 0) || (b.objnum > Highest_object_index))
{
Int3(); // See Rob
return;
}
const vobjptridx_t boss_obj = vobjptridx(b.objnum);
if ((boss_obj->type != OBJ_ROBOT) || !(Robot_info[get_robot_id(boss_obj)].boss_flag))
{
@ -977,11 +976,6 @@ void multi_do_boss_cloak(const ubyte *buf)
{
boss_cloak b;
multi_serialize_read(buf, b);
if ((b.objnum < 0) || (b.objnum > Highest_object_index))
{
Int3(); // See Rob
return;
}
const vobjptridx_t boss_obj = vobjptridx(b.objnum);
if ((boss_obj->type != OBJ_ROBOT) || !(Robot_info[get_robot_id(boss_obj)].boss_flag))
{
@ -1001,11 +995,6 @@ void multi_do_boss_start_gate(const ubyte *buf)
{
boss_start_gate b;
multi_serialize_read(buf, b);
if ((b.objnum < 0) || (b.objnum > Highest_object_index))
{
Int3(); // See Rob
return;
}
const vobjptridx_t boss_obj = vobjptridx(b.objnum);
if ((boss_obj->type != OBJ_ROBOT) || !(Robot_info[get_robot_id(boss_obj)].boss_flag))
{
@ -1019,11 +1008,6 @@ void multi_do_boss_stop_gate(const ubyte *buf)
{
boss_start_gate b;
multi_serialize_read(buf, b);
if ((b.objnum < 0) || (b.objnum > Highest_object_index))
{
Int3(); // See Rob
return;
}
const vobjptridx_t boss_obj = vobjptridx(b.objnum);
if ((boss_obj->type != OBJ_ROBOT) || !(Robot_info[get_robot_id(boss_obj)].boss_flag))
{
@ -1037,11 +1021,6 @@ void multi_do_boss_create_robot(const playernum_t pnum, const ubyte *buf)
{
boss_create_robot b;
multi_serialize_read(buf, b);
if ((b.objnum < 0) || (b.objnum > Highest_object_index))
{
Int3(); // See Rob
return;
}
const vobjptridx_t boss_obj = vobjptridx(b.objnum);
if ((boss_obj->type != OBJ_ROBOT) || !(Robot_info[get_robot_id(boss_obj)].boss_flag))
{
@ -1049,7 +1028,7 @@ void multi_do_boss_create_robot(const playernum_t pnum, const ubyte *buf)
return;
}
// Do some validity checking
if (b.objrobot >= MAX_OBJECTS || b.objrobot < 0)
if (b.objrobot >= MAX_OBJECTS)
{
Int3(); // See Rob, bad data in boss gate action message
return;