Example #1
0
void handleMousePress()
{
    int left_state = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT);
    int right_state = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT) ;

    if(!sdl_left_state && left_state)
    {
        if(CURRENT_ITEM_DRAGGED != -1)
        {
            if (sdl_mouse_x - SCREEN_SHIFT_X > 0 && sdl_mouse_x - SCREEN_SHIFT_X < SCREEN_WIDTH &&
                sdl_mouse_y - SCREEN_SHIFT_Y > 0 && sdl_mouse_y - SCREEN_SHIFT_Y < SCREEN_HEIGHT)
                drop_item(sdl_mouse_x - SCREEN_SHIFT_X, sdl_mouse_y - SCREEN_SHIFT_Y);
            else if(sdl_mouse_x > SCREEN_WIDTH + 16 + 17 + 79 && sdl_mouse_y > 237 + 19 && sdl_mouse_x < SCREEN_WIDTH + 16 + 17 + 79 + 32 && sdl_mouse_y < 237 + 19 + 32)
            {
                player_equip_item(CURRENT_ITEM_DRAGGED);
                CURRENT_ITEM_DRAGGED = -1;
            }
            else
            {
                CURRENT_ITEM_DRAGGED = -1;
            }
        }
    }

    sdl_left_state = left_state;
    sdl_right_state = right_state;
}
Example #2
0
uint16_t DropRandomItem(struct DropItem* items, uint16_t* item_buffer, struct Solid* solids, uint16_t blocks_destroyed, uint16_t solidIndex)
{
   int i;
   if (blocks_destroyed == 5) //Random drop timer
   {
		blocks_destroyed = RandomNumber() % 6;
		if (blocks_destroyed == 0)
		{
			blocks_destroyed = SPRITE_ITEMBULLET;
		}
		else if (blocks_destroyed == 1)
		{
			blocks_destroyed = SPRITE_ITEMFLAMEBALL;
		}
		else if (blocks_destroyed == 2)
		{
			blocks_destroyed = SPRITE_ITEMSHORTPADDLE;
		}
   		else if (blocks_destroyed == 3)
    	{
    		blocks_destroyed = SPRITE_ITEMLONGPADDLE;
    	}
   		else if (blocks_destroyed == 4)
    	{
    		blocks_destroyed = SPRITE_ITEMFASTBALL;
    	}
   		else
    	{
    		blocks_destroyed = SPRITE_ITEMSLOWBALL;
    	}
		for (i = 0; i < 10; i++)
		{
			if (items[i].sprite.status == 0)
			{
				drop_item(&items[i], item_buffer, blocks_destroyed, solids[solidIndex].y_pos, solids[solidIndex].x_pos);
				break;
			}
		}
		blocks_destroyed = 0;
	}
   return blocks_destroyed;
}
Example #3
0
void PlayerInst::perform_action(GameState* gs, const GameAction& action) {
	event_log("Player id=%d performing act=%d, xy=(%d,%d), frame=%d, origin=%d, room=%d, use_id=%d, use_id2=%d\n",
			this->player_entry(gs).net_id,
			action.act, action.action_x,
			action.action_y, action.frame, action.origin, action.room,
			action.use_id, action.use_id2);
	switch (action.act) {
	case GameAction::MOVE:
		return use_move(gs, action);
	case GameAction::USE_WEAPON:
		return use_weapon(gs, action);
	case GameAction::USE_SPELL:
		return use_spell(gs, action);
	case GameAction::USE_REST:
		return use_rest(gs, action);
	case GameAction::USE_PORTAL:
		return use_dngn_portal(gs, action);
	case GameAction::USE_ITEM:
		return use_item(gs, action);
	case GameAction::PICKUP_ITEM:
		return pickup_item(gs, action);
	case GameAction::DROP_ITEM:
		return drop_item(gs, action);
	case GameAction::DEEQUIP_ITEM:
		return equipment().deequip_type(action.use_id);
	case GameAction::REPOSITION_ITEM:
		return reposition_item(gs, action);
	case GameAction::CHOSE_SPELL:
		spellselect = action.use_id;
		return;
	case GameAction::PURCHASE_FROM_STORE:
		return purchase_from_store(gs, action);
	default:
		printf("PlayerInst::perform_action() error: Invalid action id %d!\n",
				action.act);
		break;
	}
}
Example #4
0
void inventory_screen( int mode )
{
	int i;
	int count = 0;
	item_t *item;
	int k;

	for( i = 0; i < entity[0].inventory_item_count; i++ )
	{
		item = entity[0].inventory[i];

		mvprintw( 2+i, 0, " %c -   %s", 'a'+i, item->name );
		attron( COLOR_PAIR( COLOR_RED ) );
		mvaddch( 2+i, 5, item->face );

		attron( COLOR_PAIR( COLOR_WHITE ) );
		if( item->flags & ITEMFLAG_STACKABLE )
			mvprintw( 2+i, 8+strlen( item->name ), "(%i)", item->quantity );

		count += entity[0].inventory[i]->quantity;
	}	

	mvprintw( 1, 1, "Inventory (%i item%s) - %s", count,
		count != 1 ? "s" : "", inventory_mode_text[mode] );
	
	k = getch();

	switch( mode )
	{
	case mode_view:
		return;
	case mode_drop:
		drop_item( &entity[0], k-'a' );
		break;
	default:
		break;
	}
}
Example #5
0
static turn_command_t process_input_map(game_t * game, int input)
{
    int move;
    item_t ** itemsel;

    switch (input)
    {
        case 'Q':
            if (prompt_yn("Do you want to quit?"))
                return turn_command_quit;
            return turn_command_void;

        case 'g':
        case ',':
            ;
            item_t * item = game->level->map[game->player.mob->position.y * game->level->width + game->player.mob->position.x].item;

            if (item == 0)
            {
                print_msg("Nothing here!");
                return turn_command_void;
            }

            char item_n[100];
            char line[MSGLEN];

            item_name(item_n, item);

            if (!try_give_item(&(game->player), item))
            {
                print_msg("You're carrying too much shit already.");
                wait();
            }
            else
            {
                snprintf(line, MSGLEN,
                         "Okay -- you now have %s.", item_n);
                print_msg(line);
                wait();
                game->level->map[game->player.mob->position.y * game->level->width + game->player.mob->position.x].item = 0;
            }

            clear_msg();
            return turn_command_complete;

        case 'd':
        case 'u':
            if (count_items(&(game->player)) == 0)
            {
                print_msg("You have no items.");
                return turn_command_void;
            }

            if (input == 'd')
                print_msg("Drop which item?");
            else if (input == 'u')
                print_msg("Use which item?");

            itemsel = list_and_select_items(&(game->player), game->player.inventory);

            /* restore view */
            clear_msg();
            draw_map(game->input_type, game->level);

            if (itemsel != NULL)
            {
                if (input == 'd')
                    drop_item(&(game->player), game->level, itemsel);
                else if (input == 'u')
                    use_item(game, itemsel);

                return turn_command_complete;
            }
            return turn_command_void;

        case '.':
            /* Rest/wait/meditate */
            return turn_command_complete;


        case ' ':
            //clear_msg();
            return turn_command_void;

        case '+':
            chaos_duel();
            return turn_command_void;

        case KEY_LEFT:
        case KEY_RIGHT:
        case KEY_UP:
        case KEY_DOWN:
            move = player_move(game, input);
            return move;

        default:
            return turn_command_void;
    }
}
Example #6
0
//--------- Begin of function Unit::deinit ---------//
//
void Unit::deinit()
{
	//---------- free up team_info ----------//

	if( team_info )
	{
		mem_del(team_info);
		team_info = NULL;
	}

	//---------------------------------------//

	// ####### begin Gilbert 22/3 ########//
	if( sys.quick_exit_flag() )
	{
		if( game.is_campaign_mode() )
		{
			// if in campaign mode, free name before exit

			if( name_id )
			{
				if( is_human() && unit_id != UNIT_WAGON )
				{
					if( name_id )
						race_res[race_id]->free_name_id( name_id );
				}
				else if( is_monster() )
				{
					if( name_id )
						monster_res.free_name_id( name_id );
				}
				else  //---- init non-human unit series no. ----//
				{
				}

				name_id = 0;
			}
		}
		return;
	}
	// ####### end Gilbert 22/3 ########//

	//---------------------------------------//

	err_when( unit_array.is_truly_deleted(sprite_recno) );

	if( !unit_id )
		return;

	// ######### begin Gilbert 23/2 #######//
	// -------- update win/lose condition or die -------//

	if( hit_points <= 0.0f || cur_action == SPRITE_DIE )
	{
		game.update_condition_on_killed( unique_id );
	}
	// ######### end Gilbert 23/2 #######//

	//--------- drop item -----------//

	if( !sys.signal_exit_flag && item.id )
	{
		drop_item(COMMAND_AUTO);
	}

	//-------- if this is a king --------//

	if( !sys.signal_exit_flag && nation_recno )
	{
		if( rank_id == RANK_KING )    // check nation_recno because monster kings will die also.
		{
			king_die();
			err_when( unit_array.is_truly_deleted(sprite_recno) );
		}
		else if( rank_id == RANK_GENERAL )
		{
			general_die();
			err_when( unit_array.is_truly_deleted(sprite_recno) );
		}
	}

	// ####### begin Gilbert 12/3 #######//

	// -------- free name id after general_die, which reads name_id ---------//

	if( name_id )
	{
		if( is_human() && unit_id != UNIT_WAGON )
		{
			if( name_id )
				race_res[race_id]->free_name_id( name_id );
		}
		else if( is_monster() )
		{
			if( name_id )
				monster_res.free_name_id( name_id );
		}
		else  //---- init non-human unit series no. ----//
		{
		}

		name_id = 0;
	}

	// ####### end Gilbert 12/3 #######//

	//---- if this is a general, deinit its link with its soldiers ----//
   //
   // We do not use team_info because monsters and rebels also use
	// leader_unit_recno and they do not use keep the member info
   // in team_info.
   //
   //-----------------------------------------------------------------//

   if( rank_id == RANK_GENERAL || rank_id == RANK_KING )
	{
		for( int i=unit_array.size() ; i>0 ; i-- )
      {
         if( unit_array.is_deleted(i) )
            continue;

			if( unit_array[i]->leader_unit_recno == sprite_recno )
				unit_array[i]->leader_unit_recno = 0;
      }
   }

	//----- if this is a unit on a ship ------//

	if( unit_mode == UNIT_MODE_ON_SHIP )
	{
		err_here();
		/*
		if( !unit_array.is_deleted(unit_mode_para) )    // the ship may have been destroyed at the same time. Actually when the ship is destroyed, all units onboard are killed and this function is called.
		{
			Unit* unitPtr = unit_array[unit_mode_para];

			err_when( unit_res[unitPtr->unit_id]->unit_class != UNIT_CLASS_SHIP );

			((UnitMarine*)unitPtr)->del_unit(sprite_recno);
		}
		*/
	}

	//----- if this is a ship in the harbor -----//

	else if( unit_mode == UNIT_MODE_IN_HARBOR )
	{
		err_here();
		/*
		if( !firm_array.is_deleted(unit_mode_para) )    // the ship may have been destroyed at the same time. Actually when the ship is destroyed, all firms onboard are killed and this function is called.
		{
			Firm* firmPtr = firm_array[unit_mode_para];

			err_when( firmPtr->firm_id != FIRM_HARBOR );

			((FirmHarbor*)firmPtr)->del_hosted_ship(sprite_recno);
		}
		*/
	}

	//----- if this unit is a constructor in a firm -------//

	else if( unit_mode == UNIT_MODE_CONSTRUCT_FIRM )
	{
		err_when( firm_array[unit_mode_para]->builder_recno != sprite_recno );

		firm_array[unit_mode_para]->builder_recno = 0;
	}

	//----- if this unit is a constructor in a town -------//

	else if( unit_mode == UNIT_MODE_CONSTRUCT_TOWN )
	{
		err_when( town_array[unit_mode_para]->builder_recno != sprite_recno );

		town_array[unit_mode_para]->builder_recno = 0;
	}

	//-------- if this is a spy ---------//

   if( spy_recno )
   {
      spy_array.del_spy( spy_recno );
		spy_recno = 0;
   }

   //---------- reset command ----------//

   if( power.command_unit_recno == sprite_recno )
      power.reset_command();

   //-----------------------------------//

   deinit_unit_id();

	//----- if cur_x == -1, the unit has not yet been hired -----//

	if( cur_x >= 0 )
		deinit_sprite();
	// ##### patch begin Gilbert 6/10 ######//
	else if( selected_flag )	// caravan may be deinit_sprite(1) and keep selected, now unselect
	{
		int curSelected = unit_array.selected_recno == sprite_recno;		// if it is currently selected unit, reset selected_recno
		deselect();
		if( curSelected && !sys.signal_exit_flag )
			info.disp();
	}
	// ##### patch end Gilbert 6/10 ######//

	//--------------- deinit AI info -------------//

	deinit_ai();

	//-------------- reset unit_id ---------------//

	unit_id = 0;
}