dxx-rebirth/common/main/fwd-weapon.h
2016-08-28 22:41:49 +00:00

250 lines
7.5 KiB
C++

/*
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING.txt.
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license below.
* See COPYING.txt for license details.
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
/*
*
* Protypes for weapon stuff.
*
*/
#pragma once
#ifdef __cplusplus
#include "pstypes.h"
#include "maths.h"
#include "dxxsconf.h"
#include "dsx-ns.h"
#include "compiler-array.h"
#include "weapon_id.h"
#include "fwd-object.h"
enum powerup_type_t : uint8_t;
#if defined(DXX_BUILD_DESCENT_II)
#define LASER_HELIX_MASK 7 // must match number of bits in flags
#define MAX_SUPER_LASER_LEVEL LASER_LEVEL_6 // Note, laser levels are numbered from 0.
#endif
#if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II)
struct PHYSFS_File;
#if 0
void weapon_info_write(PHYSFS_File *, const weapon_info &);
#endif
namespace dsx {
enum laser_level_t : uint8_t;
class stored_laser_level;
struct weapon_info;
#define REARM_TIME (F1_0)
#define WEAPON_DEFAULT_LIFETIME (F1_0*12) // Lifetime of an object if a bozo forgets to define it.
#define WEAPON_TYPE_WEAK_LASER 0
#define WEAPON_TYPE_STRONG_LASER 1
#define WEAPON_TYPE_CANNON_BALL 2
#define WEAPON_TYPE_MISSILE 3
#define WEAPON_RENDER_NONE -1
#define WEAPON_RENDER_LASER 0
#define WEAPON_RENDER_BLOB 1
#define WEAPON_RENDER_POLYMODEL 2
#define WEAPON_RENDER_VCLIP 3
#if defined(DXX_BUILD_DESCENT_I)
constexpr unsigned MAX_WEAPON_TYPES = 30;
constexpr unsigned MAX_PRIMARY_WEAPONS = 5;
constexpr unsigned MAX_SECONDARY_WEAPONS = 5;
#elif defined(DXX_BUILD_DESCENT_II)
// weapon info flags
#define WIF_PLACABLE 1 // can be placed by level designer
constexpr unsigned MAX_WEAPON_TYPES = 70;
constexpr unsigned MAX_PRIMARY_WEAPONS = 10;
constexpr unsigned MAX_SECONDARY_WEAPONS = 10;
#endif
extern const array<weapon_id_type, MAX_PRIMARY_WEAPONS> Primary_weapon_to_weapon_info;
//for each primary weapon, what kind of powerup gives weapon
extern const array<powerup_type_t, MAX_PRIMARY_WEAPONS> Primary_weapon_to_powerup;
extern const array<weapon_id_type, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_weapon_info;
//for each Secondary weapon, what kind of powerup gives weapon
extern const array<powerup_type_t, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_powerup;
extern const array<uint8_t, MAX_SECONDARY_WEAPONS> Secondary_ammo_max;
/*
* reads n weapon_info structs from a PHYSFS_File
*/
typedef array<weapon_info, MAX_WEAPON_TYPES> weapon_info_array;
extern weapon_info_array Weapon_info;
void weapon_info_read_n(weapon_info_array &wi, std::size_t count, PHYSFS_File *fp, int file_version, std::size_t offset = 0);
//given a weapon index, return the flag value
#define HAS_PRIMARY_FLAG(index) (1<<(index))
#define HAS_SECONDARY_FLAG(index) (1<<(index))
// Weapon flags, if player->weapon_flags & WEAPON_FLAG is set, then the player has this weapon
#define HAS_LASER_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::LASER_INDEX)
#define HAS_VULCAN_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::VULCAN_INDEX)
#define HAS_SPREADFIRE_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::SPREADFIRE_INDEX)
#define HAS_PLASMA_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::PLASMA_INDEX)
#define HAS_FUSION_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::FUSION_INDEX)
enum primary_weapon_index_t : uint8_t;
enum secondary_weapon_index_t : uint8_t;
#define NUM_SMART_CHILDREN 6 // Number of smart children created by default.
#if defined(DXX_BUILD_DESCENT_I)
#define NUM_SHAREWARE_WEAPONS 3 //in shareware, old get first 3 of each
#elif defined(DXX_BUILD_DESCENT_II)
#define HAS_SUPER_LASER_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::SUPER_LASER_INDEX)
#define HAS_GAUSS_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::GAUSS_INDEX)
#define HAS_HELIX_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::HELIX_INDEX)
#define HAS_PHOENIX_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::PHOENIX_INDEX)
#define HAS_OMEGA_FLAG HAS_PRIMARY_FLAG(primary_weapon_index_t::OMEGA_INDEX)
#define SUPER_WEAPON 5
//flags whether the last time we use this weapon, it was the 'super' version
#endif
//for each Secondary weapon, which gun it fires out of
extern const array<uint8_t, MAX_SECONDARY_WEAPONS> Secondary_weapon_to_gun_num;
}
namespace dcx {
extern unsigned N_weapon_types;
template <typename T>
class player_selected_weapon
{
T active, delayed;
public:
operator T() const
{
return get_active();
}
T get_active() const
{
return active;
}
T get_delayed() const
{
return delayed;
}
player_selected_weapon &operator=(T v)
{
active = v;
set_delayed(v);
return *this;
}
void set_delayed(T v)
{
delayed = v;
}
};
}
#ifdef dsx
namespace dsx {
void do_primary_weapon_select(uint_fast32_t weapon_num);
void do_secondary_weapon_select(uint_fast32_t weapon_num);
}
#endif
void auto_select_primary_weapon();
void auto_select_secondary_weapon();
#ifdef dsx
namespace dsx {
void select_primary_weapon(const char *weapon_name, uint_fast32_t weapon_num, int wait_for_rearm);
void select_secondary_weapon(const char *weapon_name, uint_fast32_t weapon_num, int wait_for_rearm);
}
#endif
class has_weapon_result;
//-----------------------------------------------------------------------------
// Return:
// Bits set:
// HAS_WEAPON_FLAG
// HAS_ENERGY_FLAG
// HAS_AMMO_FLAG
#ifdef dsx
namespace dsx {
has_weapon_result player_has_primary_weapon(int weapon_num);
}
#endif
has_weapon_result player_has_secondary_weapon(int weapon_num);
//called when one of these weapons is picked up
//when you pick up a secondary, you always get the weapon & ammo for it
#ifdef dsx
namespace dsx {
int pick_up_secondary(int weapon_index,int count);
//called when a primary weapon is picked up
//returns true if actually picked up
}
#endif
int pick_up_primary(int weapon_index);
//called when ammo (for the vulcan cannon) is picked up
int pick_up_vulcan_ammo(uint_fast32_t ammo_count, bool change_weapon = true);
namespace dsx {
//this function is for when the player intentionally drops a powerup
objptridx_t spit_powerup(vobjptr_t spitter, int id, int seed);
#if defined(DXX_BUILD_DESCENT_II)
int attempt_to_steal_item(vobjptridx_t objp, vobjptr_t playerobjp);
#define SMEGA_ID 40
extern void rock_the_mine_frame(void);
extern void smega_rock_stuff(void);
extern void init_smega_detonates(void);
extern fix64 Seismic_disturbance_end_time;
#endif
}
#endif
#ifdef dsx
namespace dsx {
void InitWeaponOrdering();
}
#endif
void CyclePrimary();
void CycleSecondary();
void ReorderPrimary();
void ReorderSecondary();
#ifdef dsx
namespace dsx {
#if defined(DXX_BUILD_DESCENT_II)
void check_to_use_primary_super_laser();
void init_seismic_disturbances(void);
void process_super_mines_frame(void);
void do_seismic_stuff();
#endif
void DropCurrentWeapon();
void DropSecondaryWeapon();
}
#endif
#endif