2015-10-20 13:51:49 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2015 Parallel Realities
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lookup.h"
|
|
|
|
|
|
|
|
static Lookup head;
|
|
|
|
static Lookup *tail;
|
|
|
|
|
|
|
|
static void addLookup(char *name, long value);
|
|
|
|
|
|
|
|
void initLookups(void)
|
|
|
|
{
|
|
|
|
memset(&head, 0, sizeof(Lookup));
|
|
|
|
tail = &head;
|
|
|
|
|
2015-10-26 18:27:43 +01:00
|
|
|
addLookup("ET_WAYPOINT", ET_WAYPOINT);
|
2015-11-09 23:46:57 +01:00
|
|
|
addLookup("ET_EXTRACTION_POINT", ET_EXTRACTION_POINT);
|
2015-12-07 20:19:14 +01:00
|
|
|
addLookup("ET_CAPITAL_SHIP", ET_CAPITAL_SHIP);
|
2015-10-26 18:27:43 +01:00
|
|
|
|
2015-10-26 20:16:12 +01:00
|
|
|
addLookup("EF_NO_KILL", EF_NO_KILL);
|
2015-11-14 17:14:48 +01:00
|
|
|
addLookup("EF_DISABLED", EF_DISABLED);
|
2015-11-16 17:24:57 +01:00
|
|
|
addLookup("EF_MUST_DISABLE", EF_MUST_DISABLE);
|
2015-10-26 20:16:12 +01:00
|
|
|
addLookup("EF_IMMORTAL", EF_IMMORTAL);
|
|
|
|
addLookup("EF_MISSION_TARGET", EF_MISSION_TARGET);
|
2015-11-21 18:32:39 +01:00
|
|
|
addLookup("EF_RETREATING", EF_RETREATING);
|
2015-11-15 00:18:09 +01:00
|
|
|
addLookup("EF_HAS_ROPE", EF_HAS_ROPE);
|
2015-11-16 12:26:23 +01:00
|
|
|
addLookup("EF_COLLECTS_ITEMS", EF_COLLECTS_ITEMS);
|
2015-11-20 23:51:44 +01:00
|
|
|
addLookup("EF_NO_EPIC", EF_NO_EPIC);
|
2015-11-30 12:29:56 +01:00
|
|
|
addLookup("EF_STATIC", EF_STATIC);
|
2015-12-07 20:19:14 +01:00
|
|
|
addLookup("EF_TAKES_DAMAGE", EF_TAKES_DAMAGE);
|
2015-12-10 13:40:23 +01:00
|
|
|
addLookup("EF_SECONDARY_TARGET", EF_SECONDARY_TARGET);
|
2015-12-12 18:12:25 +01:00
|
|
|
addLookup("EF_AI_TARGET", EF_AI_TARGET);
|
2015-12-18 13:02:01 +01:00
|
|
|
addLookup("EF_AI_LEADER", EF_AI_LEADER);
|
2015-10-23 23:44:39 +02:00
|
|
|
|
2015-11-18 12:27:05 +01:00
|
|
|
addLookup("AIF_NONE", AIF_NONE);
|
2015-11-28 15:33:05 +01:00
|
|
|
addLookup("AIF_MOVES_TO_PLAYER", AIF_MOVES_TO_PLAYER);
|
2015-11-18 12:27:05 +01:00
|
|
|
addLookup("AIF_FOLLOWS_PLAYER", AIF_FOLLOWS_PLAYER);
|
|
|
|
addLookup("AIF_UNLIMITED_RANGE", AIF_UNLIMITED_RANGE);
|
|
|
|
addLookup("AIF_COLLECTS_ITEMS", AIF_COLLECTS_ITEMS);
|
|
|
|
addLookup("AIF_TOWS", AIF_TOWS);
|
|
|
|
addLookup("AIF_RETREATS", AIF_RETREATS);
|
|
|
|
addLookup("AIF_GOAL_EXTRACTION", AIF_GOAL_EXTRACTION);
|
|
|
|
addLookup("AIF_AVOIDS_COMBAT", AIF_AVOIDS_COMBAT);
|
2015-11-22 00:27:43 +01:00
|
|
|
addLookup("AIF_DEFENSIVE", AIF_DEFENSIVE);
|
|
|
|
addLookup("AIF_MISSILE_BOAT", AIF_MISSILE_BOAT);
|
2015-11-30 12:29:56 +01:00
|
|
|
addLookup("AIF_AGGRESSIVE", AIF_AGGRESSIVE);
|
2015-12-08 23:42:31 +01:00
|
|
|
addLookup("AIF_LONG_RANGE_FIRE", AIF_LONG_RANGE_FIRE);
|
2015-12-18 13:02:01 +01:00
|
|
|
addLookup("AIF_MOVES_TO_LEADER", AIF_MOVES_TO_LEADER);
|
2015-12-24 22:42:26 +01:00
|
|
|
addLookup("AIF_WANDERS", AIF_WANDERS);
|
2015-11-18 12:27:05 +01:00
|
|
|
|
2015-12-24 13:12:23 +01:00
|
|
|
addLookup("DT_ANY", DT_ANY);
|
|
|
|
addLookup("DT_NO_SPIN", DT_NO_SPIN);
|
|
|
|
addLookup("DT_INSTANT", DT_INSTANT);
|
|
|
|
|
2015-10-22 08:08:03 +02:00
|
|
|
addLookup("TT_DESTROY", TT_DESTROY);
|
|
|
|
addLookup("TT_DISABLE", TT_DISABLE);
|
2015-10-28 20:12:58 +01:00
|
|
|
addLookup("TT_WAYPOINT", TT_WAYPOINT);
|
2015-11-11 23:33:33 +01:00
|
|
|
addLookup("TT_ESCAPED", TT_ESCAPED);
|
2015-11-20 23:51:44 +01:00
|
|
|
addLookup("TT_PLAYER_ESCAPED", TT_PLAYER_ESCAPED);
|
2015-11-16 13:31:50 +01:00
|
|
|
addLookup("TT_ITEM", TT_ITEM);
|
2015-10-22 08:08:03 +02:00
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
addLookup("WT_BUTTON", WT_BUTTON);
|
|
|
|
addLookup("WT_SELECT", WT_SELECT);
|
2015-11-26 09:16:29 +01:00
|
|
|
addLookup("WT_IMG_BUTTON", WT_IMG_BUTTON);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
addLookup("SIDE_ALLIES", SIDE_ALLIES);
|
|
|
|
addLookup("SIDE_PIRATE", SIDE_PIRATE);
|
2015-11-29 13:56:00 +01:00
|
|
|
addLookup("SIDE_REBEL", SIDE_REBEL);
|
2015-10-20 13:51:49 +02:00
|
|
|
addLookup("SIDE_PANDORAN", SIDE_PANDORAN);
|
|
|
|
addLookup("SIDE_CSN", SIDE_CSN);
|
|
|
|
addLookup("SIDE_UNF", SIDE_UNF);
|
|
|
|
addLookup("SIDE_INF", SIDE_INF);
|
|
|
|
|
|
|
|
addLookup("SND_PARTICLE", SND_PARTICLE);
|
|
|
|
addLookup("SND_PLASMA", SND_PLASMA);
|
2015-11-18 17:02:10 +01:00
|
|
|
addLookup("SND_LASER", SND_LASER);
|
2015-10-20 13:51:49 +02:00
|
|
|
addLookup("SND_MAG", SND_MAG);
|
2015-10-24 15:52:55 +02:00
|
|
|
addLookup("SND_MISSILE", SND_MISSILE);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
addLookup("BT_PARTICLE", BT_PARTICLE);
|
|
|
|
addLookup("BT_PLASMA", BT_PLASMA);
|
|
|
|
addLookup("BT_LASER", BT_LASER);
|
|
|
|
addLookup("BT_MAG", BT_MAG);
|
|
|
|
addLookup("BT_ROCKET", BT_ROCKET);
|
|
|
|
addLookup("BT_MISSILE", BT_MISSILE);
|
|
|
|
|
|
|
|
addLookup("BF_NONE", BF_NONE);
|
|
|
|
addLookup("BF_ENGINE", BF_ENGINE);
|
2015-10-21 20:21:45 +02:00
|
|
|
addLookup("BF_SYSTEM_DAMAGE", BF_SYSTEM_DAMAGE);
|
2015-11-18 17:02:10 +01:00
|
|
|
addLookup("BF_SHIELD_DAMAGE", BF_SHIELD_DAMAGE);
|
2015-10-24 15:52:55 +02:00
|
|
|
addLookup("BF_EXPLODES", BF_EXPLODES);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
addLookup("CHALLENGE_ARMOUR", CHALLENGE_ARMOUR);
|
|
|
|
addLookup("CHALLENGE_TIME", CHALLENGE_TIME);
|
|
|
|
addLookup("CHALLENGE_ACCURACY", CHALLENGE_ACCURACY);
|
|
|
|
addLookup("CHALLENGE_NO_LOSSES", CHALLENGE_NO_LOSSES);
|
|
|
|
addLookup("CHALLENGE_1_LOSS", CHALLENGE_1_LOSS);
|
|
|
|
addLookup("CHALLENGE_LOSSES", CHALLENGE_LOSSES);
|
|
|
|
addLookup("CHALLENGE_PLAYER_KILLS", CHALLENGE_PLAYER_KILLS);
|
2015-10-24 17:00:06 +02:00
|
|
|
addLookup("CHALLENGE_DISABLE", CHALLENGE_DISABLE);
|
|
|
|
addLookup("CHALLENGE_TIME_MINS", CHALLENGE_TIME_MINS);
|
2015-10-25 01:01:46 +02:00
|
|
|
|
|
|
|
addLookup("STAT_MISSIONS_STARTED", STAT_MISSIONS_STARTED);
|
|
|
|
addLookup("STAT_MISSIONS_COMPLETED", STAT_MISSIONS_COMPLETED);
|
|
|
|
addLookup("STAT_SHOTS_FIRED", STAT_SHOTS_FIRED);
|
|
|
|
addLookup("STAT_SHOTS_HIT", STAT_SHOTS_HIT);
|
2015-12-23 20:22:31 +01:00
|
|
|
addLookup("STAT_ROCKETS_FIRED", STAT_ROCKETS_FIRED);
|
|
|
|
addLookup("STAT_ROCKETS_HIT", STAT_ROCKETS_HIT);
|
2015-10-25 01:01:46 +02:00
|
|
|
addLookup("STAT_MISSILES_FIRED", STAT_MISSILES_FIRED);
|
|
|
|
addLookup("STAT_MISSILES_HIT", STAT_MISSILES_HIT);
|
|
|
|
addLookup("STAT_ENEMIES_KILLED", STAT_ENEMIES_KILLED);
|
|
|
|
addLookup("STAT_ENEMIES_KILLED_PLAYER", STAT_ENEMIES_KILLED_PLAYER);
|
|
|
|
addLookup("STAT_ALLIES_KILLED", STAT_ALLIES_KILLED);
|
|
|
|
addLookup("STAT_PLAYER_KILLED", STAT_PLAYER_KILLED);
|
2015-11-17 08:23:50 +01:00
|
|
|
addLookup("STAT_ENEMIES_DISABLED", STAT_ENEMIES_DISABLED);
|
2015-10-29 17:46:08 +01:00
|
|
|
addLookup("STAT_ENEMIES_ESCAPED", STAT_ENEMIES_ESCAPED);
|
2015-11-17 08:23:50 +01:00
|
|
|
addLookup("STAT_CIVILIANS_RESCUED", STAT_CIVILIANS_RESCUED);
|
|
|
|
addLookup("STAT_ECM", STAT_ECM);
|
|
|
|
addLookup("STAT_BOOST", STAT_BOOST);
|
|
|
|
addLookup("STAT_MISSILES_EVADED", STAT_MISSILES_EVADED);
|
|
|
|
addLookup("STAT_MISSILES_STRUCK", STAT_MISSILES_STRUCK);
|
|
|
|
addLookup("STAT_CIVILIANS_KILLED", STAT_CIVILIANS_KILLED);
|
|
|
|
addLookup("STAT_TUG", STAT_TUG);
|
|
|
|
addLookup("STAT_SHUTTLE", STAT_SHUTTLE);
|
|
|
|
addLookup("STAT_NUM_TOWED", STAT_NUM_TOWED);
|
|
|
|
addLookup("STAT_ITEMS_COLLECTED", STAT_ITEMS_COLLECTED);
|
|
|
|
addLookup("STAT_EPIC_KILL_STREAK", STAT_EPIC_KILL_STREAK);
|
2015-12-19 17:15:57 +01:00
|
|
|
addLookup("STAT_CAPITAL_SHIPS_DESTROYED", STAT_CAPITAL_SHIPS_DESTROYED);
|
|
|
|
addLookup("STAT_CAPITAL_SHIPS_LOST", STAT_CAPITAL_SHIPS_LOST);
|
2015-10-25 01:01:46 +02:00
|
|
|
addLookup("STAT_TIME", STAT_TIME);
|
2015-10-20 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void addLookup(char *name, long value)
|
|
|
|
{
|
|
|
|
Lookup *lookup = malloc(sizeof(Lookup));
|
|
|
|
memset(lookup, 0, sizeof(Lookup));
|
|
|
|
|
|
|
|
STRNCPY(lookup->name, name, MAX_NAME_LENGTH);
|
|
|
|
lookup->value = value;
|
|
|
|
|
|
|
|
tail->next = lookup;
|
|
|
|
tail = lookup;
|
|
|
|
}
|
|
|
|
|
|
|
|
long lookup(char *name)
|
|
|
|
{
|
|
|
|
Lookup *l;
|
|
|
|
|
|
|
|
for (l = head.next ; l != NULL ; l = l->next)
|
|
|
|
{
|
|
|
|
if (strcmp(l->name, name) == 0)
|
|
|
|
{
|
|
|
|
return l->value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "No such lookup value '%s'", name);
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *getLookupName(char *prefix, long num)
|
|
|
|
{
|
|
|
|
Lookup *l;
|
|
|
|
|
|
|
|
for (l = head.next ; l != NULL ; l = l->next)
|
|
|
|
{
|
|
|
|
if (l->value == num && strncmp(prefix, l->name, strlen(prefix)) == 0)
|
|
|
|
{
|
|
|
|
return l->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-23 11:14:42 +01:00
|
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "No such lookup value %ld, prefix=%s", num, prefix);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *getFlagValues(char *prefix, long flags)
|
|
|
|
{
|
|
|
|
static char flagStr[MAX_DESCRIPTION_LENGTH];
|
|
|
|
int requirePlus;
|
|
|
|
Lookup *l;
|
|
|
|
|
|
|
|
memset(flagStr, '\0', MAX_DESCRIPTION_LENGTH);
|
|
|
|
|
|
|
|
requirePlus = 0;
|
|
|
|
|
|
|
|
for (l = head.next ; l != NULL ; l = l->next)
|
|
|
|
{
|
|
|
|
if (flags & l->value && strncmp(prefix, l->name, strlen(prefix)) == 0)
|
|
|
|
{
|
|
|
|
if (requirePlus)
|
|
|
|
{
|
|
|
|
strcat(flagStr, "+");
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat(flagStr, l->name);
|
|
|
|
|
|
|
|
requirePlus = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flagStr;
|
|
|
|
}
|
|
|
|
|
2015-12-12 19:24:23 +01:00
|
|
|
long flagsToLong(char *flags, int *add)
|
2015-10-20 13:51:49 +02:00
|
|
|
{
|
|
|
|
char *flag;
|
|
|
|
long total;
|
|
|
|
|
|
|
|
total = 0;
|
|
|
|
|
2015-12-12 19:24:23 +01:00
|
|
|
if (add)
|
|
|
|
{
|
|
|
|
*add = (flags[0] == '+');
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
flag = strtok(flags, "+");
|
|
|
|
while (flag)
|
|
|
|
{
|
|
|
|
total += lookup(flag);
|
|
|
|
flag = strtok(NULL, "+");
|
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroyLookups(void)
|
|
|
|
{
|
|
|
|
Lookup *l;
|
|
|
|
|
|
|
|
while (head.next)
|
|
|
|
{
|
|
|
|
l = head.next;
|
|
|
|
head.next = l->next;
|
|
|
|
free(l);
|
|
|
|
}
|
|
|
|
}
|