Esempio n. 1
0
/* building_ready values:
 *  - negative if a building is in progress
 *  - positive if a building is ready
 *  - zero (BUILDING_NONE) if no building is ready */
void game_sidebar_button_build_click(UI_WIDGET *widget, unsigned int type, UI_EVENT *e) {
	if(e&&e->mouse->buttons&UI_EVENT_MOUSE_BUTTON_RIGHT)
		building_cancel=1;
	UI_PROPERTY_VALUE v;
	int i=0;
	// Find the building number.
	for(; i<4&&widget!=game_sidebar_button_build[i]; i++);
	if(i==4) {
		//Special buildings
		for(; i<7&&widget!=game_specialbar_button_build[i-4]; i++);
		if(i==7) {
			panelist_game_sidebar.next=panelist_game_sidebar.next==&panelist_game_abilitybar?&panelist_game_specialbar:&panelist_game_abilitybar;
			ui_selected_widget=NULL;
			return;
		}
	}
	if(!building_cancel) {
		if(building_ready==BUILDING_SCOUT+i) {
			// If the building is ready, place it.
			building_place=building_ready;
		} else if(building_ready==BUILDING_NONE) { 
			//Build if no there are no buildings in progress nor other buildings ready.
			client_message_send(player_id, MSG_SEND_START_BUILD, BUILDING_SCOUT+i, MSG_BUILDING_START, NULL);
			v.p=game_sidebar_progress_build;
			widget->set_prop(widget, UI_BUTTON_PROP_CHILD, v);
			game_set_building_progress(0, 0);
			game_set_building_ready(-(BUILDING_SCOUT+i));
		}
	} else if(ABS(building_ready)==BUILDING_SCOUT+i) {
		//Cancel if the building is is in progress or ready and shift is pressed
		client_message_send(player_id, MSG_SEND_START_BUILD, BUILDING_SCOUT+i, MSG_BUILDING_STOP, NULL);
		if(i<4)
			v.p=game_sidebar_label_build[i];
		else {
			v.p=game_specialbar_label_build[i-4];
			panelist_game_sidebar.next=&panelist_game_abilitybar;
		}
		widget->set_prop(widget, UI_BUTTON_PROP_CHILD, v);
		game_set_building_progress(0, 0);
		game_set_building_ready(BUILDING_NONE); // No buildings in progress
		building_place=-1;
	}
	ui_selected_widget=NULL;
}
Esempio n. 2
0
// 网络来的指令, 这里获得的包数据是一个网络包, 需要分拆为各个消息包.
int CALLBACK Net_ProcessRecv( char *pack_data, int packlen, int sock_index  )
{
	short cmd;
	int allsize;
	int tmpsize;
	short datasize;
	char *ptr;
	if( pack_data == NULL || packlen < 0 || packlen >= 2048 )
		return -1;
	ptr = pack_data;
	// || CMDS_COMMAND | datasize[short] | ... ||
	allsize = 0;
	while(1)
	{
		tmpsize = 0;
		if( allsize >= packlen )
			break;
		cmd = *((short *)ptr); ptr+=sizeof(short);tmpsize+=sizeof(short);
		datasize = *((short *)ptr); ptr+=sizeof(short);tmpsize+=sizeof(short);
		allsize += tmpsize;
		if( datasize < 0 )
			return -1;
		assert(allsize>=0);
		assert(datasize>=0);
		switch(cmd)
		{
		case CMDS_LOGIN:		// || ... | result[byte] ||
			tmpsize = datasize;
			client_message_send( CMD_LOGIN, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		case CMDS_ENTERINFO:		// || ... | result[byte] ||
			tmpsize = datasize;
			client_message_send( CMD_ENTERINFO, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		case CMDS_LIST:		// || ... | result[byte] ||
			tmpsize = datasize;
			client_message_send( CMD_LIST, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		case CMDS_CREATE:		// || ... | result[byte] ||
			tmpsize = datasize;
			client_message_send( CMD_CREATE, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		case CMDS_ENTERGAME:	// || ... | result[byte] | ActorID[int] | characterset[short] | posx[short] | posy[short] ||
			tmpsize = datasize;
			client_message_send( CMD_ENTERGAME, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			g_enter_num++;
			break;
		case CMDS_MOVE:			// || ... | ActorID[int] | posx[short] | posy[short] ||
			tmpsize = datasize;
			client_message_send( CMD_MOVE, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		case CMDS_TALK:			// || ... | type[byte] | ActorID[int] | msgsize[short] | pText[msgsize] ||
			tmpsize = datasize;
			client_message_send( CMD_TALK, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		case CMDS_FIGHT:
			tmpsize = datasize;
			client_message_send( CMD_FIGHT, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		case CMDS_FIGHT_PROCESS:
			tmpsize = datasize;
			client_message_send( CMD_FIGHT_PROCESS, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		case CMDS_COORDINATE:
			tmpsize = datasize;
			client_message_send( CMD_COORDINATE, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		case CMDS_STSTCHANGE:
			tmpsize = datasize;
			client_message_send( CMD_STSTCHANGE, ptr, tmpsize, sock_index );
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		default:
			tmpsize = datasize;
			ptr += tmpsize;
			allsize += tmpsize;
			break;
		}
	}
	return 0;
}
Esempio n. 3
0
void game_view_buttons(UI_WIDGET *widget, unsigned int type, UI_EVENT *e) {
	int scroll_x=0, scroll_y=0;
	int screen_w=platform.screen_w, screen_h=platform.screen_h;
	
	//darnit buttons have no press or release events, we have to handle this ourselves
	
	//View movement
	if(!chat_is_visible(&panelist_game_sidebar)) {
		if(e->buttons->left&&map->cam_x>-((screen_w-sidebar_width)/2))
			scroll_x=-SCROLL_SPEED;
		else if(e->buttons->right&&map->cam_x<map_w-(screen_w-sidebar_width)/2)
			scroll_x=SCROLL_SPEED;
		if(e->buttons->up&&map->cam_y>-(screen_h)/2)
			scroll_y=-SCROLL_SPEED;
		else if(e->buttons->down&&map->cam_y<map_h-screen_h/2)
			scroll_y=SCROLL_SPEED;
			
		if(e->buttons->l) {
			scroll_x*=2;
			scroll_y*=2;
		}
		if(scroll_x||scroll_y) {
			d_map_camera_move(map, map->cam_x+scroll_x, map->cam_y+scroll_y);
			map_minimap_update_viewport();
		}
	}
	if(!(platform.platform&DARNIT_PLATFORM_MAEMO)||e->buttons->select) {
		//Interaction keys
		if(e->buttons->start&&!prevbuttons.start)
			game_state(GAME_STATE_GAME_MENU);
		if(e->buttons->a&&!prevbuttons.a)
			chat_toggle(&panelist_game_sidebar);
		if(e->buttons->b&&!prevbuttons.b) {
			if(building_place>-1) {
				building_place=-1;
			} else if(map_selected_building()) {
				client_message_send(player_id, MSG_SEND_PLACE_BUILDING, BUILDING_NONE, map_selected_index(), NULL);
				map_select_nothing();
			}
		}
		if(e->buttons->x&&!prevbuttons.x) {
			DARNIT_MOUSE m=d_mouse_get();
			UI_EVENT_MOUSE e_m={
				0,
				0,
				UI_EVENT_MOUSE_BUTTON_LEFT,
				0,
			};
			e_m.x=m.x; e_m.y=m.y;
			UI_EVENT e={.mouse=&e_m};
			ui_event_global_send(UI_EVENT_TYPE_MOUSE_PRESS, &e);
		}
		if(e->buttons->y&&!prevbuttons.y) {
			if(building_place==-1&&ability_place==0) {
				int selected_building=map_selected_building();
				if(attacker_target)
					attacker_target=0;
				else if(map_selected_owner()==player_id&&(selected_building==BUILDING_ATTACKER||selected_building==BUILDING_SCOUT))
					attacker_target=1;
			}
		}
	}