示例#1
0
/**
 * @brief Runs missions matching location, all Lua side and one-shot.
 *
 *    @param loc Location to match.
 *    @param faction Faction of the planet.
 *    @param planet Name of the current planet.
 *    @param sysname Name of the current system.
 */
void missions_run( int loc, int faction, const char* planet, const char* sysname )
{
   MissionData* misn;
   Mission mission;
   int i;
   double chance;

   for (i=0; i<mission_nstack; i++) {
      misn = &mission_stack[i];
      if (misn->avail.loc != loc)
         continue;

      if (!mission_meetReq(i, faction, planet, sysname))
         continue;

      chance = (double)(misn->avail.chance % 100)/100.;
      if (chance == 0.) /* We want to consider 100 -> 100% not 0% */
         chance = 1.;

      if (RNGF() < chance) {
         mission_init( &mission, misn, 1, 1, NULL );
         mission_cleanup(&mission); /* it better clean up for itself or we do it */
      }
   }
}
示例#2
0
文件: mission.c 项目: AvanWolf/naev
/**
 * @brief Generates a mission list. This runs create() so won't work with all
 *        missions.
 *
 *    @param[out] n Missions created.
 *    @param faction Faction of the planet.
 *    @param planet Name of the planet.
 *    @param sysname Name of the current system.
 *    @param loc Location
 *    @return The stack of Missions created with n members.
 */
Mission* missions_genList( int *n, int faction,
                           const char* planet, const char* sysname, int loc )
{
    int i,j, m, alloced;
    double chance;
    int rep;
    Mission* tmp;
    MissionData* misn;

    /* Missions can't be generated by tutorial. */
    if (player_isTut()) {
        *n = 0;
        return NULL;
    }

    /* Find available missions. */
    tmp      = NULL;
    m        = 0;
    alloced  = 0;
    for (i=0; i<mission_nstack; i++) {
        misn = &mission_stack[i];
        if (misn->avail.loc == loc) {

            /* Must meet requirements. */
            if (!mission_meetReq(i, faction, planet, sysname))
                continue;

            /* Must hit chance. */
            chance = (double)(misn->avail.chance % 100)/100.;
            if (chance == 0.) /* We want to consider 100 -> 100% not 0% */
                chance = 1.;
            rep = MAX(1, misn->avail.chance / 100);

            for (j=0; j<rep; j++) /* random chance of rep appearances */
                if (RNGF() < chance) {
                    m++;
                    /* Extra allocation. */
                    if (m > alloced) {
                        alloced += 32;
                        tmp      = realloc( tmp, sizeof(Mission) * alloced );
                    }
                    /* Initialize the mission. */
                    if (mission_init( &tmp[m-1], misn, 1, 1, NULL ))
                        m--;
                }
        }
    }

    /* Sort. */
    if (tmp != NULL) {
        qsort( tmp, m, sizeof(Mission), mission_compare );
        (*n) = m;
    }
    else {
        (*n) = 0;
    }
    return tmp;
}