Lephisto/src/mission.h
2014-04-14 21:15:38 +01:00

101 lines
2.7 KiB
C

#pragma once
#include "llua_misn.h"
/* Availability by location. */
#define MIS_AVAIL_NONE 0
#define MIS_AVAIL_COMPUTER 1
#define MIS_AVAIL_BAR 2
#define MIS_AVAIL_OUTFIT 3
#define MIS_AVAIL_SHIPYARD 4
#define MIS_AVAIL_LAND 5
#define MIS_AVAIL_COMMODITY 6 /**< Mission is available at commodity exchange. */
/* Flags. */
#define mis_isFlag(m,f) ((m)->flags & (f))
#define mis_setFlag(m,f) ((m)->flags |= (f))
#define mis_rmFlag(m,f) ((m)->flags &= ~(f))
#define MISSION_UNIQUE 1 /* Unique missions can't be repeated. */
#define MISSION_TIMER_MAX 4 /**< Maximum amount of timers in a mission. */
/* Static mission data. */
typedef struct MissionData_ {
char* name; /* the name of the mission. */
/* Availability. */
struct {
int loc; /* Location. */
int chance; /* Chance of it appearing. */
/* For specific cases. */
char* planet;
char* system;
/* For generic cases. */
int* factions;
int nfactions;
char* cond; /* Conditional that must be met. */
char* done; /* Previous mission that must have been done. */
} avail;
unsigned int flags; /* Flags to store binary properties. */
char* lua;
} MissionData;
/* Active mission. */
typedef struct Mission_ {
MissionData* data;
/* Unique mission identifier, used for keeping track of hooks. */
unsigned int id;
char* title; /* Not to be confused with name.. */
char* desc; /* Description of the mission. */
char* reward; /* Rewards - in text. */
/* Mission cargo give to the player - Need to cleanup. */
unsigned int* cargo;
int ncargo;
char* sys_marker; /* Marked system. */
/* Timers. */
double timer[MISSION_TIMER_MAX];
char* tfunc[MISSION_TIMER_MAX];
lua_State* L; /* The state of the running lua code. */
} Mission;
#define MISSION_MAX 6 /* No sense in the player having unlimited missions.. */
extern Mission player_missions[MISSION_MAX];
/* For mission computer. */
Mission* missions_computer(int* n, int faction, char* planet, char* sysname);
/* Player accepted mission - mission computer. */
int mission_accept(Mission* mission);
void missions_run(int loc, int faction, char* planet, char* sysname);
int mission_start(char* name);
/* Misc. */
void missions_update(const double dt);
int mission_getID(char* name);
MissionData* mission_get(int id);
void mission_sysMark(void);
void mission_sysComputerMark(Mission* misn);
/* Cargo stuff. */
int mission_linkCargo(Mission* misn, unsigned int cargo_id);
int mission_unlinkCargo(Mission* misn, unsigned int cargo_id);
/* Load/Quit. */
int missions_load(void);
void mission_cleanup(Mission* misn);
void missions_free(void);
void missions_cleanup(void);
int misn_tryRun(Mission* misn, char* func);
int misn_run(Mission* misn, char* func);