- [+] move all definitions into data.c

- [+] initcommands
    - [+] initobjects
    - [+] initskills
    - [+] initjobs
    - [+] initrace
    - [+] (but leave init() itself in nexus.c)
This commit is contained in:
Rob Pearce 2011-09-15 01:58:16 +00:00
parent 885953fc9b
commit b200e3acf7
8 changed files with 9 additions and 8385 deletions

View File

@ -1,5 +1,5 @@
nexus: Makefile defs.h nexus.c nexus.h ai.c ai.h attack.c attack.h flag.c flag.h god.c god.h io.c io.h lf.c lf.h map.c map.h move.c move.h objects.c objects.h text.c text.h save.c save.h spell.c spell.h vault.c vault.h nexus: Makefile defs.h nexus.c nexus.h ai.c ai.h attack.c attack.h data.c data.h flag.c flag.h god.c god.h io.c io.h lf.c lf.h map.c map.h move.c move.h objects.c objects.h text.c text.h save.c save.h spell.c spell.h vault.c vault.h
gcc -Wall -g -pg -o nexus nexus.c ai.c attack.c flag.c god.c io.c lf.c map.c move.c objects.c text.c save.c spell.c vault.c vault.h -lncurses -lsqlite3 gcc -Wall -g -pg -o nexus nexus.c ai.c attack.c data.c flag.c god.c io.c lf.c map.c move.c objects.c text.c save.c spell.c vault.c vault.h -lncurses -lsqlite3
check: Makefile defs.h nexus.c nexus.h ai.c ai.h attack.c attack.h flag.c flag.h god.c god.h io.c io.h lf.c lf.h map.c map.h move.c move.h objects.c objects.h text.c text.h save.c save.h spell.c spell.h vault.c vault.h check: Makefile defs.h nexus.c nexus.h ai.c ai.h attack.c attack.h data.c data.h flag.c flag.h god.c god.h io.c io.h lf.c lf.h map.c map.h move.c move.h objects.c objects.h text.c text.h save.c save.h spell.c spell.h vault.c vault.h
splint -onlytrans -nullret -nullstate -branchstate -usedef -type -retvalint -retvalother +posixlib -unrecog -boolops -mustfreefresh -predboolint -unqualifiedtrans -compdef *.c splint -onlytrans -nullret -nullstate -branchstate -usedef -type -retvalint -retvalother +posixlib -unrecog -boolops -mustfreefresh -predboolint -unqualifiedtrans -compdef *.c

5
defs.h
View File

