#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
#define SNIPERGUN 1
#define SHOTGUN 2
#define MACHINEGUN 3
SOUND *sndReload = "reload.wav";
SOUND *sndDrop = "getready.wav";
SOUND *sndShot = "shot2.wav";
Bag *bag = NULL;
Item *gun1 = NULL;
Item *gun2 = NULL;
Item *gun3 = NULL;
ENTITY *active_weapon = NULL;
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)
{
switch ( placed_item_id )
{
case SNIPERGUN:
active_weapon = ent_createlayer ( "snipergun.mdl", SHOW, 1 );
break;
case SHOTGUN:
active_weapon = ent_createlayer ( "shotgun.mdl", SHOW, 1 );
break;
case MACHINEGUN:
active_weapon = ent_createlayer ( "machinegun.mdl", SHOW, 1 );
break;
}
active_weapon_action ();
snd_play ( sndReload, 100, 0 );
}
}
}
}
ENTITY *create_scenery_object ( var type, VECTOR *vecPos )
{
ENTITY *ent = NULL;
switch ( type )
{
case SNIPERGUN:
ent = ent_create ( "snipergun.mdl", vecPos, NULL );
break;
case SHOTGUN:
ent = ent_create ( "shotgun.mdl", vecPos, NULL );
break;
case MACHINEGUN:
ent = ent_create ( "machinegun.mdl", vecPos, NULL );
break;
}
if ( ent )
{
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 = NULL;
switch ( mouse_ent.skill1 )
{
case SNIPERGUN:
inv_insert_item_into_bag ( bag, gun1 );
ent = mouse_ent;
break;
case SHOTGUN: inv_insert_item_into_bag ( bag, gun2 );
ent = mouse_ent;
break;
case MACHINEGUN: inv_insert_item_into_bag ( bag, gun3 );
ent = mouse_ent;
break;
}
if ( ent )
{
wait(1); // ent_remove needs a wait before calling it from a 3dgs event
ent_remove ( ent );
}
}
else
{
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();
gun1 = inv_create_item ( SNIPERGUN, 1, "icon2.pcx", "icon2.pcx" );
gun2 = inv_create_item ( SHOTGUN, 1, "icon3.pcx", "icon3.pcx" );
gun3 = inv_create_item ( MACHINEGUN, 1, "icon4.pcx", "icon4.pcx" );
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);
inv_insert_item_into_bag ( bag, gun1 );
inv_insert_item_into_bag ( bag, gun2 );
inv_insert_item_into_bag ( bag, gun3 );
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 );
}