#include <acknex.h>
#include <default.c>
#include "inventory.c"
#define PRAGMA_PATH "%EXE_DIR%\\templates\\sounds"
#define PRAGMA_PATH "%EXE_DIR%\\templates\\images"
#define PRAGMA_PATH "%EXE_DIR%\\templates\\models"
#define PRAGMA_PATH "%EXE_DIR%\\templates\\levels"
#define MAIN_BAG_ID 1
#define ACTIV_WPN_SLOT_ID 0
SOUND *sndReload = "reload.wav";
SOUND *sndDrop = "getready.wav";
SOUND *sndShot = "shot2.wav";
ENTITY *active_weapon = NULL;
Bag *bag = NULL;
Item *myItems[3];
TEXT *txtItemModelNames = { strings = 3; }
#define SNIPERGUN 0
#define SHOTGUN 1
#define MACHINEGUN 2
action active_weapon_action ()
{
ENTITY *ent = active_weapon;
if ( ent )
{
ent.x = 70;
ent.y = -20;
ent.z = -20;
while ( ent == active_weapon )
wait(1);
ent_remove ( ent );
}
}
function slot_was_clicked ( int occurrence, int bag_id, int slot_id, int placed_item_id, int removed_item_id )
{
if ( ( occurrence == INV_ITEM_REMOVED ) || ( occurrence == INV_ITEM_SWAPPED ) )
{
if (bag_id == MAIN_BAG_ID)
{
if (slot_id == ACTIV_WPN_SLOT_ID)
{
active_weapon = NULL;
}
}
}
if ( ( occurrence == INV_ITEM_PLACED ) || ( occurrence == INV_ITEM_SWAPPED ) )
{
if (bag_id == MAIN_BAG_ID)
{
if (slot_id == ACTIV_WPN_SLOT_ID)
{
active_weapon = ent_createlayer ( (txtItemModelNames.pstring)[placed_item_id], SHOW, 1 );
active_weapon_action ();
snd_play ( sndReload, 100, 0 );
}
}
}
}
ENTITY *create_scenery_object ( var type, VECTOR *vecPos )
{
ENTITY *ent = ent_create ( (txtItemModelNames.pstring)[type], vecPos, NULL );
ent->skill1 = type;
snd_play ( sndDrop, 100, 0 );
return ent;
}
void onMouseLeft ()
{
if ( mouse_panel )
return;
if ( inv_is_floating() )
{
VECTOR vecTemp;
vec_set ( vecTemp, mouse_dir3d );
vec_scale ( vecTemp, 1000 );
vec_add ( vecTemp, camera.x );
c_trace ( camera.x, vecTemp, IGNORE_PASSABLE );
if ( HIT_TARGET )
{
vec_set ( vecTemp, hit.x );
vecTemp.z += 10;
var item_id = inv_get_floating_icon_item ();
ENTITY *entObject = create_scenery_object ( item_id, hit.x );
}
}
else if ( mouse_ent )
{
ENTITY *ent = mouse_ent;
inv_insert_item_into_bag ( bag, myItems[mouse_ent.skill1] );
wait(1); // ent_remove needs a wait before calling it from a 3dgs event
ent_remove ( ent );
}
else if ( active_weapon )
{
snd_play ( sndShot, 100, 0 );
}
}
void newLevel ()
{
level_load ( "" );
ENTITY *entTerrain = ent_create( "water.hmp", nullvector, NULL );
entTerrain.flags2 |= UNTOUCHABLE;
camera.x = -200;
camera.z = 400;
camera.tilt = -60;
inv_run_slot_callback ( bag, ACTIV_WPN_SLOT_ID );
}
function main()
{
mouse_mode = 4;
inv_init();
bag = inv_create_bag ( MAIN_BAG_ID,"bluebar.pcx");
inv_add_slot_to_bag ( bag, ACTIV_WPN_SLOT_ID, 1, "flash2.tga", 0, 0 );
inv_add_slot_to_bag ( bag, 1,0,"flash2.tga",0,120);
inv_add_slot_to_bag ( bag, 2,0,"flash2.tga",0,180);
inv_add_slot_to_bag ( bag, 3,0,"flash2.tga",0,240);
myItems[SNIPERGUN] = inv_create_item ( SNIPERGUN, 1, "icon2.pcx", "icon2.pcx" );
inv_insert_item_into_bag ( bag, myItems[SNIPERGUN] );
str_cpy ( (txtItemModelNames.pstring)[SNIPERGUN], "snipergun.mdl" );
myItems[SHOTGUN] = inv_create_item ( SHOTGUN, 1, "icon3.pcx", "icon3.pcx" );
inv_insert_item_into_bag ( bag, myItems[SHOTGUN] );
str_cpy ( (txtItemModelNames.pstring)[SHOTGUN], "shotgun.mdl" );
myItems[MACHINEGUN] = inv_create_item ( MACHINEGUN, 1, "icon4.pcx", "icon4.pcx" );
inv_insert_item_into_bag ( bag, myItems[MACHINEGUN] );
str_cpy ( (txtItemModelNames.pstring)[MACHINEGUN], "machinegun.mdl" );
set_on_click_callback ( "slot_was_clicked" );
on_mouse_left = onMouseLeft;
on_space = newLevel;
newLevel ();
inv_open_bag ( bag, 0, 0 );
while ( !key_esc )
wait(1);
sys_exit ( NULL );
}