#pragma once

#include "pickup.qh"
#include <common/items/all.qh>
#include <common/mutators/mutator/powerups/_mod.qh>
// NOTE: ammo doesn't need this powerups include, but it prevents #2994
// TODO: this sort of problem could be fixed by moving away from registries
#include <common/resources/resources.qh>
#ifdef SVQC
    #include <common/resources/sv_resources.qh>
    #include <server/items/items.qh>
#endif

#ifdef GAMEQC
.int spawnflags;
#endif

#ifdef SVQC
bool autocvar_g_pickup_ammo_anyway;
float autocvar_g_pickup_respawntime_ammo;
float autocvar_g_pickup_respawntimejitter_ammo;
#endif

CLASS(Ammo, Pickup)
#ifdef SVQC
    ATTRIB(Ammo, m_pickupevalfunc, float(entity player, entity item), ammo_pickupevalfunc);
    ATTRIB(Ammo, m_respawntime, float, autocvar_g_pickup_respawntime_ammo);
    ATTRIB(Ammo, m_respawntimejitter, float, autocvar_g_pickup_respawntimejitter_ammo);
    ATTRIB(Ammo, m_pickupanyway, bool, autocvar_g_pickup_ammo_anyway);
#endif
ENDCLASS(Ammo)


// NOTE: ammo resource registration order should match ammo (as item) registration order
// see REGISTER_RESOURCE calls order

// ammo type #1: shells
#ifdef GAMEQC
MODEL(Shells_ITEM, Item_Model("a_shells.md3"));
#endif

#ifdef SVQC
int autocvar_g_pickup_shells;
int autocvar_g_pickup_shells_max;
void ammo_shells_init(Pickup this, entity item)
{
    if(!GetResource(item, RES_SHELLS))
        SetResourceExplicit(item, RES_SHELLS, autocvar_g_pickup_shells);
}
#endif

CLASS(Shells, Ammo)
/* spawnfunc  */ ATTRIB(Shells, m_canonical_spawnfunc, string, "item_shells");
#ifdef GAMEQC
/* spawnflags */ ATTRIB(Shells, spawnflags, int, ITEM_FLAG_NORMAL | ITEM_FLAG_RESOURCE);
/* model      */ ATTRIB(Shells, m_model, Model, MDL_Shells_ITEM);
#endif
/* refname    */ ATTRIB(Shells, netname, string, "shells");
/* itemname   */ ATTRIB(Shells, m_name, string, _("Shells"));
/* icon       */ ATTRIB(Shells, m_icon, string, "ammo_shells");
/* color      */ ATTRIB(Shells, m_color, vector, '0.604 0.647 0.671');
#ifdef SVQC
/* botvalue   */ ATTRIB(Shells, m_botvalue, int, 1000);
/* itemid     */ ATTRIB(Shells, m_itemid, int, IT_RESOURCE);
/* iteminit   */ ATTRIB(Shells, m_iteminit, void(Pickup this, entity item), ammo_shells_init);
#endif
ENDCLASS(Shells)
REGISTER_ITEM(Shells, NEW(Shells));

SPAWNFUNC_ITEM(item_shells, ITEM_Shells)


// ammo type #2: bullets
#ifdef GAMEQC
MODEL(Bullets_ITEM, Item_Model("a_bullets.mdl"));
#endif

#ifdef SVQC
int autocvar_g_pickup_nails;
int autocvar_g_pickup_nails_max;
void ammo_bullets_init(Pickup this, entity item)
{
    if(!GetResource(item, RES_BULLETS))
        SetResourceExplicit(item, RES_BULLETS, autocvar_g_pickup_nails);
}
#endif

CLASS(Bullets, Ammo)
/* spawnfunc  */ ATTRIB(Bullets, m_canonical_spawnfunc, string, "item_bullets");
#ifdef GAMEQC
/* spawnflags */ ATTRIB(Bullets, spawnflags, int, ITEM_FLAG_NORMAL | ITEM_FLAG_RESOURCE);
/* model      */ ATTRIB(Bullets, m_model, Model, MDL_Bullets_ITEM);
#endif
/* refname    */ ATTRIB(Bullets, netname, string, "bullets");
/* itemname   */ ATTRIB(Bullets, m_name, string, _("Bullets"));
/* icon       */ ATTRIB(Bullets, m_icon, string, "ammo_bullets");
/* color      */ ATTRIB(Bullets, m_color, vector, '0.678 0.941 0.522');
#ifdef SVQC
/* botvalue   */ ATTRIB(Bullets, m_botvalue, int, 1500);
/* itemid     */ ATTRIB(Bullets, m_itemid, int, IT_RESOURCE);
/* iteminit   */ ATTRIB(Bullets, m_iteminit, void(Pickup this, entity item), ammo_bullets_init);
#endif
ENDCLASS(Bullets)
REGISTER_ITEM(Bullets, NEW(Bullets));

SPAWNFUNC_ITEM(item_bullets, ITEM_Bullets)


// ammo type #3: rockets
#ifdef GAMEQC
MODEL(Rockets_ITEM, Item_Model("a_rockets.md3"));
#endif

