Beispiel #1
0
int main() {

	int flag = 1;

	while(flag) {

		printf("\n\nUS Military Encryption Service\n");
		printf("Please input your branch of service:\n");
		printf("0-Exit\t1-Army\t2-Navy\t3-Air Force\n");
		kbhit();
		fflush(stdout);
		char in = getch();

		switch(in) {
			case '0':
				flag = 0;
				break;
			case '1':
				army();
				break;
			case '2':
				navy();
				break;
			case '3':
				airForce();
				break;
			default:
				printf("Error, please enter a valid military branch.\n");
				break;
		}
	}
	return 0;
}
	SearchResults search()
	{		
		// construct the search object
		ArmySearch army(params);

		// run the search 
		SearchResults result = army.search();
		
		// return the results object
		return result;
	}
Beispiel #3
0
sint32 ui_HandleKeypress(WPARAM wParam, LPARAM lParam)
{
    WORLD_DIRECTION	d;
    BOOL			move = FALSE;
#ifdef _PLAYTEST
    int i;
#endif
	BOOL isMyTurn = !g_network.IsActive() || g_network.IsMyTurn();
	Unit city;

	
	if ( g_isKMScreen) {
		switch(wParam) {
			case VK_ESCAPE:
			case VK_LEFT + 256:
			case VK_RIGHT + 256:
			case VK_UP + 256:
			case VK_DOWN + 256:
			case 29: 
			case 28: 
				
				return TRUE;
			default:
				
				km_screen_remapKey( wParam, lParam );
				return TRUE;
		}
	}
	
#ifdef _PLAYTEST
	if(commandMode) {
		switch(wParam) {
			case '\r' + 128: wParam = '\r'; break;
			case '\t' + 128: wParam = '\t'; break;
			case 8 + 128: wParam = 8; break;
		}
		commandMode = g_commandLine.AddKey(static_cast<char>(wParam));
		return TRUE;
	}
#endif






	
	if (wParam == VK_ESCAPE) {
		
		extern OptionsWindow *g_optionsWindow;
		
		if(g_c3ui->TopWindow() && g_c3ui->TopWindow() == DipWizard::GetWindow()) {
			
			
		} else if(g_keyboardHandlers.GetTail()) {
			g_keyboardHandlers.GetTail()->kh_Close();
		} else if (g_civApp->IsGameLoaded()) {
			if(g_currentMessageWindow && 
			   g_currentMessageWindow->GetMessage() &&
			   (g_theMessagePool->IsValid(*g_currentMessageWindow->GetMessage()))) {
				g_currentMessageWindow->GetMessage()->Minimize();
			} else if(g_modalMessage) {
				
				Message *msg = g_modalMessage->GetMessage();
				if(msg && g_theMessagePool->IsValid(*msg)) {
					Assert(msg->IsAlertBox());
					MessageData *data = msg->AccessData();
					if(data->GetNumButtons() <= 2 && data->GetNumButtons() > 0) {
						data->GetButton(0)->Callback();
					}
				}	
			} else if (g_optionsWindow && g_c3ui->GetWindow(g_optionsWindow->Id())) {
				
				optionsscreen_removeMyWindow(AUI_BUTTON_ACTION_EXECUTE);
			} else if(g_c3ui->TopWindow() && g_c3ui->TopWindow()->HandleKey(wParam)) {
				
			} else if(g_battleViewWindow) {
				battleview_ExitButtonActionCallback( NULL, AUI_BUTTON_ACTION_EXECUTE, 0, NULL);
			} else {
				
				optionsscreen_Initialize();
				optionsscreen_displayMyWindow(1);
			}
		}
		return TRUE;
	}

	
	aui_Window *topWindow = g_c3ui->TopWindow();
	if(topWindow && (!g_controlPanel || topWindow != g_controlPanel->GetWindow()) && topWindow != g_statusWindow) {
		if(topWindow->HandleKey(wParam))
			return 0;
	}

	
	
	if (!theKeyMap) return 0;

	
	if (g_slicEngine && g_slicEngine->RunKeyboardTrigger(static_cast<char>(wParam))) 
	{
		return 0;
	}

	if (!g_civApp->IsGameLoaded()) {
		return TRUE;
	}

	KEY_FUNCTION	kf = theKeyMap->get_function(wParam); 
	if (kf != KEY_FUNCTION_NOOP) 
	{
		g_selected_item->RegisterUIClick();
	}

	if (topWindow->IsStronglyModal() /*&& keypress_IsGameFunction(kf)*/) // I should not be able to open other windows if I have have open strongly modal windows like the DipWizzard
	{
		return 0;
	}

#if 0
	MapPoint point;
	g_tiledMap->GetMouseTilePos(point);
#endif

	switch (kf) {
#ifdef _PLAYTEST
	case KEY_FUNCTION_ENTER_COMMAND: 
		segmentlist_Display();
		break;
	case KEY_FUNCTION_ENTER_COMMAND_ALTERNATE:
		commandMode = TRUE; 
		move = FALSE; 
		break;
#endif
    case KEY_FUNCTION_NOOP: return FALSE; 
    case KEY_FUNCTION_MOVE_NORTHWEST: d = NORTHWEST; move = TRUE; break;
    case KEY_FUNCTION_MOVE_NORTH: d = NORTH; move = TRUE; break; 
    case KEY_FUNCTION_MOVE_NORTHEAST: d = NORTHEAST; move = TRUE; break; 
    case KEY_FUNCTION_MOVE_WEST: d = WEST; move = TRUE; break; 
    case KEY_FUNCTION_MOVE_EAST: d = EAST; move = TRUE; break; 
    case KEY_FUNCTION_MOVE_SOUTHWEST: d = SOUTHWEST; move = TRUE; break; 
    case KEY_FUNCTION_MOVE_SOUTH: d = SOUTH; move = TRUE; break; 
    case KEY_FUNCTION_MOVE_SOUTHEAST: d = SOUTHEAST; move = TRUE; break;

	case KEY_FUNCTION_ENTRENCH:
		if(isMyTurn) g_selected_item->Entrench();
		break;









	case KEY_FUNCTION_UNLOAD_TRANS:
	{
		sint32 order;
		if(!g_theOrderDB->GetNamedItem("ORDER_UNLOAD", order))
			return 0;

		Army a;
		if(g_selected_item->GetSelectedArmy(a))
			g_controlPanel->BeginOrderDelivery(g_theOrderDB->Access(order));
	}
	break;
	case KEY_FUNCTION_SETTLE:
	{
		g_selected_item->Settle();
		move = FALSE;
		break;
	}
	case KEY_FUNCTION_SPACE_LAUNCH:
		if(isMyTurn) {
			sint32 index;
			if(g_theOrderDB->GetNamedItem("ORDER_SPACE_LAUNCH", index)) {
				g_controlPanel->BeginOrderDelivery(g_theOrderDB->Access(index));
			}
			
			return TRUE;
		}
		break;
	case KEY_FUNCTION_DESCEND:		
		g_selected_item->Descend();
		break;
	case KEY_FUNCTION_PILLAGE:
	{
		sint32 order;
		if(!g_theOrderDB->GetNamedItem("ORDER_PILLAGE", order))
			return 0;

		Army a;
		if(g_selected_item->GetSelectedArmy(a) && a.CanPillage()) {
			g_controlPanel->BeginOrderDelivery(g_theOrderDB->Access(order));
		} else {
			g_selected_item->Pillage();
			return 0;
		}
	}
		break;
	case KEY_FUNCTION_BOMBARD:
	{
		sint32 order;
		if(!g_theOrderDB->GetNamedItem("ORDER_BOMBARD", order))
			return 0;

		Army a;
		if(g_selected_item->GetSelectedArmy(a) && a.CanBombard()) {
			g_controlPanel->BeginOrderDelivery(g_theOrderDB->Access(order));
		} else {
			return 0;
		}
	}
		




		break;
	case KEY_FUNCTION_EXPEL:		
	{
		sint32 order;
		if(!g_theOrderDB->GetNamedItem("ORDER_EXPEL", order))
			return 0;

		Army a;
		if(g_selected_item->GetSelectedArmy(a) && a.CanExpel()) {
			g_controlPanel->BeginOrderDelivery(g_theOrderDB->Access(order));
		} else {
			return 0;
		}
	}
			



		break;
	case KEY_FUNCTION_SLEEP:
		if(isMyTurn) {
			move = FALSE;

			g_selected_item->Sleep();
		}
		break;
    case KEY_FUNCTION_NEXT_ITEM: 
        g_selected_item->NextItem(); 
		move = FALSE;
        break;

	case KEY_FUNCTION_PARADROP:
		if(isMyTurn) {
			MapPoint point;
			g_tiledMap->GetMouseTilePos(point);
			g_selected_item->Paradrop(point);
			return TRUE;
		}
		break;

	case KEY_FUNCTION_INVESTIGATE_CITY:
        {
            MapPoint    point;
            g_tiledMap->GetMouseTilePos(point);
		    g_selected_item->InvestigateCity(point);
        }
		break;

	case KEY_FUNCTION_PLANT_NUKE:				
	{
		sint32 order;
		if(!g_theOrderDB->GetNamedItem("ORDER_PLANT_NUKE", order))
			return 0;

		Army a;
		double chance, escape_chance;
		if(g_selected_item->GetSelectedArmy(a) && a.CanPlantNuke(chance, escape_chance)) {
			g_controlPanel->BeginOrderDelivery(g_theOrderDB->Access(order));
		} else {
			return 0;
		}
	}
	
		break;
	case KEY_FUNCTION_BIOINFECT:				
	{
		sint32 order;
		if(!g_theOrderDB->GetNamedItem("ORDER_BIO_INFECT", order))
			return 0;

		Army a;
		double chance;
		if(g_selected_item->GetSelectedArmy(a) && a.CanBioInfect(chance)) {
			g_controlPanel->BeginOrderDelivery(g_theOrderDB->Access(order));
		} else {
			return 0;
		}
	}
	
		break;
	case KEY_FUNCTION_NANOTERROR:				
	{
		sint32 order;
		if(!g_theOrderDB->GetNamedItem("ORDER_NANO_INFECT", order))
			return 0;

		Army a;
		double chance;
		if(g_selected_item->GetSelectedArmy(a) && a.CanNanoInfect(chance)) {
			g_controlPanel->BeginOrderDelivery(g_theOrderDB->Access(order));
		} else {
			return 0;
		}
	}
	
		break;
	case KEY_FUNCTION_CREATE_PARK:				
	{
		sint32 order;
		if(!g_theOrderDB->GetNamedItem("ORDER_CREATE_PARK", order))
			return 0;

		Army a;
		if(g_selected_item->GetSelectedArmy(a) && a.AccessData()->CanCreatePark()) {
			g_controlPanel->BeginOrderDelivery(g_theOrderDB->Access(order));
		} else {
			return 0;
		}
	}
	
		break;
	case KEY_FUNCTION_REFORM:
	{
		sint32 order;
		if(!g_theOrderDB->GetNamedItem("ORDER_REFORM", order))
			return 0;

		Army a;
		if(g_selected_item->GetSelectedArmy(a) && a.AccessData()->CanReformCity()) {
			g_controlPanel->BeginOrderDelivery(g_theOrderDB->Access(order));
		} else {
			return 0;
		}
	}
	
		break;

	case KEY_FUNCTION_OPEN_WORK_VIEW:
		ArmyManagerWindow::Toggle();
		break;
	case KEY_FUNCTION_OPEN_CITY_VIEW:
		if(!g_modalWindow) {
			close_AllScreens();
			open_CityView();
		}
		break;
	case KEY_FUNCTION_OPEN_CITY_STATUS:
		if ( !g_modalWindow ) {
			close_AllScreens();
			open_CityStatus();
		}
		break;
	case KEY_FUNCTION_OPEN_CIV_STATUS:
		if ( !g_modalWindow ) {
			close_AllScreens();
			open_CivStatus();
		}
		break;
	case KEY_FUNCTION_OPEN_SCIENCE_STATUS:
		if ( !g_modalWindow ) {
			close_AllScreens();
			open_ScienceStatus();
		}
		break;
	case KEY_FUNCTION_OPEN_UNIT_STATUS:
		if ( !g_modalWindow ) {
			close_AllScreens();
			open_UnitStatus();
		}
		break;
	case KEY_FUNCTION_OPEN_TRADE_STATUS:
		if ( !g_modalWindow ) {
			close_AllScreens();
			TradeManager::Display();
			TradeManager::SetMode(TRADE_MANAGER_MARKET);
			
		}
		break;
	case KEY_FUNCTION_OPEN_DIPLOMACY:
		if ( !g_modalWindow ) {
			close_AllScreens();
			open_Diplomacy();
		}
		break;
	case KEY_FUNCTION_OPEN_INFO_SCREEN:
		if ( !g_modalWindow ) {
			InfoWindow::SelectScoreTab();
			InfoWindow::Open();
		}
		break;
	case KEY_FUNCTION_OPEN_GREAT_LIBRARY:
		if ( !g_modalWindow ) {
			close_AllScreens();
			open_GreatLibrary();
		}
		break;
	case KEY_FUNCTION_OPEN_OPTIONS_SCREEN:
		if ( !g_modalWindow ) {
			close_AllScreens();
			open_OptionsScreen(1);
		}
		break;

	case KEY_FUNCTION_OPEN_SCENARIO_EDITOR:
		if(!g_modalWindow
		&& !g_turn->IsEmail()
		){
			close_AllScreens();
			optionsscreen_mapeditorPress(NULL, AUI_BUTTON_ACTION_EXECUTE, 0, NULL);
		}
		break;
		
		
		
    case KEY_FUNCTION_ZOOM_IN1:
        if (g_tiledMap) {
			g_tiledMap->ZoomIn();
		}
		break;

    case KEY_FUNCTION_ZOOM_OUT1:
        if (g_tiledMap) {
			g_tiledMap->ZoomOut();
        }

		break;

	case KEY_FUNCTION_CENTER_MAP:
	{
		PLAYER_INDEX s_player; 
		ID s_item; 
		SELECT_TYPE s_state; 
		g_selected_item->GetTopCurItem(s_player, s_item, s_state);

        MapPoint pos;
		switch(s_state) {
			case SELECT_TYPE_LOCAL_ARMY:
			{	
				Army army(s_item);
				army.GetPos(pos);
				g_radarMap->CenterMap(pos);
				g_tiledMap->Refresh();
				g_tiledMap->InvalidateMap();
				break;
			}
			case SELECT_TYPE_LOCAL_CITY:
			{	
				Unit unit(s_item);
				unit.GetPos(pos);
				g_radarMap->CenterMap(pos);
				g_tiledMap->Refresh();
				g_tiledMap->InvalidateMap();

				break;
			}
		}
	}
	break;

	case KEY_FUNCTION_SAVE_GAME:
		if(g_network.IsActive()) {
			if(g_network.IsHost()) {
				
				
				g_isScenario = FALSE;
				loadsavescreen_displayMyWindow(LSS_SAVE_MP);
			}
		} else {
			
			
			g_isScenario = FALSE;

			loadsavescreen_displayMyWindow(LSS_SAVE_GAME);
		}
		break;
	case KEY_FUNCTION_LOAD_GAME:
		if(!g_network.IsActive()) {
			loadsavescreen_displayMyWindow(LSS_LOAD_GAME);
		}
		break;						
	case KEY_FUNCTION_REMAP_KEYBOARD:	
		open_KeyMappingScreen();
		break;
	
    case KEY_FUNCTION_KEYBOARD_SELECT_UNIT:
         g_selected_item->KeyboardSelectFirstUnit(); 
		 move = FALSE;
		 break; 

#ifdef _PLAYTEST
    case KEY_FUNCTION_RAND_TEST:
       g_is_rand_test=TRUE; 
         return TRUE; 
		 break;
#endif
        
#if 0
	case KEY_FUNCTION_ENDSLICE:
		if(g_network.IsActive()) {
			if(g_network.IsMyTurn() ||
			   (g_network.IsHost() && 
				g_player[g_selected_item->GetCurPlayer()]->IsRobot())) {
				g_turn->EndThisSliceBeginNewSlice();
			}
		} else {
			g_turn->EndThisSliceBeginNewSlice();
		}
		move = FALSE;
		break;
#endif
    case KEY_FUNCTION_ENDTURN: 
#ifdef _PLAYTEST
        if (g_selected_item->GetCurPlayer() != g_selected_item->GetVisiblePlayer()) 
           break; 

		if(g_network.IsActive()) {
			g_turn->NetworkEndTurn();
		} else {
            g_selected_item->Deselect(g_selected_item->GetCurPlayer());

			

			
			NewTurnCount::StartNextPlayer(true);

 			
          	
            
            
			

			
			
            
            

			g_tiledMap->InvalidateMix();
			g_tiledMap->InvalidateMap();
			g_tiledMap->Refresh();
			g_radarMap->Update();
			g_turn->InformMessages();
		}
		move = FALSE;
        break;
#endif
    
    case KEY_FUNCTION_NEXT_ROUND:   

		
		
		if(g_modalMessage) {
			Message *msg = g_modalMessage->GetMessage();
			if(g_theMessagePool->IsValid(*msg)) {
				Assert(msg->IsAlertBox());
				MessageData *data = msg->AccessData();
				if(data->GetNumButtons() <= 2 && data->GetNumButtons() > 0) {
					data->GetButton(0)->Callback();
				}
			}	
		} else if(g_utilityTextMessage) {
			g_utilityTextMessage->m_callback(FALSE);
			g_utilityTextMessage->RemoveWindow();
		} else {
			
			
			if(g_selected_item->GetVisiblePlayer() == g_selected_item->GetCurPlayer()) {
				DPRINTF(k_DBG_GAMESTATE, ("Keypress end turn, %d\n", g_selected_item->GetCurPlayer()));
				g_selected_item->RegisterManualEndTurn();
				g_director->AddEndTurn(); 
			}
			else
			{
				
				
				
			}
		}
        break; 

    case KEY_FUNCTION_SAVE_WORLD :
		if (g_civApp->IsGameLoaded() && !g_network.IsClient()) {
			g_civApp->AutoSave(g_selected_item->GetVisiblePlayer(), true);

			
			
			

			
		}
		move = FALSE ;
		break ;
        
    case KEY_FUNCTION_LOAD_WORLD :
		if (g_civApp->IsGameLoaded() && !g_network.IsActive()) {
			{
				g_civApp->PostLoadQuickSaveAction(g_selected_item->GetVisiblePlayer());
				
				
				
				
				
			}
			move = FALSE ;
		}
		break ;

    case KEY_FUNCTION_QUIT:
		optionwarningscreen_displayMyWindow(OWS_QUIT);


        return 1;
        break;

#ifdef _PLAYTEST
    case KEY_FUNCTION_GAMESTATE_DEBUG:
        g_theWorld->GamestateDebug();
        for (i=0; i<2; i++) { 
            g_player[i]->GamestateDebug(); 
        }
        return TRUE; 
		break;
#endif
	
    case KEY_FUNCTION_GROUP_ARMY:
	{
		Army a;
		if(g_selected_item->GetSelectedArmy(a)) {
			if(g_network.IsClient()) 
            {
				CellUnitList units;
				Cell *cell = g_theWorld->GetCell(a->RetPos());
				for (sint32 i = 0; i < cell->GetNumUnits(); i++) {
					if(cell->AccessUnit(i).GetArmy().m_id != a.m_id) {
						units.Insert(cell->AccessUnit(i));
					}
				}
				if(units.Num() > 0) {
					g_network.SendGroupRequest(units, a);
				}
			} else {
				g_gevManager->AddEvent(GEV_INSERT_Tail, GEV_GroupOrder,
									   GEA_Army, a.m_id,
									   GEA_End);
			}
		}	

		return TRUE;
	}
	break;
	case KEY_FUNCTION_UNGROUP_ARMY:	
	{	
		Army a;
		if(g_selected_item->GetSelectedArmy(a)) {
			if(g_network.IsClient()) {
				g_network.SendUngroupRequest(a, *a.AccessData());
			} else {
				g_gevManager->AddEvent(GEV_INSERT_Tail, GEV_UngroupOrder,
									   GEA_Army, a.m_id,
									   GEA_End);
			}
		}
		

		return TRUE; 
	}
	break;
	case KEY_FUNCTION_PROCESS_UNIT_ORDERS:
		if(isMyTurn) {
			g_gevManager->Pause();
			for 
            (
                sint32 i = 0; 
                i < g_player[g_selected_item->GetVisiblePlayer()]->m_all_armies->Num(); 
                i++
            ) 
            {
				g_gevManager->AddEvent(GEV_INSERT_Tail, GEV_BeginTurnExecute,
									   GEA_Army, g_player[g_selected_item->GetVisiblePlayer()]->m_all_armies->Access(i),
									   GEA_End);
			}
			g_gevManager->Resume();
			
		}
		break;
	case KEY_FUNCTION_EXECUTE_ORDERS:
		if(isMyTurn)
		{
			PLAYER_INDEX s_player; 
			ID s_item; 
			SELECT_TYPE s_state; 
			g_selected_item->GetTopCurItem(s_player, s_item, s_state);
			Army army(s_item);
			if (s_state == SELECT_TYPE_LOCAL_ARMY && army.IsValid())
            {
				army.ExecuteOrders();
			}
		}
		break;

#if defined(CTP1_HAS_RISEN_FROM_THE_GRAVE)
	case KEY_FUNCTION_TOGGLE_SPACE:
	{
		if(!g_network.IsActive()) {
			extern sint32 g_fog_toggle;
			g_fog_toggle = !g_fog_toggle;
			void WhackScreen();
			WhackScreen();
		}
		break;
	}
#endif

	case KEY_FUNCTION_TOGGLE_CITY_NAMES:
		g_theProfileDB->SetShowCityNames(!g_theProfileDB->GetShowCityNames());
		break;

	case KEY_FUNCTION_TOGGLE_TRADE_ROUTES:
		g_theProfileDB->SetShowTradeRoutes(!g_theProfileDB->GetShowTradeRoutes());
		break;
//#if 0
//	case KEY_FUNCTION_TOGGLE_ARMY_NAMES: //emod
//		g_theProfileDB->SetShowArmyNames(!g_theProfileDB->GetShowArmyNames());
//		break;
//#endif

#ifdef _DEBUG
#if 0
	case KEY_FUNCTION_CRC:
		if(g_debugOwner != k_DEBUG_OWNER_CRC) {
            if (!g_dataCheck) { 
                g_dataCheck = new DataCheck();
            }
			g_debugOwner = k_DEBUG_OWNER_CRC;
			g_dataCheck->BeginTurn();
			g_dataCheck->SetDisplay(1);
		} else {
			g_debugOwner = k_DEBUG_OWNER_NONE;
		}
		break;	
#endif
#endif
	case KEY_FUNCTION_HELP_MODE_TOGGLE:
		break;

	case KEY_FUNCTION_CHAT_KEY:
		if (g_chatBox) 
        {
			g_chatBox->SetActive(!g_chatBox->IsActive());
		}
		break;

	case KEY_FUNCTION_UNIT_CITY_TOGGLE:
		g_selected_item->UnitCityToggle();
		break;
	case KEY_FUNCTION_END_UNIT_TURN:
		g_selected_item->EndUnitTurn();
		break;

	case KEY_FUNCTION_NETWORK_PLAYERS_SCREEN:
		if ( !g_networkPlayersScreen ) {
			g_networkPlayersScreen = new c3_UtilityPlayerListPopup((c3_UtilityPlayerListCallback *)network_PlayerListCallback);
		}
		g_networkPlayersScreen->DisplayWindow();
		if ( g_network.IsHost() ) {
			g_networkPlayersScreen->EnableButtons();
		}
		else if ( g_network.IsClient() ) {		
			g_networkPlayersScreen->DisableButtons();
		}
		
		break;
	case KEY_FUNCTION_CIV_TAB:
		if(g_controlPanel) {
			g_controlPanel->SetTab(CP_TAB_CIV);
		}
		break;
	case KEY_FUNCTION_MSG_TAB:
		if(g_controlPanel) {
			g_controlPanel->SetTab(CP_TAB_MSGLOG);
		}
		break;
	case KEY_FUNCTION_CITY_TAB:
		if(g_controlPanel) {
			g_controlPanel->SetTab(CP_TAB_CITY);
		}
		break;
	case KEY_FUNCTION_UNIT_TAB:
		if(g_controlPanel) {
			g_controlPanel->SetTab(CP_TAB_UNIT);
		}
		break;
	case KEY_FUNCTION_TILE_TAB:
		if(g_controlPanel) {
			g_controlPanel->SetTab(CP_TAB_TILEIMP);
		}
		break;
		
	case KEY_FUNCTION_CONTROL_NEXT:
#if 0
		if(g_controlPanel) {

			if(g_cp_productionTab && 
			   (g_cp_productionTab->GetMode() == PRODTAB_MODE_CHANGE ||
				g_cp_productionTab->GetMode() == PRODTAB_MODE_QUEUE)) {
				c3_ListBox *plist = g_cp_productionTab->GetPurchaseList();
				if(plist && plist->NumItems() > 0) {
					sint32 curIndex = plist->GetSelectedItemIndex();
					if(curIndex >= plist->NumItems() - 1) {
						curIndex = -1;
					}
					plist->SelectItem(curIndex + 1);
					plist->GetVerticalRanger()->SetValue(0, curIndex + 1 - 2);
				}
			}
		}
#endif
		break;
	case KEY_FUNCTION_CONTROL_PREV:
#if 0
		if(g_controlPanel) {

			if(g_cp_productionTab && 
			   (g_cp_productionTab->GetMode() == PRODTAB_MODE_CHANGE ||
				g_cp_productionTab->GetMode() == PRODTAB_MODE_QUEUE)) {
				c3_ListBox *plist = g_cp_productionTab->GetPurchaseList();
				if(plist && plist->NumItems() > 0) {
					sint32 curIndex = plist->GetSelectedItemIndex();
					if(curIndex <= 0) {
						curIndex = plist->NumItems();
					}
					plist->SelectItem(curIndex - 1);
					plist->GetVerticalRanger()->SetValue(0, curIndex - 1 - 2);
				}
			}
		}
#endif
		break;
	case KEY_FUNCTION_CLOSE:		
		if(g_currentMessageWindow) {
			if(g_theMessagePool->IsValid(*g_currentMessageWindow->GetMessage())) {
				g_currentMessageWindow->GetMessage()->Kill();
			}
		} else if(g_modalMessage) {
			Message *msg = g_modalMessage->GetMessage();
			if(g_theMessagePool->IsValid(*msg)) {
				Assert(msg->IsAlertBox());
				MessageData *data = msg->AccessData();
				if(data->GetNumButtons() <= 2 && data->GetNumButtons() > 0) {
					data->GetButton(0)->Callback();
				}
			}	
		}

		break;
	case KEY_FUNCTION_YES:
	{
		if(g_modalMessage) {
			Message *msg = g_modalMessage->GetMessage();
			if(g_theMessagePool->IsValid(*msg)) {
				Assert(msg->IsAlertBox());
				MessageData *data = msg->AccessData();
				if(data->GetNumButtons() == 2) {
					data->GetButton(1)->Callback();
				}
			}
		} else if(g_utilityTextMessage) {
			g_utilityTextMessage->m_callback(TRUE);
			g_utilityTextMessage->RemoveWindow();
		}
		break;
	}
	case KEY_FUNCTION_NO:
	{
		if(g_modalMessage) {
			Message *msg = g_modalMessage->GetMessage();
			if(g_theMessagePool->IsValid(*msg)) {
				Assert(msg->IsAlertBox());
				MessageData *data = msg->AccessData();
				if(data->GetNumButtons() == 2) {
					data->GetButton(0)->Callback();
				}
			}
		} else if(g_utilityTextMessage) {
			g_utilityTextMessage->m_callback(FALSE);
			g_utilityTextMessage->RemoveWindow();
		}
		break;
	}
	case KEY_FUNCTION_CLEAR_QUEUE:
		if(g_controlPanel 

			) {
			Unit city;
			if(g_selected_item->GetSelectedCity(city)) {
				city.GetData()->GetCityData()->GetBuildQueue()->Clear();
#if 0
				if(g_cp_productionTab) {
					g_cp_productionTab->LoadCityData(city);
					g_cp_productionTab->FillQueueList(city);
				}
#endif
			}
		}
		break;
	case KEY_FUNCTION_OPEN_MESSAGE: 
		{
			
			
			extern sint32 g_modalWindow;
			if (g_modalWindow == 0) {
				if(g_currentMessageWindow) {
					if(g_currentMessageWindow->GetMinimizeAction()) {
						g_currentMessageWindow->GetMinimizeAction()->Execute(NULL,
																		   AUI_BUTTON_ACTION_EXECUTE,
																		   0);
					}
				} else if(g_selected_item) {
					sint32 visPlayer = g_selected_item->GetVisiblePlayer();
					
					if(g_player[visPlayer] && g_player[visPlayer]->m_messages->Num() > 0) {
						sint32 m;
						for(m = 0; m < g_player[visPlayer]->m_messages->Num(); m++) {
							if(!g_player[visPlayer]->m_messages->Access(m).IsRead()) {
								g_player[visPlayer]->m_messages->Access(m).Show();
								break;
							}
						}
					}
				}
			}
		}
		break;
	case KEY_FUNCTION_EXECUTE_EYEPOINT:
		{
			
			if(g_currentMessageWindow) {
				if(g_theMessagePool->IsValid(*g_currentMessageWindow->GetMessage())) {
					g_currentMessageWindow->GetMessage()->AccessData()->EyePointCallback(0);
				}
			}
			break;
		}
	case KEY_FUNCTION_MOVE_ORDER:
		g_controlPanel->BeginOrderDelivery(g_selected_item->GetMoveOrder());
		break;

	case KEY_FUNCTION_TOGGLE_RADAR:
		radarwindow_Toggle();
		break;

	case KEY_FUNCTION_TOGGLE_CONTROL_PANEL:
		g_controlPanel->Toggle();
		break;

	case KEY_FUNCTION_TOGGLE_ALL:
		if(!g_c3ui->GetWindow(g_controlPanel->GetWindow()->Id())) {
			g_c3ui->AddWindow(g_controlPanel->GetWindow());
			radarwindow_Show();
		} else {
			g_c3ui->RemoveWindow(g_controlPanel->GetWindow()->Id());
			radarwindow_Hide();
		}
		break;

	
	case KEY_FUNCTION_TRADE_SUMMARY:    
		if (!g_modalWindow) {
			close_AllScreens();
			TradeManager::Display();
			TradeManager::SetMode(TRADE_MANAGER_SUMMARY);
		}
		break;

	case KEY_FUNCTION_GAIA:
		if(!g_modalWindow) {
			close_AllScreens();
			ScienceVictoryDialog::Open();
		}
		break;

	case KEY_FUNCTION_BUILD_QUEUE:
	{
		if(!g_modalWindow && g_player[g_selected_item->GetVisiblePlayer()]) {
			Unit city;
			if(g_selected_item->GetSelectedCity(city)) {
				city = g_theWorld->GetCity(g_selected_item->GetCurSelectPos());
			} else if(g_player[g_selected_item->GetVisiblePlayer()]->GetNumCities()) {
				city = g_player[g_selected_item->GetVisiblePlayer()]->m_all_cities->Access(0);
			}
				if(city.IsValid()) {
					close_AllScreens();
					EditQueue::Display(CityWindow::GetCityData(city));
				}
		} 
		break;
	}		
	case KEY_FUNCTION_CITY_MANAGEMENT:
		if(!g_modalWindow && g_player[g_selected_item->GetVisiblePlayer()]) {
			close_AllScreens();
			Unit city;
			if(g_selected_item->GetSelectedCity(city)) {
				CityWindow::Display(city.GetData()->GetCityData());
			} else if(g_player[g_selected_item->GetVisiblePlayer()]->GetNumCities()) {
				city = g_player[g_selected_item->GetVisiblePlayer()]->m_all_cities->Access(0);
				g_selected_item->SetSelectCity(city);
				CityWindow::Display(city.GetData()->GetCityData());
			}
		}
		break;

	case KEY_FUNCTION_NEW_PROPOSAL:
		if(!g_modalWindow) {
			if(DipWizard::CanInitiateRightNow()) {
				DipWizard::Display();
			}
		}
		break;

	case KEY_FUNCTION_TIMELINE:
		if(!g_modalWindow) {
			InfoWindow::SelectWonderTab();
			InfoWindow::Open();
		}
		break;

	case KEY_FUNCTION_RANK:
		if(!g_modalWindow) {
			InfoWindow::SelectRankingTab();
			InfoWindow::Open();
		}
		break;
	
	case KEY_FUNCTION_RESTART:
		//Added by Martin Gühmann to disable also the restart key in network
		//games, hot seat games and email games.
		if(!g_modalWindow 
		&& !g_theProfileDB->IsScenario() 
		&& !g_isScenario
		&& !g_network.IsActive()
		&& !g_turn->IsHotSeat() 
		&& !g_turn->IsEmail()
		) {
			optionwarningscreen_displayMyWindow(OWS_RESTART) ;
		}
		break;

	case KEY_FUNCTION_NEW_GAME:
		if(!g_modalWindow) {

			optionwarningscreen_displayMyWindow(OWS_QUITTOSHELL);	
		}
		break;

	case KEY_FUNCTION_SOUND_OPTIONS:
		if(!g_modalWindow) {
			soundscreen_displayMyWindow();
		}
		break;
		
	// MUSIC added by ahenobarb
	case KEY_FUNCTION_MUSIC_OPTIONS:
		if(!g_modalWindow) {
			musicscreen_displayMyWindow();
		}
		break;
		
	case KEY_FUNCTION_GRAPHICS_OPTIONS:
		if(!g_modalWindow) {
			graphicsscreen_displayMyWindow();
		}
		break;

	case KEY_FUNCTION_GAMEPLAY_OPTIONS:
		if(!g_modalWindow) {
			gameplayoptions_displayMyWindow();
		}
		break;
	case KEY_FUNCTION_ADVANCED_OPTIONS:
		if(!g_modalWindow) {
			ProfileEdit::Display();
		}
		break;
	default :
        Assert(FALSE); 
    }
    
    if (move && isMyTurn) {
		
		PLAYER_INDEX s_player; 
		ID s_item; 
		SELECT_TYPE s_state; 
        
		g_selected_item->GetTopCurItem(s_player, s_item, s_state);
		
		switch(s_state) { 
			case SELECT_TYPE_LOCAL_ARMY:
			{
				Army army(s_item);
				MapPoint pos;
				army.GetPos(pos);
				MapPoint newpos;

				if(pos.GetNeighborPosition(d, newpos)) {
					g_gevManager->AddEvent(GEV_INSERT_Tail, GEV_MoveToOrder,
										   GEA_Army, army.m_id,
										   GEA_Direction, d,
										   GEA_End);
					
					g_selected_item->DidKeyboardMove();
				}
				break;
			}
				
			default: 
				break; 
		}
	}

	return TRUE;
}