JNIEXPORT void JNICALL Java_net_hackcasual_freeciv_NativeHarness_sendNativeCommand (JNIEnv * env, jobject obj, jint command) { civ_lock(); switch (command) { case COM_GO_TO: key_unit_goto(); break; case COM_BUILD_CITY: key_unit_build_city(); break; case COM_END_TURN: dsend_packet_player_phase_done(&client.conn, game.info.turn); break; case COM_EXPLORE: key_unit_auto_explore(); break; case COM_AUTO_WORKER: key_unit_auto_settle(); break; case COM_SENTRY: key_unit_sentry(); break; case COM_FORTIFY: key_unit_fortify(); break; case COM_DISBAND: key_unit_disband(); break; case COM_ROAD: key_unit_road(); break; case COM_IRRIGATION: key_unit_irrigate(); break; case COM_CONNECT_ROAD: key_unit_connect(ACTIVITY_ROAD); break; case COM_CONNECT_IRRIGATION: key_unit_connect(ACTIVITY_IRRIGATE); break; case COM_CONNECT_RAILROAD: key_unit_connect(ACTIVITY_RAILROAD); break; case COM_WAIT: key_unit_wait(); break; case COM_BUILD_WONDER: key_unit_build_wonder(); break; case COM_TRADE_ROUTE: key_unit_trade_route(); break; case COM_MINE: key_unit_mine(); break; case COM_TRANSFORM: key_unit_transform(); break; case COM_FORTRESS: key_unit_fortress(); break; case COM_AIRBASE: key_unit_airbase(); break; case COM_POLLUTION: key_unit_pollution(); break; case COM_FALLOUT: key_unit_fallout(); break; case COM_PARADROP: key_unit_paradrop(); break; case COM_PILLAGE: key_unit_pillage(); break; case COM_HOMECITY: key_unit_homecity(); break; case COM_UNLOAD_TRANSPORT: key_unit_unload_all(); break; case COM_LOAD: unit_list_iterate(get_units_in_focus(), punit) { request_unit_load(punit, NULL); } unit_list_iterate_end; break; case COM_UNLOAD: unit_list_iterate(get_units_in_focus(), punit) { request_unit_unload(punit); } unit_list_iterate_end;
/************************************************************************** Sets the "page" that the client should show. See documentation in pages_g.h. **************************************************************************/ void real_set_client_page(enum client_pages page) { switch (old_page) { case PAGE_MAIN: popdown_start_menu(); break; case PAGE_LOAD: popdown_load_game_dialog(); break; case PAGE_NETWORK: close_connection_dialog(); break; case PAGE_START: popdown_conn_list_dialog(); break; case PAGE_GAME: close_game_page(); break; default: break; } switch (page) { case PAGE_MAIN: show_main_page(); break; case PAGE_LOAD: client_start_server(); break; case PAGE_NETWORK: popup_join_game_dialog(); break; case PAGE_START: conn_list_dialog_update(); break; case PAGE_GAME: show_game_page(); enable_main_widgets(); update_info_label(); unit_focus_update(); update_unit_info_label(get_units_in_focus()); update_turn_done_button_state(); refresh_overview(); menus_update(); break; default: break; } old_page = page; }
/************************************************************************** User has responded to goto dialog **************************************************************************/ static void goto_cmd_callback(GtkWidget *dlg, gint arg) { switch (arg) { case GTK_RESPONSE_CANCEL: center_tile_mapcanvas(original_tile); break; case CMD_AIRLIFT: { struct city *pdestcity = get_selected_city(); if (pdestcity) { unit_list_iterate(get_units_in_focus(), punit) { if (unit_can_airlift_to(punit, pdestcity)) { request_unit_airlift(punit, pdestcity); } } unit_list_iterate_end; } } break; case CMD_GOTO: { struct city *pdestcity = get_selected_city(); if (pdestcity) { unit_list_iterate(get_units_in_focus(), punit) { send_goto_tile(punit, pdestcity->tile); } unit_list_iterate_end; } } break; default: break; }
/************************************************************************** Called when the tileset is changed to reset unit pixmaps. **************************************************************************/ void reset_unit_below_pixmaps(void) { long i; for (i = 0; i < num_units_below; i++) { XFreePixmap(display, unit_below_pixmap[i]); } xaw_set_bitmap(more_arrow_label, None); fill_unit_below_pixmaps(); set_unit_icons_more_arrow(FALSE); if (get_num_units_in_focus() == 1) { set_unit_icon(-1, head_of_units_in_focus()); } else { set_unit_icon(-1, NULL); } update_unit_pix_label(get_units_in_focus()); }
/**************************************************************************** Really resize the main window. ****************************************************************************/ static void real_resize_window_callback(void *data) { struct widget *widget; Uint32 flags = Main.screen->flags; if (gui_sdl_fullscreen) { flags |= SDL_FULLSCREEN; } else { flags &= ~SDL_FULLSCREEN; } set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height, flags); if (C_S_RUNNING == client_state()) { /* Move units window to botton-right corner. */ set_new_unitinfo_window_pos(); /* Move minimap window to botton-left corner. */ set_new_minimap_window_pos(); /* Move cooling/warming icons to botton-right corner. */ widget = get_widget_pointer_form_main_list(ID_WARMING_ICON); widget_set_position(widget, (Main.screen->w - adj_size(10) - (widget->size.w * 2)), widget->size.y); widget = get_widget_pointer_form_main_list(ID_COOLING_ICON); widget_set_position(widget, (Main.screen->w - adj_size(10) - widget->size.w), widget->size.y); map_canvas_resized(Main.screen->w, Main.screen->h); update_info_label(); update_unit_info_label(get_units_in_focus()); center_on_something(); /* With redrawing full map. */ update_order_widgets(); } else { draw_intro_gfx(); dirty_all(); } flush_all(); }
/************************************************************************** This function will reset the mouse cursor if it leaves the map. **************************************************************************/ gboolean leave_mapcanvas(GtkWidget *widget, GdkEventCrossing *event) { if (gtk_notebook_get_current_page(GTK_NOTEBOOK(top_notebook)) != gtk_notebook_page_num(GTK_NOTEBOOK(top_notebook), map_widget)) { /* Map is not currently topmost tab. Do not use tile specific cursors. */ update_mouse_cursor(CURSOR_DEFAULT); return TRUE; } /* Bizarrely, this function can be called even when we don't "leave" * the map canvas, for instance, it gets called any time the mouse is * clicked. */ if (map_exists() && event->x >= 0 && event->y >= 0 && event->x < mapview.width && event->y < mapview.height) { control_mouse_cursor(canvas_pos_to_tile(event->x, event->y)); } else { update_mouse_cursor(CURSOR_DEFAULT); } update_unit_info_label(get_units_in_focus()); return TRUE; }
// TODO: Support irrigation modes JNIEXPORT jbyteArray JNICALL Java_net_hackcasual_freeciv_NativeHarness_getAvailableCommandsForActiveUnit (JNIEnv * env, jobject obj) { struct unit * pUnit; char availCommands[COM_UNIT_LAST]; int commandCount = 0; pUnit = head_of_units_in_focus(); if (pUnit) { struct tile *pTile = pUnit->tile; struct city *pCity = tile_city(pTile); struct terrain *pTerrain = tile_terrain(pTile); struct base_type *pbase; struct unit_list *punits = get_units_in_focus(); if (can_unit_build_city(pUnit)) { availCommands[commandCount++] = COM_BUILD_CITY; } if (can_unit_do_activity(pUnit, ACTIVITY_GOTO)) { availCommands[commandCount++] = COM_GO_TO; availCommands[commandCount++] = COM_GO_TO_CITY; } if (can_unit_do_activity(pUnit, ACTIVITY_SENTRY)) { availCommands[commandCount++] = COM_SENTRY; } if (can_unit_do_activity(pUnit, ACTIVITY_FORTIFYING)) { availCommands[commandCount++] = COM_FORTIFY; } if (can_unit_do_activity(pUnit, ACTIVITY_EXPLORE)) { availCommands[commandCount++] = COM_EXPLORE; } availCommands[commandCount++] = COM_DISBAND; if (can_unit_do_activity(pUnit, ACTIVITY_ROAD) || can_unit_do_activity(pUnit, ACTIVITY_RAILROAD)) { availCommands[commandCount++] = COM_ROAD; } if (can_unit_do_activity(pUnit, ACTIVITY_IRRIGATE)) { availCommands[commandCount++] = COM_IRRIGATION; } if (can_unit_do_autosettlers(pUnit)) { availCommands[commandCount++] = COM_AUTO_WORKER; } if (can_unit_do_connect(pUnit, ACTIVITY_IRRIGATE)) { availCommands[commandCount++] = COM_CONNECT_IRRIGATION; } if (can_unit_do_connect(pUnit, ACTIVITY_ROAD)) { availCommands[commandCount++] = COM_CONNECT_ROAD; } if (can_unit_do_connect(pUnit, ACTIVITY_RAILROAD)) { availCommands[commandCount++] = COM_CONNECT_RAILROAD; } availCommands[commandCount++] = COM_WAIT; if (unit_can_help_build_wonder_here(pUnit)) { availCommands[commandCount++] = COM_BUILD_WONDER; } if (unit_can_est_trade_route_here(pUnit)) { availCommands[commandCount++] = COM_TRADE_ROUTE; } if (can_unit_do_activity(pUnit, ACTIVITY_MINE)) { availCommands[commandCount++] = COM_MINE; } if (can_unit_do_activity(pUnit, ACTIVITY_TRANSFORM)) { availCommands[commandCount++] = COM_TRANSFORM; } pbase = get_base_by_gui_type(BASE_GUI_FORTRESS, pUnit, pUnit->tile); if (!pCity && pbase) { availCommands[commandCount++] = COM_FORTRESS; } pbase = get_base_by_gui_type(BASE_GUI_AIRBASE, pUnit, pUnit->tile); if (!pCity && pbase) { availCommands[commandCount++] = COM_AIRBASE; } if (can_unit_do_activity(pUnit, ACTIVITY_POLLUTION)) { availCommands[commandCount++] = COM_POLLUTION; } if (can_unit_do_activity(pUnit, ACTIVITY_FALLOUT)) { availCommands[commandCount++] = COM_FALLOUT; } if (can_unit_paradrop(pUnit)) { availCommands[commandCount++] = COM_PARADROP; } if (can_unit_do_activity(pUnit, ACTIVITY_PILLAGE)) { availCommands[commandCount++] = COM_FALLOUT; } if (pCity && can_unit_change_homecity(pUnit) && pCity->id != pUnit->homecity) { availCommands[commandCount++] = COM_HOMECITY; } if (pUnit->occupy && get_transporter_occupancy(pUnit) > 0) { availCommands[commandCount++] = COM_UNLOAD_TRANSPORT; } if (units_can_load(punits)) { availCommands[commandCount++] = COM_LOAD; } if (units_can_unload(punits)) { availCommands[commandCount++] = COM_UNLOAD; } if (pCity && pCity->airlift) { availCommands[commandCount++] = COM_AIRLIFT; } if (pCity && can_upgrade_unittype(client.conn.playing, unit_type(pUnit))) { availCommands[commandCount++] = COM_UPGRADE; } if (diplomat_can_do_action(pUnit, DIPLOMAT_ANY_ACTION, pUnit->tile)) { availCommands[commandCount++] = COM_DIPLOMAT; } if (unit_has_type_flag(pUnit, F_NUCLEAR)) { availCommands[commandCount++] = COM_NUKE; } } jbyteArray commands; commands = (*env)->NewByteArray(env, commandCount); (*env)->SetByteArrayRegion(env, commands, 0, commandCount, (jbyte *)availCommands); return commands; }
/************************************************************************** ... **************************************************************************/ static int unit_order_callback(struct widget *pOrder_Widget) { if (Main.event.button.button == SDL_BUTTON_LEFT) { struct unit *pUnit = head_of_units_in_focus(); set_wstate(pOrder_Widget, FC_WS_SELLECTED); pSellected_Widget = pOrder_Widget; if (!pUnit) { return -1; } switch (pOrder_Widget->ID) { case ID_UNIT_ORDER_BUILD_CITY: /* Enable the button for adding to a city in all cases, so we get an eventual error message from the server if we try. */ key_unit_build_city(); break; case ID_UNIT_ORDER_BUILD_WONDER: key_unit_build_wonder(); break; case ID_UNIT_ORDER_ROAD: key_unit_road(); break; case ID_UNIT_ORDER_TRADE_ROUTE: key_unit_trade_route(); break; case ID_UNIT_ORDER_IRRIGATE: key_unit_irrigate(); break; case ID_UNIT_ORDER_MINE: key_unit_mine(); break; case ID_UNIT_ORDER_TRANSFORM: key_unit_transform(); break; case ID_UNIT_ORDER_FORTRESS: key_unit_fortress(); break; case ID_UNIT_ORDER_FORTIFY: key_unit_fortify(); break; case ID_UNIT_ORDER_AIRBASE: key_unit_airbase(); break; case ID_UNIT_ORDER_POLLUTION: key_unit_pollution(); break; case ID_UNIT_ORDER_PARADROP: key_unit_paradrop(); break; case ID_UNIT_ORDER_FALLOUT: key_unit_fallout(); break; case ID_UNIT_ORDER_SENTRY: key_unit_sentry(); break; case ID_UNIT_ORDER_PILLAGE: key_unit_pillage(); break; case ID_UNIT_ORDER_HOMECITY: key_unit_homecity(); break; case ID_UNIT_ORDER_UNLOAD_TRANSPORTER: key_unit_unload_all(); break; case ID_UNIT_ORDER_LOAD: unit_list_iterate(get_units_in_focus(), punit) { request_unit_load(punit, NULL); } unit_list_iterate_end; break; case ID_UNIT_ORDER_UNLOAD: unit_list_iterate(get_units_in_focus(), punit) { request_unit_unload(punit); } unit_list_iterate_end; break; case ID_UNIT_ORDER_WAKEUP_OTHERS: key_unit_wakeup_others(); break; case ID_UNIT_ORDER_AUTO_SETTLER: unit_list_iterate(get_units_in_focus(), punit) { request_unit_autosettlers(punit); } unit_list_iterate_end;
static PyObject* python_get_units_in_focus(PyObject* self, PyObject* args) { if(PyArg_ParseTuple(args, "") == 0) return NULL; struct unit_list* retval = get_units_in_focus(); return Py_BuildValue("O", py_mapper_unit_list(retval)); }