示例#1
0
/**************************************************************************
  Place a spaceship part
**************************************************************************/
bool do_spaceship_place(struct player *pplayer, bool user_initiated,
                        enum spaceship_place_type type, int num)
{
  struct player_spaceship *ship = &pplayer->spaceship;
  
  if (ship->state == SSHIP_NONE) {
    if (user_initiated) {
      notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                    _("Spaceship action received,"
                      " but you don't have a spaceship!"));
    }

    return FALSE;
  }

  if (ship->state >= SSHIP_LAUNCHED) {
    if (user_initiated) {
      notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                    _("You can't modify your spaceship after launch!"));
    }

    return FALSE;
  }

  if (type == SSHIP_PLACE_STRUCTURAL) {
    if (num < 0 || num >= NUM_SS_STRUCTURALS
        || BV_ISSET(ship->structure, num)) {
      return FALSE;
    }
    if (num_spaceship_structurals_placed(ship) >= ship->structurals) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("You don't have any unplaced Space Structurals!"));
      }

      return FALSE;
    }
    if (num != 0
        && !BV_ISSET(ship->structure, structurals_info[num].required)) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("That Space Structural would not be connected!"));
      }

      return FALSE;
    }

    BV_SET(ship->structure, num);
    spaceship_calc_derived(ship);
    send_spaceship_info(pplayer, NULL);
    return TRUE;
  }

  if (type == SSHIP_PLACE_FUEL) {
    if (ship->fuel != num - 1) {
      return FALSE;
    }
    if (ship->fuel + ship->propulsion >= ship->components) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("You don't have any unplaced Space Components!"));
      }

      return FALSE;
    }
    if (num > NUM_SS_COMPONENTS/2) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("Your spaceship already has"
                        " the maximum number of Fuel Components!"));
      }

      return FALSE;
    }

    ship->fuel++;
    spaceship_calc_derived(ship);
    send_spaceship_info(pplayer, NULL);
    return TRUE;
  }

  if (type == SSHIP_PLACE_PROPULSION) {
    if (ship->propulsion != num - 1) {
      return FALSE;
    }
    if (ship->fuel + ship->propulsion >= ship->components) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("You don't have any unplaced"
                        " Space Components!"));
      }

      return FALSE;
    }
    if (num > NUM_SS_COMPONENTS/2) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("Your spaceship already has the"
                        " maximum number of Propulsion Components!"));
      }

      return FALSE;
    }

    ship->propulsion++;
    spaceship_calc_derived(ship);
    send_spaceship_info(pplayer, NULL);
    return TRUE;
  }

  if (type == SSHIP_PLACE_HABITATION) {
    if (ship->habitation != num - 1) {
      return FALSE;
    }
    if (ship->habitation + ship->life_support + ship->solar_panels
        >= ship->modules) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("You don't have any unplaced Space Modules!"));
      }

      return FALSE;
    }
    if (num > NUM_SS_MODULES / 3) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("Your spaceship already has the"
                        " maximum number of Habitation Modules!"));
      }

      return FALSE;
    }

    ship->habitation++;
    spaceship_calc_derived(ship);
    send_spaceship_info(pplayer, NULL);
    return TRUE;
  }

  if (type == SSHIP_PLACE_LIFE_SUPPORT) {
    if (ship->life_support != num - 1) {
      return FALSE;
    }
    if (ship->habitation + ship->life_support + ship->solar_panels
        >= ship->modules) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("You don't have any unplaced Space Modules!"));
      }

      return FALSE;
    }
    if (num > NUM_SS_MODULES / 3) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("Your spaceship already has the"
                        " maximum number of Life Support Modules!"));
      }

      return FALSE;
    }

    ship->life_support++;
    spaceship_calc_derived(ship);
    send_spaceship_info(pplayer, NULL);
    return TRUE;
  }

  if (type == SSHIP_PLACE_SOLAR_PANELS) {
    if (ship->solar_panels != num - 1) {
      return FALSE;
    }
    if (ship->habitation + ship->life_support + ship->solar_panels
        >= ship->modules) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("You don't have any unplaced Space Modules!"));
      }

      return FALSE;
    }
    if (num > NUM_SS_MODULES / 3) {
      if (user_initiated) {
        notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
                      _("Your spaceship already has the"
                        " maximum number of Solar Panel Modules!"));
      }

      return FALSE;
    }

    ship->solar_panels++;
    spaceship_calc_derived(ship);
    send_spaceship_info(pplayer, NULL);
    return TRUE;
  }

  log_error("Received unknown spaceship place type %d from %s",
            type, player_name(pplayer));
  return FALSE;
}
示例#2
0
/****************************************************************************
  This borrows heavily from autoplace code already in the client source.
  AJS, 19990610
****************************************************************************/
bool dai_spaceship_autoplace(struct player *pplayer,
                             struct player_spaceship *ship)
{
  enum spaceship_place_type type;
  int num, i;
  bool retval = FALSE;
  