#ifdef SVQC
int autocvar_g_pickup_rockets;
int autocvar_g_pickup_rockets_max;
void ammo_rockets_init(Pickup this, entity item)
{
    if(!GetResource(item, RES_ROCKETS))
        SetResourceExplicit(item, RES_ROCKETS, autocvar_g_pickup_rockets);
}
#endif

CLASS(Rockets, Ammo)
/* spawnfunc  */ ATTRIB(Rockets, m_canonical_spawnfunc, string, "item_rockets");
#ifdef GAMEQC
/* spawnflags */ ATTRIB(Rockets, spawnflags, int, ITEM_FLAG_NORMAL | ITEM_FLAG_RESOURCE);
/* model      */ ATTRIB(Rockets, m_model, Model, MDL_Rockets_ITEM);
#endif
/* refname    */ ATTRIB(Rockets, netname, string, "rockets");
/* itename    */ ATTRIB(Rockets, m_name, string, _("Rockets"));
/* icon       */ ATTRIB(Rockets, m_icon, string, "ammo_rockets");
/* color      */ ATTRIB(Rockets, m_color, vector, '0.918 0.686 0.525');
#ifdef SVQC
/* botvalue   */ ATTRIB(Rockets, m_botvalue, int, 1500);
/* itemid     */ ATTRIB(Rockets, m_itemid, int, IT_RESOURCE);
/* iteminit   */ ATTRIB(Rockets, m_iteminit, void(Pickup this, entity item), ammo_rockets_init);
#endif
ENDCLASS(Rockets)
REGISTER_ITEM(Rockets, NEW(Rockets));

SPAWNFUNC_ITEM(item_rockets, ITEM_Rockets)


// ammo type #4: cells
#ifdef GAMEQC
MODEL(Cells_ITEM, Item_Model("a_cells.md3"));
#endif

#ifdef SVQC
int autocvar_g_pickup_cells;
int autocvar_g_pickup_cells_max;
void ammo_cells_init(Pickup this, entity item)
{
    if(!GetResource(item, RES_CELLS))
        SetResourceExplicit(item, RES_CELLS, autocvar_g_pickup_cells);
}
#endif

CLASS(Cells, Ammo)
/* spawnfunc  */ ATTRIB(Cells, m_canonical_spawnfunc, string, "item_cells");
#ifdef GAMEQC
/* spawnflags */ ATTRIB(Cells, spawnflags, int, ITEM_FLAG_NORMAL | ITEM_FLAG_RESOURCE);
/* model      */ ATTRIB(Cells, m_model, Model, MDL_Cells_ITEM);
#endif
/* refname    */ ATTRIB(Cells, netname, string, "cells");
/* itemname   */ ATTRIB(Cells, m_name, string, _("Cells"));
/* icon       */ ATTRIB(Cells, m_icon, string, "ammo_cells");
/* color      */ ATTRIB(Cells, m_color, vector, '0.545 0.882 0.969');
#ifdef SVQC
/* botvalue   */ ATTRIB(Cells, m_botvalue, int, 1500);
/* itemid     */ ATTRIB(Cells, m_itemid, int, IT_RESOURCE);
/* iteminit   */ ATTRIB(Cells, m_iteminit, void(Pickup this, entity item), ammo_cells_init);
#endif
ENDCLASS(Cells)
REGISTER_ITEM(Cells, NEW(Cells));

SPAWNFUNC_ITEM(item_cells, ITEM_Cells)


// ammo type #5: fuel
#ifdef GAMEQC
MODEL(Fuel_ITEM, Item_Model("g_fuel.md3"));
#endif

#ifdef SVQC
int autocvar_g_pickup_fuel;
int autocvar_g_pickup_fuel_max;
void ammo_fuel_init(Pickup this, entity item)
{
    if(!GetResource(item, RES_FUEL))
        SetResourceExplicit(item, RES_FUEL, autocvar_g_pickup_fuel);
}
#endif

CLASS(Fuel, Ammo)
/* spawnfunc  */ ATTRIB(Fuel, m_canonical_spawnfunc, string, "item_fuel");
#ifdef GAMEQC
/* spawnflags */ ATTRIB(Fuel, spawnflags, int, ITEM_FLAG_NORMAL | ITEM_FLAG_RESOURCE);
/* model      */ ATTRIB(Fuel, m_model, Model, MDL_Fuel_ITEM);
#endif
/* refname    */ ATTRIB(Fuel, netname, string, "fuel");
/* itemname   */ ATTRIB(Fuel, m_name, string, _("Fuel"));
/* icon       */ ATTRIB(Fuel, m_icon, string, "ammo_fuel");
/* color      */ ATTRIB(Fuel, m_color, vector, '0.984 0.878 0.506');
#ifdef SVQC
/* botvlaue   */ ATTRIB(Fuel, m_botvalue, int, 2000);
/* itemid     */ ATTRIB(Fuel, m_itemid, int, IT_RESOURCE);
/* iteminit   */ ATTRIB(Fuel, m_iteminit, void(Pickup this, entity item), ammo_fuel_init);
#endif
ENDCLASS(Fuel)
REGISTER_ITEM(Fuel, NEW(Fuel));

SPAWNFUNC_ITEM(item_fuel, ITEM_Fuel)