@ -2854,6 +2854,11 @@ typedef struct glyph_s {
int colour; int colour;
} glyph_t; } glyph_t;
typedef struct hiddennamewithcol_s {
char *name;
enum COLOUR col;
} hiddennamewithcol_t;
typedef struct cell_s { typedef struct cell_s {
map_t *map; // pointer back to map map_t *map; // pointer back to map
int x,y; // map coords int x,y; // map coords

3768
lf.c

File diff suppressed because it is too large Load Diff

3
lf.h
View File

@ -238,9 +238,6 @@ flag_t *hasactivespell(lifeform_t *lf, enum OBTYPE sid);
int haslof(cell_t *src, cell_t *dest, enum LOFTYPE loftype, cell_t **newdest); int haslof(cell_t *src, cell_t *dest, enum LOFTYPE loftype, cell_t **newdest);
int haslos(lifeform_t *viewer, cell_t *dest); int haslos(lifeform_t *viewer, cell_t *dest);
int haslos_fast(lifeform_t *viewer, cell_t *dest); int haslos_fast(lifeform_t *viewer, cell_t *dest);
void initjobs(void);
void initrace(void);
void initskills(void);
void interrupt(lifeform_t *lf); void interrupt(lifeform_t *lf);
int isairborne(lifeform_t *lf); int isairborne(lifeform_t *lf);
int isaquatic(lifeform_t *lf); int isaquatic(lifeform_t *lf);

113
nexus.c
View File

@ -8,6 +8,7 @@
#include <unistd.h> #include <unistd.h>
#include "ai.h" #include "ai.h"
#include "attack.h" #include "attack.h"
#include "data.h"
#include "io.h" #include "io.h"
#include "flag.h" #include "flag.h"
#include "lf.h" #include "lf.h"
@ -469,31 +470,6 @@ celltype_t *addcelltype(int id, char *name, char glyph, int colour, int solid, i
return a; return a;
} }
command_t *addcommand(enum COMMAND id, char ch, char *desc) {
command_t *a;
// add to the end of the list
if (firstcommand == NULL) {
firstcommand = malloc(sizeof(command_t));
a = firstcommand;
a->prev = NULL;
} else {
// go to end of list
a = lastcommand;
a->next = malloc(sizeof(command_t));
a->next->prev = a;
a = a->next;
}
lastcommand = a;
a->next = NULL;
// set props
a->id = id;
a->ch = ch;
a->desc = strdup(desc);
return a;
}
void checkdeath(void) { void checkdeath(void) {
lifeform_t *lf, *nextlf; lifeform_t *lf, *nextlf;
@ -966,51 +942,6 @@ void initbresnham(int x1, int y1, int x2, int y2, int *xinc1, int *yinc1, int *d
} }
} }
void initcommands(void) {
// Actions
addcommand(CMD_UP, '<', "Go up stairs.");
addcommand(CMD_DOWN, '>', "Go down stairs, enter a shop/portal.");
addcommand(CMD_REST, '.', "Rest once.");
addcommand(CMD_PICKUP, ',', "Pick up something from the ground.");
addcommand(CMD_CLOSE, 'c', "Close a door.");
addcommand(CMD_COMMS, 'C', "Communicate with an ally.");
//addcommand(CMD_DROP, 'd', "Drop an item.");
addcommand(CMD_DROPMULTI, 'd', "Drop one or more items.");
addcommand(CMD_EAT, 'e', "Eat something.");
addcommand(CMD_EAT, 'E', "Enhance your skills.");
addcommand(CMD_MAGIC, 'm', "Use magic or abilities.");
addcommand(CMD_MEMMAGIC, 'M', "Memorise a magic shortcut");
addcommand(CMD_OFFER, 'O', "Offer a sacrifice to the gods.");
addcommand(CMD_OPERATE, 'o', "Operate a tool/wand/device.");
addcommand(CMD_PICKLOCK, 'p', "Pick a lock.");
addcommand(CMD_POUR, 'P', "Pour a potion onto something.");
addcommand(CMD_QUAFF, 'q', "Quaff (drink) a potion.");
addcommand(CMD_READ, 'r', "Read a scroll/book.");
addcommand(CMD_RESTFULL, 'R', "Rest until healed, or train your skills.");
addcommand(CMD_THROW, 't', "Throw an object.");
addcommand(CMD_TAKEOFF, 'T', "Take off an item of clothing/jewelery.");
addcommand(CMD_WEILD, 'w', "Weild a weapon.");
addcommand(CMD_WEAR, 'W', "Wear an item of clothing/jewelery.");
// Firearms
addcommand(CMD_FIRE, 'f', "Fire your firearm/bow at your current target.");
addcommand(CMD_FIRENEW, 'F', "Fire your firearm/bow at a new target.");
addcommand(CMD_AIM, 'a', "Aim your current firearm/bow at a new target.");
// Information
addcommand(CMD_HELP, '?', "Display this text.");
addcommand(CMD_INFOPLAYER, '@', "Display player stats.");
addcommand(CMD_INFOARMOUR, ']', "Display player armour.");
addcommand(CMD_FORCEATTACK, 'A', "Force an attack in a given direction.");
addcommand(CMD_LOOKHERE, ':', "Look at current cell.");
addcommand(CMD_LOOKAROUND, '/', "Look at a remote cell.");
addcommand(CMD_INFOKNOWLEDGE, '\\', "Display known items.");
addcommand(CMD_MSGHIST, '|', "Display message history.");
addcommand(CMD_INV, 'i', "Display your inventory.");
// GAME FUNCTIONS
addcommand(CMD_QUIT, 'Q', "Quit the game.");
addcommand(CMD_SAVEQUIT, 'S', "Save and quit the game.");
sortcommands();
}
int isplayerturn(void) { int isplayerturn(void) {
if (!player) return B_FALSE; if (!player) return B_FALSE;
@ -1360,48 +1291,6 @@ dblog("doing sort...");
} }
*/ */
void sortcommands(void) {
command_t *c;
int donesomething = B_TRUE;
while (donesomething) {
donesomething = B_FALSE;
for (c = firstcommand ; c->next ; c = c->next) {
// move up one position if required.
if (c->ch > c->next->ch) {
command_t *temp;
// remember next element
temp = c->next;
// remove this element from list
if (c->prev == NULL) {
// first
firstcommand = c->next;
c->next->prev = NULL;
} else {
// not first
c->prev->next = c->next;
c->next->prev = c->prev;
}
// re-add element afterwards
c->next = temp->next;
c->prev = temp;
temp->next = c;
if (c->next == NULL) {
lastcommand = c;
} else {
c->next->prev = c;
}
// mark as done.
donesomething = B_TRUE;
break;
}
}
}
}
void timeeffectsworld(map_t *map, int updategametime) { void timeeffectsworld(map_t *map, int updategametime) {

View File

@ -1,7 +1,6 @@
#include "defs.h" #include "defs.h"
celltype_t *addcelltype(int id, char *name, char glyph, int colour, int solid, int transparent, enum MATERIAL mat, int floorheight); celltype_t *addcelltype(int id, char *name, char glyph, int colour, int solid, int transparent, enum MATERIAL mat, int floorheight);
command_t *addcommand(enum COMMAND id, char c, char *desc);
void checkdeath(void); void checkdeath(void);
void checkendgame(void); void checkendgame(void);
void cleanup(void); void cleanup(void);
@ -15,7 +14,6 @@ void getrarityrange(int depth, int *min, int *max, int range, int oodok);
int init(void); int init(void);
void calcbresnham(map_t *m, int x1, int y1, int x2, int y2, cell_t **retcell, int *numpixels); void calcbresnham(map_t *m, int x1, int y1, int x2, int y2, cell_t **retcell, int *numpixels);
void initbresnham(int x1, int y1, int x2, int y2, int *xinc1, int *yinc1, int *dinc1, int *xinc2, int *yinc2, int *dinc2, int *numpixels, int *d); void initbresnham(int x1, int y1, int x2, int y2, int *xinc1, int *yinc1, int *dinc1, int *xinc2, int *yinc2, int *dinc2, int *numpixels, int *d);
void initcommands(void);
int isplayerturn(void); int isplayerturn(void);
int limit(int *what, int min, int max); int limit(int *what, int min, int max);
int limitf(float *what, float min, float max); int limitf(float *what, float min, float max);
@ -31,6 +29,5 @@ int rolldie(int ndice, int sides);
int rollhitdice(lifeform_t *lf); int rollhitdice(lifeform_t *lf);
int rollmpdice(lifeform_t *lf); int rollmpdice(lifeform_t *lf);
//void sortlf(map_t *map); //void sortlf(map_t *map);
void sortcommands(void);
void timeeffectsworld(map_t *map, int updategametime); void timeeffectsworld(map_t *map, int updategametime);
void usage(char *progname); void usage(char *progname);

4495
objects.c

File diff suppressed because it is too large Load Diff

View File

@ -143,7 +143,6 @@ object_t *hasobwithflagval(obpile_t *op, enum FLAG flagid, int val0, int val1, i
object_t *hasobid(obpile_t *op, long id); object_t *hasobid(obpile_t *op, long id);
void identify(object_t *o); void identify(object_t *o);
void ignite(object_t *o); void ignite(object_t *o);
void initobjects(void);
flag_t *isarmour(object_t *o); flag_t *isarmour(object_t *o);
int isactivated(object_t *o); int isactivated(object_t *o);
int isammofor(objecttype_t *ammo, object_t *gun); int isammofor(objecttype_t *ammo, object_t *gun);