Пример #1
0
void state_init(struct state *s, struct basic_options *op, struct multi_options *mop){
 
  s->speed = op->speed;
  s->prev_speed = s->speed;
  s->dif = op->dif;
  s->map_seed = op->map_seed;
  s->conditions = op->conditions;
  s->inequality = op->inequality;
  s->winlosecondition = 0;
  s->time = (1850 + rand()%100) * 360 + rand()%360;

  /* player controlled from the keyboard */
  s->controlled = 1;
  /* int players[] = {7, 2, 3, 5}; */
  /* int players[] = {2, 3, 4, 5, 6, 7}; */

  int all_players[] = {1, 2, 3, 4, 5, 6, 7};
  int comp_players[MAX_PLAYER]; 
  int comp_players_num = 7 - mop->clients_num;
 
  s->kings_num = comp_players_num;
  int ui_players[MAX_PLAYER];
  int ui_players_num = mop->clients_num;
  int i;
  for (i=0; i<7; ++i) {
    if (i<mop->clients_num)
      ui_players[i] = all_players[i];
    else {
      int j = i - mop->clients_num; /* computer player index / king's index */
      comp_players[j] = all_players[i];
      switch (i){
        case 1:
          king_init (&s->king[j], i+1, opportunist, &s->grid, s->dif); 
          break;
        case 2:
          king_init (&s->king[j], i+1, one_greedy, &s->grid, s->dif);
          break;
        case 3:
          king_init (&s->king[j], i+1, none, &s->grid, s->dif);
          break;
        case 4:
          king_init (&s->king[j], i+1, aggr_greedy, &s->grid, s->dif);
          break;
        case 5:
          king_init (&s->king[j], i+1, noble, &s->grid, s->dif);
          break;
        case 6:
          king_init (&s->king[j], i+1, persistent_greedy, &s->grid, s->dif);
          break;
      }
    }
  }

  /* Initialize map generation with the map_seed */
  srand(s->map_seed);

  /* Map generation starts */
  {
    int conflict_code = 0;
    do {
      grid_init(&s->grid, op->w, op->h);
  
      /* starting locations arrays */
      struct loc loc_arr[MAX_AVLBL_LOC];
      int available_loc_num = 0;
      int d = 2;
      apply_stencil(op->shape, &s->grid, d, loc_arr, &available_loc_num);
     
      /* conflict mode */
      conflict_code = 0;
      if (!op->keep_random_flag) 
        conflict_code = conflict(&s->grid, loc_arr, available_loc_num, 
            comp_players, comp_players_num, op->loc_num, ui_players, ui_players_num, s->conditions, s->inequality);
    } while(conflict_code != 0 || !is_connected(&s->grid));
  }
  /* Map is ready */

  int p;
  for(p = 0; p<MAX_PLAYER; ++p) {
    flag_grid_init(&s->fg[p], op->w, op->h);
    s->country[p].gold = 0;
  }

  /* kings evaluate the map */
  for(p = 0; p < s->kings_num; ++p) {
    king_evaluate_map(&s->king[p], &s->grid, s->dif);
  }

  /* Zero timeline */
  s->show_timeline = op->timeline_flag;
  s->timeline.mark = -1;
  for(i=0; i<MAX_TIMELINE_MARK; ++i) {
    s->timeline.time[i] = s->time;
    for(p=0; p<MAX_PLAYER; ++p) {
      s->timeline.data[p][i] = 0.0;
    }
  }

  /* init turn by turn */
  for(p=0; p<mop->clients_num; ++p) {
	s->turn_validated[p] = 0;
  }
}
Пример #2
0
void state_init(struct state *s, int w, int h, enum stencil shape,
    unsigned int map_seed, int keep_random, int locations_num, int clients_num, 
    int conditions, int inequality, enum config_speed speed, enum config_dif dif){
  
  s->speed = speed;
  s->prev_speed = s->speed;
  s->dif = dif;
  s->map_seed = map_seed;
  s->conditions = conditions;
  s->inequality = inequality;
  s->time = (1850 + rand()%100) * 360 + rand()%360;

  /* player controlled from the keyboard */
  s->controlled = 1;
  /* int players[] = {7, 2, 3, 5}; */
  /* int players[] = {2, 3, 4, 5, 6, 7}; */

  int all_players[] = {1, 2, 3, 4, 5, 6, 7};
  int comp_players[MAX_PLAYER]; 
  int comp_players_num = 7 - clients_num;
 
  s->kings_num = comp_players_num;
  int ui_players[MAX_PLAYER];
  int ui_players_num = clients_num;
  int i;
  for (i=0; i<7; ++i) {
    if (i<clients_num)
      ui_players[i] = all_players[i];
    else {
      int j = i - clients_num; /* computer player index / king's index */
      comp_players[j] = all_players[i];
      switch (i){
        case 1:
          king_init (&s->king[j], i+1, opportunist, &s->grid, s->dif); 
          break;
        case 2:
          king_init (&s->king[j], i+1, one_greedy, &s->grid, s->dif);
          break;
        case 3:
          king_init (&s->king[j], i+1, none, &s->grid, s->dif);
          break;
        case 4:
          king_init (&s->king[j], i+1, aggr_greedy, &s->grid, s->dif);
          break;
        case 5:
          king_init (&s->king[j], i+1, noble, &s->grid, s->dif);
          break;
        case 6:
          king_init (&s->king[j], i+1, persistent_greedy, &s->grid, s->dif);
          break;
      }
    }
  }


  /* Initialize map generation with the map_seed */
  srand(s->map_seed);

  /* Map generation starts */
  {
    int conflict_code = 0;
    do {
      grid_init(&s->grid, w, h);
  
      /* starting locations arrays */
      struct loc loc_arr[MAX_AVLBL_LOC];
      int available_loc_num = 0;
      int d = 2;
      apply_stencil(shape, &s->grid, d, loc_arr, &available_loc_num);
     
      /* find the leftmost visible tile */
      /*
      int i, j;
      s->xskip = MAX_WIDTH * 2 + 1; 
      for(i=0; i<s->grid.width; ++i)
        for(j=0; j<s->grid.height; ++j)
          if(is_visible(s->grid.tiles[i][j].cl)) {
            int x = i*2 + j;
            if (s->xskip > x)
              s->xskip = x;
          }
      s->xskip = s->xskip/2;
      */

      /* conflict mode */
      conflict_code = 0;
      if (!keep_random) 
        conflict_code = conflict(&s->grid, loc_arr, available_loc_num, 
            comp_players, comp_players_num, locations_num, ui_players, ui_players_num, s->conditions, s->inequality);
    } while(conflict_code != 0 || !is_connected(&s->grid));
  }
  /* Map is ready */

  int p;
  for(p = 0; p<MAX_PLAYER; ++p) {
    flag_grid_init(&s->fg[p], w, h);
    s->country[p].gold = 0;
  }
 
  /* cursor location */
  /*
  s->cursor.i = s->grid.width/2;
  s->cursor.j = s->grid.height/2;
  int i, j;
  for (i=0; i<s->grid.width; ++i) {
    for (j=0; j<s->grid.height; ++j) {
      if (s->grid.tiles[i][j].units[s->controlled][citizen] > 
          s->grid.tiles[s->cursor.i][s->cursor.j].units[s->controlled][citizen]) {
        s->cursor.i = i;
        s->cursor.j = j;
      }
    }
  }
  */

  /* Kings */
  /* s->kings_num = 5; */
  /* king_init (&s->king[0], 2, opportunist, &s->grid, s->dif); */
  /*
  king_init (&s->king[1], 3, one_greedy, &s->grid, s->dif);
  king_init (&s->king[2], 7, persistent_greedy, &s->grid, s->dif);
  king_init (&s->king[3], 5, aggr_greedy, &s->grid, s->dif);
  king_init (&s->king[4], 4, none, &s->grid, s->dif);
  king_init (&s->king[0], 6, noble, &s->grid, s->dif);
  */
}