| 1 |
/* |
| 2 |
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
| 3 |
* It is copyright by its individual contributors, as recorded in the |
| 4 |
* project's Git history. See COPYING.txt at the top level for license |
| 5 |
* terms and a link to the Git history. |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* |
| 10 |
* Player Stuff |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
#include "fwd-vclip.h" |
| 15 |
#include "object.h" |
| 16 |
#include "player.h" |
| 17 |
#include "physfsx.h" |
| 18 |
#include "compiler-range_for.h" |
| 19 |
|
| 20 |
namespace dsx { |
| 21 |
|
| 22 |
#if DXX_BUILD_DESCENT == 2 |
| 23 |
const player &get_player_controlling_guidebot(const d_unique_buddy_state & /* reserved for future use */, const valptridx<player>::array_managed_type &Players) |
| 24 |
{ |
| 25 |
/* One day, the game may support letting someone other than player 0 |
| 26 |
* control the guidebot. For now, only player 0 will ever control |
| 27 |
* it. |
| 28 |
*/ |
| 29 |
return Players.front(); |
| 30 |
} |
| 31 |
#endif |
| 32 |
|
| 33 |
void player_rw_swap(player_rw *p, const physfsx_endian swap) |
| 34 |
{ |
| 35 |
if (swap == physfsx_endian::native) |
| 36 |
return; |
| 37 |
|
| 38 |
p->objnum = SWAPINT(p->objnum); |
| 39 |
p->flags = SWAPINT(p->flags); |
| 40 |
p->energy = SWAPINT(p->energy); |
| 41 |
p->shields = SWAPINT(p->shields); |
| 42 |
p->killer_objnum = SWAPSHORT(p->killer_objnum); |
| 43 |
#if DXX_BUILD_DESCENT == 2 |
| 44 |
p->primary_weapon_flags = SWAPSHORT(p->primary_weapon_flags); |
| 45 |
#endif |
| 46 |
p->vulcan_ammo = SWAPSHORT(p->vulcan_ammo); |
| 47 |
for (int i = 0; i < MAX_SECONDARY_WEAPONS; i++) |
| 48 |
p->secondary_ammo[i] = SWAPSHORT(p->secondary_ammo[i]); |
| 49 |
p->last_score = SWAPINT(p->last_score); |
| 50 |
p->score = SWAPINT(p->score); |
| 51 |
p->time_level = SWAPINT(p->time_level); |
| 52 |
p->time_total = SWAPINT(p->time_total); |
| 53 |
p->cloak_time = SWAPINT(p->cloak_time); |
| 54 |
p->invulnerable_time = SWAPINT(p->invulnerable_time); |
| 55 |
#if DXX_BUILD_DESCENT == 2 |
| 56 |
p->KillGoalCount = SWAPSHORT(p->KillGoalCount); |
| 57 |
#endif |
| 58 |
p->net_killed_total = SWAPSHORT(p->net_killed_total); |
| 59 |
p->net_kills_total = SWAPSHORT(p->net_kills_total); |
| 60 |
p->num_kills_level = SWAPSHORT(p->num_kills_level); |
| 61 |
p->num_kills_total = SWAPSHORT(p->num_kills_total); |
| 62 |
p->num_robots_level = SWAPSHORT(p->num_robots_level); |
| 63 |
p->num_robots_total = SWAPSHORT(p->num_robots_total); |
| 64 |
p->hostages_rescued_total = SWAPSHORT(p->hostages_rescued_total); |
| 65 |
p->hostages_total = SWAPSHORT(p->hostages_total); |
| 66 |
p->homing_object_dist = SWAPINT(p->homing_object_dist); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
/* |
| 71 |
* reads a player_ship structure from a PHYSFS_File |
| 72 |
*/ |
| 73 |
void player_ship_read(player_ship *ps, const NamedPHYSFS_File fp) |
| 74 |
{ |
| 75 |
ps->model_num = build_polygon_model_index_from_untrusted(PHYSFSX_readInt(fp)); |
| 76 |
ps->expl_vclip_num = build_vclip_index_from_untrusted(PHYSFSX_readInt(fp)); |
| 77 |
ps->mass = PHYSFSX_readFix(fp); |
| 78 |
ps->drag = PHYSFSX_readFix(fp); |
| 79 |
ps->max_thrust = PHYSFSX_readFix(fp); |
| 80 |
ps->reverse_thrust = PHYSFSX_readFix(fp); |
| 81 |
ps->brakes = PHYSFSX_readFix(fp); |
| 82 |
ps->wiggle = PHYSFSX_readFix(fp); |
| 83 |
ps->max_rotthrust = PHYSFSX_readFix(fp); |
| 84 |
range_for (auto &i, ps->gun_points) |
| 85 |
PHYSFSX_readVector(fp, i); |
| 86 |
} |