Ejemplo n.º 1
0
/**
 * @brief Aborts a mission in the mission menu.
 *    @param str Unused.
 */
static void mission_menu_abort( unsigned int wid, char* str )
{
   (void)str;
   int pos;
   Mission* misn;
   int ret;

   if (dialogue_YesNo( "Abort Mission",
            "Are you sure you want to abort this mission?" )) {

      /* Get the mission. */
      pos = toolkit_getListPos(wid, "lstMission" );
      misn = &player_missions[pos];

      /* We run the "abort" function if it's found. */
      ret = misn_tryRun( misn, "abort" );

      /* Now clean up mission. */
      if (ret != 2) {
         mission_cleanup( misn );
         memmove( misn, &player_missions[pos+1],
               sizeof(Mission) * (MISSION_MAX-pos-1) );
         memset( &player_missions[MISSION_MAX-1], 0, sizeof(Mission) );
      }

      /* Reset markers. */
      mission_sysMark();

      /* Reset claims. */
      claim_activateAll();

      /* Regenerate list. */
      mission_menu_genList(wid ,0);
   }
}
Ejemplo n.º 2
0
/**
 * @brief Runs all the events matching a trigger.
 *
 *    @param trigger Trigger to match.
 */
void events_trigger( EventTrigger_t trigger )
{
   int i, c;
   int created;

   /* Events can't be triggered by tutorial. */
   if (player_isTut())
      return;

   created = 0;
   for (i=0; i<event_ndata; i++) {
      /* Make sure trigger matches. */
      if (event_data[i].trigger != trigger)
         continue;

      /* Make sure chance is succeeded. */
      if (RNGF() > event_data[i].chance)
         continue;

      /* Test uniqueness. */
      if ((event_data[i].flags & EVENT_FLAG_UNIQUE) &&
            (player_eventAlreadyDone( i ) || event_alreadyRunning(i)))
         continue;

      /* Test conditional. */
      if (event_data[i].cond != NULL) {
         c = cond_check(event_data[i].cond);
         if (c<0) {
            WARN("Conditional for event '%s' failed to run.", event_data[i].name);
            continue;
         }
         else if (!c)
            continue;
      }

      /* Create the event. */
      event_create( i, NULL );
      created++;
   }

   /* Run claims if necessary. */
   if (created)
      claim_activateAll();
}
Ejemplo n.º 3
0
/**
 * @brief Makes the player jettison the currently selected cargo.
 *    @param str Unused.
 */
static void cargo_jettison( unsigned int wid, char* str )
{
   (void)str;
   int i, j, f, pos, ret;
   Mission *misn;

   if (player.p->ncommodities==0)
      return; /* No cargo, redundant check */

   pos = toolkit_getListPos( wid, "lstCargo" );

   /* Special case mission cargo. */
   if (player.p->commodities[pos].id != 0) {
      if (!dialogue_YesNo( "Abort Mission",
               "Are you sure you want to abort this mission?" ))
         return;

      /* Get the mission. */
      f = 0;
      for (i=0; i<MISSION_MAX; i++) {
         for (j=0; j<player_missions[i].ncargo; j++) {
            if (player_missions[i].cargo[j] == player.p->commodities[pos].id) {
               f = 1;
               break;
            }
         }
         if (f==1)
            break;
      }
      if (!f) {
         WARN("Cargo '%d' does not belong to any active mission.",
               player.p->commodities[pos].id);
         return;
      }
      misn = &player_missions[i];

      /* We run the "abort" function if it's found. */
      ret = misn_tryRun( misn, "abort" );

      /* Now clean up mission. */
      if (ret != 2) {
         mission_cleanup( misn );
         memmove( misn, &player_missions[i+1],
               sizeof(Mission) * (MISSION_MAX-i-1) );
         memset( &player_missions[MISSION_MAX-1], 0, sizeof(Mission) );
      }

      /* Reset markers. */
      mission_sysMark();

      /* Reset claims. */
      claim_activateAll();

      /* Regenerate list. */
      mission_menu_genList( info_windows[ INFO_WIN_MISN ] ,0);
   }
   else {
      /* Remove the cargo */
      commodity_Jettison( player.p->id, player.p->commodities[pos].commodity,
            player.p->commodities[pos].quantity );
      pilot_cargoRm( player.p, player.p->commodities[pos].commodity,
            player.p->commodities[pos].quantity );
   }

   /* We reopen the menu to recreate the list now. */
   ship_update( info_windows[ INFO_WIN_SHIP ] );
   cargo_genList( wid );
}
Ejemplo n.º 4
0
/**
 * @brief Tries to run a pilot hook if he has it.
 *
 *    @param p Pilot to run the hook.
 *    @param hook_type Type of hook to run.
 *    @return The number of hooks run.
 */
int pilot_runHookParam( Pilot* p, int hook_type, HookParam* param, int nparam )
{
   int n, i, run, ret;
   HookParam hparam[3], *hdynparam;

   /* Set up hook parameters. */
   if (nparam <= 1) {
      hparam[0].type       = HOOK_PARAM_PILOT;
      hparam[0].u.lp.pilot = p->id;
      n  = 1;
      if (nparam == 1) {
         memcpy( &hparam[n], param, sizeof(HookParam) );
         n++;
      }
      hparam[n].type    = HOOK_PARAM_SENTINAL;
      hdynparam         = NULL;
   }
   else {
      hdynparam   = malloc( sizeof(HookParam) * (nparam+2) );
      hdynparam[0].type       = HOOK_PARAM_PILOT;
      hdynparam[0].u.lp.pilot = p->id;
      memcpy( &hdynparam[1], param, sizeof(HookParam)*nparam );
      hdynparam[nparam].type  = HOOK_PARAM_SENTINAL;
   }

   /* Run pilot specific hooks. */
   run = 0;
   for (i=0; i<p->nhooks; i++) {
      if (p->hooks[i].type != hook_type)
         continue;

      ret = hook_runIDparam( p->hooks[i].id, hparam );
      if (ret)
         WARN("Pilot '%s' failed to run hook type %d", p->name, hook_type);
      else
         run++;
   }

   /* Run global hooks. */
   if (pilot_globalHooks != NULL) {
      for (i=0; i<array_size(pilot_globalHooks); i++) {
         if (pilot_globalHooks[i].type != hook_type)
            continue;

         ret = hook_runIDparam( pilot_globalHooks[i].id, hparam );
         if (ret)
            WARN("Pilot '%s' failed to run hook type %d", p->name, hook_type);
         else
            run++;
      }
   }

   /* Clean up. */
   if (hdynparam != NULL)
      free( hdynparam );

   if (run > 0)
      claim_activateAll(); /* Reset claims. */

   return run;
}