Esempio n. 1
0
/**************************************************************************
...
**************************************************************************/
void handle_city_info(struct packet_city_info *packet)
{
  int i, x, y, city_is_new;
  struct city *pcity;

  pcity=city_list_find_id(&game.players[packet->owner].cities, packet->id);

  if(!pcity) {
    city_is_new=1;
    pcity=(struct city *)malloc(sizeof(struct city));
  }
  else
    city_is_new=0;
  
  pcity->id=packet->id;
  pcity->owner=packet->owner;
  pcity->x=packet->x;
  pcity->y=packet->y;
  strcpy(pcity->name, packet->name);
  
  pcity->size=packet->size;
  pcity->ppl_happy[4]=packet->ppl_happy;
  pcity->ppl_content[4]=packet->ppl_content;
  pcity->ppl_unhappy[4]=packet->ppl_unhappy;
  pcity->ppl_elvis=packet->ppl_elvis;
  pcity->ppl_scientist=packet->ppl_scientist;
  pcity->ppl_taxman=packet->ppl_taxman;
  for (i=0;i<4;i++)
    pcity->trade[i]=packet->trade[i];
  
  pcity->food_prod=packet->food_prod;
  pcity->food_surplus=packet->food_surplus;
  pcity->shield_prod=packet->shield_prod;
  pcity->shield_surplus=packet->shield_surplus;
  pcity->trade_prod=packet->trade_prod;
  pcity->corruption=packet->corruption;
  
  pcity->luxury_total=packet->luxury_total;
  pcity->tax_total=packet->tax_total;
  pcity->science_total=packet->science_total;
  
  pcity->food_stock=packet->food_stock;
  pcity->shield_stock=packet->shield_stock;
  pcity->polution=packet->polution;
  pcity->incite_revolt_cost=packet->incite_revolt_cost;
    
  pcity->is_building_unit=packet->is_building_unit;
  pcity->currently_building=packet->currently_building;
  pcity->did_buy=packet->did_buy;
  pcity->did_sell=packet->did_sell;
    
  i=0;
  for(y=0; y<CITY_MAP_SIZE; y++)
    for(x=0; x<CITY_MAP_SIZE; x++)
      pcity->city_map[x][y]=packet->city_map[i++]-'0';
    
  for(i=0; i<B_LAST; i++)
    pcity->improvements[i]=(packet->improvements[i]=='1') ? 1 : 0;

  
  if(city_is_new) {
    unit_list_init(&pcity->units_supported);
    city_list_insert(&game.players[packet->owner].cities, pcity);
    map_set_city(pcity->x, pcity->y, pcity);
    if(pcity->owner==game.player_idx)
      city_report_dialog_update();

    for(i=0; i<game.nplayers; i++) {
      struct genlist_iterator myiter;
      genlist_iterator_init(&myiter, &game.players[i].units.list, 0);
     
      for(;ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) {
	struct unit *punit=(struct unit *)ITERATOR_PTR(myiter);
	if(punit->homecity==pcity->id)
	  unit_list_insert(&pcity->units_supported, punit);
      }
    }
  }
    
  refresh_tile_mapcanvas(pcity->x, pcity->y, 1);
  
  if(city_is_new && client_state==CLIENT_GAME_RUNNING_STATE && 
     pcity->owner==game.player_idx)
    popup_city_dialog(pcity, 0);

  if(!city_is_new)
    refresh_city_dialog(pcity);
}
Esempio n. 2
0
/**************************************************************************
  Main handler for key presses
**************************************************************************/
static Uint16 main_key_down_handler(SDL_keysym Key, void *pData)
{
    static struct widget *pWidget;
    if ((pWidget = find_next_widget_for_key(NULL, Key)) != NULL) {
        return widget_pressed_action(pWidget);
    } else {
        if (Key.sym == SDLK_TAB) {
            /* input */
            popup_input_line();
        } else {
            if (map_event_handler(Key)
                    && C_S_RUNNING == client_state()) {
                switch (Key.sym) {
                case SDLK_RETURN:
                case SDLK_KP_ENTER:
                    if (LSHIFT || RSHIFT) {
                        disable_focus_animation();
                        key_end_turn();
                    } else {
                        struct unit *pUnit;
                        struct city *pCity;
                        if (NULL != (pUnit = head_of_units_in_focus()) &&
                                (pCity = tile_city(unit_tile(pUnit))) != NULL &&
                                city_owner(pCity) == client.conn.playing) {
                            popup_city_dialog(pCity);
                        }
                    }
                    return ID_ERROR;

                case SDLK_F2:
                    units_report_dialog_popup(FALSE);
                    return ID_ERROR;

                case SDLK_F4:
                    city_report_dialog_popup(FALSE);
                    return ID_ERROR;

                case SDLK_F7:
                    send_report_request(REPORT_WONDERS_OF_THE_WORLD);
                    return ID_ERROR;

                case SDLK_F8:
                    send_report_request(REPORT_TOP_5_CITIES);
                    return ID_ERROR;

                case SDLK_F9:
                    if (meswin_dialog_is_open()) {
                        meswin_dialog_popdown();
                    } else {
                        meswin_dialog_popup(TRUE);
                    }
                    flush_dirty();
                    return ID_ERROR;

                case SDLK_F11:
                    send_report_request(REPORT_DEMOGRAPHIC);
                    return ID_ERROR;

                case SDLK_F12:
                    popup_spaceship_dialog(client.conn.playing);
                    return ID_ERROR;

                default:
                    return ID_ERROR;
                }
            }
        }
    }

    return ID_ERROR;
}