/** * @brief Runs all the events matching a trigger. * * @param trigger Trigger to match. */ void events_trigger( EventTrigger_t trigger ) { int i, c; 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 ); } }
/** * @brief Checks to see if the player has an event active. * * @usage if player.evtActive( "Shipwreck" ) then -- The shipwreck event is active * * @luaparam name Name of the mission to check. * @luareturn true if the mission is active, false if it isn't. * @luafunc evtActive( name ) */ static int playerL_evtActive( lua_State *L ) { int evtid; const char *str; str = luaL_checkstring(L,1); evtid = event_dataID( str ); if (evtid < 0) { NLUA_ERROR(L, "Event '%s' not found in stack", str); return 0; } lua_pushboolean( L, event_alreadyRunning( evtid ) ); return 1; }
/** * @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(); }