Minor fixes

* Be more cautious while doing pathfinding
* Be a little more deterministic on network by initialising all member
  fields.
This commit is contained in:
Michał Janiszewski 2016-02-14 21:36:31 +01:00
parent 2ebb691e71
commit a09afd0be5
5 changed files with 21 additions and 27 deletions

View File

@ -183,18 +183,6 @@ bool NetworkPacket::CommandRequiresAuth()
}
}
NetworkPlayer::NetworkPlayer()
{
name[0] = 0;
ping = 0;
flags = 0;
money_spent = MONEY(0, 0);
commands_ran = 0;
group = 0;
last_action = -999;
last_action_coord = {0};
}
void NetworkPlayer::Read(NetworkPacket& packet)
{
const char* name = packet.ReadString();

View File

@ -153,21 +153,21 @@ public:
class NetworkPlayer
{
public:
NetworkPlayer();
NetworkPlayer() = default;
void Read(NetworkPacket& packet);
void Write(NetworkPacket& packet);
void SetName(const char* name);
void AddMoneySpent(money32 cost);
uint8 id;
uint8 name[32 + 1];
uint16 ping;
uint8 flags;
uint8 group;
money32 money_spent;
unsigned int commands_ran;
int last_action;
uint32 last_action_time;
rct_xyz16 last_action_coord;
uint8 id = 0;
uint8 name[32 + 1] = { 0 };
uint16 ping = 0;
uint8 flags = 0;
uint8 group = 0;
money32 money_spent = MONEY(0, 0);
unsigned int commands_ran = 0;
int last_action = -999;
uint32 last_action_time = 0;
rct_xyz16 last_action_coord = { 0 };
};
class NetworkAction
@ -219,7 +219,7 @@ public:
void SetName(std::string name);
rct_string_id GetNameStringId();
std::array<uint8, 8> actions_allowed;
uint8 id;
uint8 id = 0;
private:
std::string name;

View File

@ -7873,7 +7873,7 @@ int peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep *peep)
*RCT2_ADDRESS(0x00F1AEDC, int) = saved_f1aedc;
if (score < best_score || (score == best_score && RCT2_GLOBAL(0x00F1AED3, uint8) < best_sub)) {
chosen_edge = test_edge;
chosen_edge = test_edge;
best_score = score;
best_sub = RCT2_GLOBAL(0x00F1AED3, uint8);
}

View File

@ -796,6 +796,9 @@ static int staff_path_finding_handyman(rct_peep* peep) {
}
// countof(TileDirectionDelta)
assert(direction < 8);
rct_xy16 chosenTile = {
.x = peep->next_x + TileDirectionDelta[direction].x,
.y = peep->next_y + TileDirectionDelta[direction].y
@ -819,7 +822,7 @@ static int staff_path_finding_handyman(rct_peep* peep) {
uint8 staff_direction_surface(rct_peep* peep, uint8 initialDirection) {
uint8 direction = initialDirection;
for (int i = 0; i < 2; ++i) {
for (int i = 0; i < 3; ++i) {
// Looks left and right from initial direction
switch (i) {
case 1:
@ -1038,6 +1041,9 @@ static int staff_path_finding_mechanic(rct_peep* peep) {
direction = staff_mechanic_direction_path(peep, validDirections, pathElement);
}
// countof(TileDirectionDelta)
assert(direction < 8);
rct_xy16 chosenTile = {
.x = peep->next_x + TileDirectionDelta[direction].x,
.y = peep->next_y + TileDirectionDelta[direction].y

View File

@ -4470,7 +4470,7 @@ train_ref vehicle_create_train(int rideIndex, int x, int y, int z, int *remainin
void vehicle_create_trains(int rideIndex, int x, int y, int z, rct_map_element *mapElement)
{
rct_ride *ride = get_ride(rideIndex);
train_ref firstTrain, lastTrain;
train_ref firstTrain = { 0 }, lastTrain = { 0 };
int remainingDistance = 0;
for (int vehicleIndex = 0; vehicleIndex < ride->num_vehicles; vehicleIndex++) {