  while (ship->modules > (ship->habitation + ship->life_support
		       + ship->solar_panels)) {
    
    type =
      (ship->habitation==0)   ? SSHIP_PLACE_HABITATION :
      (ship->life_support==0) ? SSHIP_PLACE_LIFE_SUPPORT :
      (ship->solar_panels==0) ? SSHIP_PLACE_SOLAR_PANELS :
      ((ship->habitation < ship->life_support)
       && (ship->solar_panels*2 >= ship->habitation + ship->life_support + 1))
                              ? SSHIP_PLACE_HABITATION :
      (ship->solar_panels*2 < ship->habitation + ship->life_support)
                              ? SSHIP_PLACE_SOLAR_PANELS :
      (ship->life_support<ship->habitation)
                              ? SSHIP_PLACE_LIFE_SUPPORT :
      ((ship->life_support <= ship->habitation)
       && (ship->solar_panels*2 >= ship->habitation + ship->life_support + 1))
                              ? SSHIP_PLACE_LIFE_SUPPORT :
                                SSHIP_PLACE_SOLAR_PANELS;

    if (type == SSHIP_PLACE_HABITATION) {
      num = ship->habitation + 1;
    } else if(type == SSHIP_PLACE_LIFE_SUPPORT) {
      num = ship->life_support + 1;
    } else {
      num = ship->solar_panels + 1;
    }
    fc_assert_ret_val(num <= NUM_SS_MODULES / 3, FALSE);

    handle_spaceship_place(pplayer, type, num);
    retval = TRUE;
  }
  while (ship->components > ship->fuel + ship->propulsion) {
    if (ship->fuel <= ship->propulsion) {
      type = SSHIP_PLACE_FUEL;
      num = ship->fuel + 1;
    } else {
      type = SSHIP_PLACE_PROPULSION;
      num = ship->propulsion + 1;
    }
    handle_spaceship_place(pplayer, type, num);
    retval = TRUE;
  }
  while (ship->structurals > num_spaceship_structurals_placed(ship)) {
    /* Want to choose which structurals are most important.
       Else we first want to connect one of each type of module,
       then all placed components, pairwise, then any remaining
       modules, or else finally in numerical order.
    */
    int req = -1;
    
    if (!ship->structure[0]) {
      /* if we don't have the first structural, place that! */
      type = SSHIP_PLACE_STRUCTURAL;
      num = 0;
      handle_spaceship_place(pplayer, type, num);
    }
    
    if (ship->habitation >= 1
	&& !ship->structure[modules_info[0].required]) {
      req = modules_info[0].required;
    } else if (ship->life_support >= 1
	       && !ship->structure[modules_info[1].required]) {
      req = modules_info[1].required;
    } else if (ship->solar_panels >= 1
	       && !ship->structure[modules_info[2].required]) {
      req = modules_info[2].required;
    } else {
      int i;
      for(i=0; i<NUM_SS_COMPONENTS; i++) {
	if ((i%2==0 && ship->fuel > (i/2))
	    || (i%2==1 && ship->propulsion > (i/2))) {
	  if (!ship->structure[components_info[i].required]) {
	    req = components_info[i].required;
	    break;
	  }
	}
      }
    }
    if (req == -1) {
      for(i=0; i<NUM_SS_MODULES; i++) {
	if ((i%3==0 && ship->habitation > (i/3))
	    || (i%3==1 && ship->life_support > (i/3))
	    || (i%3==2 && ship->solar_panels > (i/3))) {
	  if (!ship->structure[modules_info[i].required]) {
	    req = modules_info[i].required;
	    break;
	  }
	}
      }
    }
    if (req == -1) {
      for(i=0; i<NUM_SS_STRUCTURALS; i++) {
	if (!ship->structure[i]) {
	  req = i;
	  break;
	}
      }
    }
    /* sanity: */
    fc_assert_ret_val(-1 != req, FALSE);
    fc_assert_ret_val(!ship->structure[req], FALSE);
    
    /* Now we want to find a structural we can build which leads to req.
       This loop should bottom out, because everything leads back to s0,
       and we made sure above that we do s0 first.
     */
    while(!ship->structure[structurals_info[req].required]) {
      req = structurals_info[req].required;
    }
    type = SSHIP_PLACE_STRUCTURAL;
    num = req;
    handle_spaceship_place(pplayer, type, num);
    retval = TRUE;
  }
  return retval;
}