2011-02-01 06:16:13 +11:00
|
|
|
#include <ctype.h>
|
2010-12-02 12:17:54 +11:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "defs.h"
|
2011-02-01 06:16:13 +11:00
|
|
|
#include "lf.h"
|
2010-12-02 12:17:54 +11:00
|
|
|
#include "objects.h"
|
2011-02-01 06:16:13 +11:00
|
|
|
#include "text.h"
|
|
|
|
|
|
|
|
extern long curtime;
|
2010-12-02 12:17:54 +11:00
|
|
|
|
2011-04-06 17:27:55 +10:00
|
|
|
|
|
|
|
int needan(char *text) {
|
|
|
|
if (isvowel(tolower(text[0]))) {
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
char *capitalise(char *text) {
|
2011-02-01 06:16:13 +11:00
|
|
|
if (strlen(text) > 0) {
|
|
|
|
text[0] = toupper(text[0]);
|
|
|
|
}
|
2010-12-02 12:17:54 +11:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2011-02-16 05:21:33 +11:00
|
|
|
char *capitaliseall(char *text) {
|
|
|
|
if (strlen(text) > 0) {
|
|
|
|
char *p;
|
|
|
|
for (p = text ; *p; p++) {
|
|
|
|
if (p == text) { // first letter
|
|
|
|
*p = toupper(*p);
|
|
|
|
} else if (*(p-1) == ' ') { // first letter after a space
|
|
|
|
*p = toupper(*p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2011-04-01 10:54:44 +11:00
|
|
|
char *dicetotext(int ndice, int nsides, int bonus, int *min, int *max, char *dicebuf, char *minmaxbuf) {
|
|
|
|
int localmin, localmax;
|
|
|
|
|
|
|
|
if (ndice == NA) ndice = 0;
|
|
|
|
if (nsides == NA) nsides = 0;
|
|
|
|
if (bonus == NA) bonus = 0;
|
|
|
|
|
|
|
|
// ie. rolled a 1 on all dice
|
|
|
|
localmin = (ndice * 1) + bonus;
|
|
|
|
// ie. rolled max on all dice
|
|
|
|
localmax = (ndice * nsides) + bonus;
|
|
|
|
|
|
|
|
if (min) {
|
|
|
|
*min = localmin;
|
|
|
|
}
|
|
|
|
if (max) {
|
|
|
|
*max = localmax;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dicebuf) {
|
|
|
|
if ((ndice == 0) || (nsides == 0)) {
|
|
|
|
sprintf(dicebuf, "%d", bonus);
|
|
|
|
} else {
|
|
|
|
if (bonus) {
|
|
|
|
sprintf(dicebuf, "%dd%d%c%d", ndice, nsides,
|
|
|
|
(bonus > 0) ? '+' : '-',
|
|
|
|
abs(bonus));
|
|
|
|
} else {
|
|
|
|
sprintf(dicebuf, "%dd%d", ndice, nsides);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (minmaxbuf) {
|
|
|
|
if (localmin == localmax) {
|
|
|
|
sprintf(minmaxbuf, "%d", localmin);
|
|
|
|
} else {
|
|
|
|
sprintf(minmaxbuf, "%d-%d", localmin, localmax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dicebuf;
|
|
|
|
}
|
|
|
|
|
2011-04-06 17:27:55 +10:00
|
|
|
char *getattrabbrev(enum ATTRIB att) {
|
|
|
|
switch (att) {
|
|
|
|
case A_NONE:
|
|
|
|
return "??";
|
|
|
|
case A_STR:
|
|
|
|
return "St";
|
|
|
|
case A_IQ:
|
|
|
|
return "Iq";
|
|
|
|
case A_DEX:
|
|
|
|
return "Dx";
|
|
|
|
case A_CON:
|
|
|
|
return "Cn";
|
|
|
|
}
|
|
|
|
return "??";
|
|
|
|
}
|
2011-04-01 10:54:44 +11:00
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
char *getattrname(enum ATTRIB att) {
|
|
|
|
switch (att) {
|
2011-03-24 16:09:31 +11:00
|
|
|
case A_NONE:
|
|
|
|
return "?attrib_none?";
|
2011-02-01 06:16:13 +11:00
|
|
|
case A_STR:
|
|
|
|
return "strength";
|
|
|
|
case A_IQ:
|
|
|
|
return "intelligence";
|
|
|
|
case A_DEX:
|
|
|
|
return "dexterity";
|
2011-03-24 16:09:31 +11:00
|
|
|
case A_CON:
|
|
|
|
return "constitution";
|
2011-02-01 06:16:13 +11:00
|
|
|
}
|
2011-03-24 16:09:31 +11:00
|
|
|
return "?badattrib?";
|
2011-02-01 06:16:13 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
char *getpossessive(char *text) {
|
|
|
|
char lastchar;
|
|
|
|
// you -> your
|
|
|
|
if (!strcmp(text, "you")) {
|
|
|
|
return "r";
|
|
|
|
}
|
|
|
|
|
|
|
|
// xxxs -> xxxs'
|
|
|
|
lastchar = text[strlen(text)-1];
|
|
|
|
if (tolower(lastchar) == 's') {
|
|
|
|
return "'";
|
|
|
|
}
|
|
|
|
// default: 's
|
|
|
|
return "'s";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *getsizetext(enum LFSIZE sz) {
|
|
|
|
switch (sz) {
|
|
|
|
case SZ_ENORMOUS:
|
|
|
|
return "enormous";
|
|
|
|
case SZ_HUGE:
|
|
|
|
return "huge";
|
|
|
|
case SZ_LARGE:
|
|
|
|
return "large";
|
|
|
|
case SZ_HUMAN:
|
|
|
|
return "human-sized";
|
|
|
|
case SZ_MEDIUM:
|
|
|
|
return "medium";
|
|
|
|
case SZ_SMALL:
|
|
|
|
return "small";
|
|
|
|
case SZ_MINI:
|
|
|
|
case SZ_TINY:
|
|
|
|
return "extremely small";
|
|
|
|
default:
|
|
|
|
return "unknown-sized";
|
|
|
|
}
|
|
|
|
return "unknown-sized";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *gettimetext(char *retbuf) {
|
|
|
|
int hours,mins,secs;
|
|
|
|
splittime(&hours, &mins, &secs);
|
|
|
|
|
|
|
|
sprintf(retbuf, "%02d:%02d:%02d",hours,mins,secs);
|
|
|
|
return retbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *gettimetextfuzzy(char *retbuf, int wantpm) {
|
|
|
|
int hours,mins,secs;
|
|
|
|
int pm = B_FALSE;
|
|
|
|
splittime(&hours, &mins, &secs);
|
|
|
|
|
|
|
|
if (hours > 12) {
|
|
|
|
hours -= 12;
|
|
|
|
pm = B_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mins == 0) {
|
|
|
|
sprintf(retbuf, "exactly %d o'clock", hours);
|
|
|
|
} else if (mins <= 15) {
|
|
|
|
sprintf(retbuf, "a little after %d o'clock", hours);
|
|
|
|
} else if (mins <= 25) {
|
|
|
|
sprintf(retbuf, "nearly half past %d", hours);
|
|
|
|
} else if (mins <= 35) {
|
|
|
|
sprintf(retbuf, "around half past %d", hours);
|
|
|
|
} else if (mins <= 45) {
|
2011-03-04 12:22:36 +11:00
|
|
|
sprintf(retbuf, "coming up to %d o'clock", (hours == 12) ? 1 : (hours+1));
|
2011-02-01 06:16:13 +11:00
|
|
|
} else {
|
|
|
|
sprintf(retbuf, "nearly %d o'clock", (hours == 12) ? 1 : (hours+1));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wantpm) {
|
|
|
|
strcat(retbuf, " in the ");
|
|
|
|
if (pm) {
|
|
|
|
strcat(retbuf, "afternoon");
|
|
|
|
} else {
|
|
|
|
strcat(retbuf, "morning");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *getweighttext(float weight, char *buf) {
|
|
|
|
if (weight >= 1) {
|
|
|
|
if ((int)weight == weight) { // ie. is weight an integer?
|
|
|
|
sprintf(buf, "%0.0f kg",weight);
|
|
|
|
} else {
|
|
|
|
sprintf(buf, "%0.1f kg",weight);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sprintf(buf, "%0.0f grams", weight * 1000);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
int isvowel (char c) {
|
|
|
|
switch (c) {
|
|
|
|
case 'a':
|
|
|
|
case 'e':
|
|
|
|
case 'i':
|
|
|
|
case 'o':
|
|
|
|
case 'u':
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocates and returns new string
|
|
|
|
char *makeplural(char *text) {
|
|
|
|
char lastlet;
|
2010-12-07 18:34:26 +11:00
|
|
|
char *newtext;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
newtext = strdup(text);
|
|
|
|
|
|
|
|
// scrolls
|
2011-02-01 06:16:13 +11:00
|
|
|
newtext = strrep(newtext, "berry ", "berries ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "block ", "blocks ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "can ", "cans ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "chunk ", "chunks ", &rv);
|
|
|
|
if (rv) return newtext;
|
2011-04-01 10:54:44 +11:00
|
|
|
newtext = strrep(newtext, "flask ", "flasks ", &rv);
|
|
|
|
if (rv) return newtext;
|
2011-02-01 06:16:13 +11:00
|
|
|
newtext = strrep(newtext, "gem ", "gems ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "loaf ", "loaves ", &rv);
|
2010-12-07 18:34:26 +11:00
|
|
|
if (rv) return newtext;
|
2011-02-01 06:16:13 +11:00
|
|
|
newtext = strrep(newtext, "lump ", "lumps ", &rv);
|
2010-12-07 18:34:26 +11:00
|
|
|
if (rv) return newtext;
|
2011-02-01 06:16:13 +11:00
|
|
|
newtext = strrep(newtext, "piece ", "pieces ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "pile ", "piles ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "pool ", "pools ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "potion ", "potions ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "puddle ", "puddles ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "ring ", "rings ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "scroll ", "scrolls ", &rv);
|
|
|
|
if (rv) return newtext;
|
2011-03-04 12:22:36 +11:00
|
|
|
newtext = strrep(newtext, "splash ", "splashes ", &rv);
|
|
|
|
if (rv) return newtext;
|
|
|
|
newtext = strrep(newtext, "suit ", "suits ", &rv);
|
|
|
|
if (rv) return newtext;
|
2011-02-01 06:16:13 +11:00
|
|
|
newtext = strrep(newtext, "vial ", "vials ", &rv);
|
2010-12-07 18:34:26 +11:00
|
|
|
if (rv) return newtext;
|
2010-12-02 12:17:54 +11:00
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
|
|
|
|
//
|
|
|
|
newtext = strrep(newtext, "pair ", "pairs ", &rv);
|
2010-12-07 18:34:26 +11:00
|
|
|
// don't return
|
|
|
|
|
|
|
|
// default
|
2010-12-02 12:17:54 +11:00
|
|
|
lastlet = text[strlen(text)-1];
|
|
|
|
switch (lastlet) {
|
2011-03-04 12:22:36 +11:00
|
|
|
case 'y': // change to 'ies'
|
|
|
|
text[strlen(text)-1] = '\0';
|
|
|
|
asprintf(&newtext, "%sies",text);
|
|
|
|
break;
|
2010-12-02 12:17:54 +11:00
|
|
|
case 's':
|
|
|
|
case 'o': // append "es"
|
|
|
|
asprintf(&newtext, "%ses",text);
|
|
|
|
break;
|
|
|
|
default: // append "s"
|
|
|
|
asprintf(&newtext, "%ss",text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return newtext;
|
|
|
|
}
|
2010-12-07 18:34:26 +11:00
|
|
|
|
2011-03-24 16:09:31 +11:00
|
|
|
int needses(char *text) {
|
|
|
|
if (text[strlen(text)-1] == 's') {
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(text) >= 2) {
|
|
|
|
if ((text[strlen(text)-2] == 'c') &&
|
|
|
|
(text[strlen(text)-1] == 'h')) {
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
char *noprefix(char *obname) {
|
|
|
|
char *p;
|
|
|
|
p = strchr(obname, ' ');
|
|
|
|
if (p) {
|
|
|
|
p++;
|
|
|
|
return p;
|
|
|
|
} else {
|
|
|
|
return obname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-16 15:45:46 +11:00
|
|
|
char *numtotext(int num, char *buf) {
|
|
|
|
switch (num) {
|
|
|
|
case 1:
|
|
|
|
sprintf(buf, "a");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
sprintf(buf, "two");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
sprintf(buf, "three");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
sprintf(buf, "four");
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
sprintf(buf, "five");
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
sprintf(buf, "six");
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
sprintf(buf, "seven");
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
sprintf(buf, "eight");
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
sprintf(buf, "nine");
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
sprintf(buf, "ten");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(buf, "%d",num);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert number to roman numerals
|
|
|
|
// only copes with 1-10
|
|
|
|
char *roman(int num) {
|
|
|
|
switch (num) {
|
|
|
|
case 1:
|
|
|
|
return "I";
|
|
|
|
case 2:
|
|
|
|
return "II";
|
|
|
|
case 3:
|
|
|
|
return "III";
|
|
|
|
case 4:
|
|
|
|
return "IV";
|
|
|
|
case 5:
|
|
|
|
return "V";
|
|
|
|
case 6:
|
|
|
|
return "VI";
|
|
|
|
case 7:
|
|
|
|
return "VII";
|
|
|
|
case 8:
|
|
|
|
return "VIII";
|
|
|
|
case 9:
|
|
|
|
return "IX";
|
|
|
|
case 10:
|
|
|
|
return "X";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
void splittime(int *hours, int *mins, int *secs) {
|
|
|
|
long left;
|
|
|
|
left = curtime;
|
|
|
|
|
|
|
|
*hours = left / 3600;
|
|
|
|
left -= (*hours * 3600);
|
|
|
|
*mins = left / 60;
|
|
|
|
left -= (*mins * 60);
|
|
|
|
*secs = left;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *strrep(char *text, char *oldtok, char *newtok, int *rv) {
|
2010-12-07 18:34:26 +11:00
|
|
|
char *temp;
|
2011-02-01 06:16:13 +11:00
|
|
|
temp = strdup(" "); // ooooooo is this bad??
|
|
|
|
dostrrep(text, &temp, oldtok, newtok, rv);
|
2010-12-07 18:34:26 +11:00
|
|
|
// swap
|
2011-02-01 06:16:13 +11:00
|
|
|
text = realloc(text, strlen(temp)+1); // extra space for NUL
|
2010-12-07 18:34:26 +11:00
|
|
|
strcpy(text, temp);
|
|
|
|
free(temp);
|
2011-02-01 06:16:13 +11:00
|
|
|
return text;
|
2010-12-07 18:34:26 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns TRUE if any replacements made
|
2011-02-01 06:16:13 +11:00
|
|
|
char *dostrrep(char* in, char** out, char* oldtok, char* newtok, int *rv) {
|
2010-12-07 18:34:26 +11:00
|
|
|
char *temp;
|
|
|
|
char *found = strstr(in, oldtok);
|
|
|
|
int idx;
|
|
|
|
if(!found) {
|
2011-02-01 06:16:13 +11:00
|
|
|
*out = realloc(*out, strlen(in) + 1); // oooooooo crashing in realloc
|
2010-12-07 18:34:26 +11:00
|
|
|
strcpy(*out, in);
|
2011-02-01 06:16:13 +11:00
|
|
|
|
|
|
|
if (rv) *rv = B_FALSE;
|
|
|
|
return *out;
|
2010-12-07 18:34:26 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
idx = found - in;
|
|
|
|
|
|
|
|
*out = realloc(*out, strlen(in) - strlen(oldtok) + strlen(newtok) + 1);
|
|
|
|
strncpy(*out, in, idx);
|
|
|
|
strcpy(*out + idx, newtok);
|
|
|
|
strcpy(*out + idx + strlen(newtok), in + idx + strlen(oldtok));
|
|
|
|
|
|
|
|
temp = malloc(idx+strlen(newtok)+1);
|
|
|
|
strncpy(temp,*out,idx+strlen(newtok));
|
|
|
|
temp[idx + strlen(newtok)] = '\0';
|
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
dostrrep(found + strlen(oldtok), out, oldtok, newtok, rv);
|
2010-12-07 18:34:26 +11:00
|
|
|
temp = realloc(temp, strlen(temp) + strlen(*out) + 1);
|
|
|
|
strcat(temp,*out);
|
|
|
|
free(*out);
|
|
|
|
*out = temp;
|
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
if (rv) *rv = B_TRUE;
|
|
|
|
return *out;
|
2010-12-07 18:34:26 +11:00
|
|
|
}
|
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
int strpixmatch(char *haystack, char *needle) {
|
|
|
|
int matched = B_FALSE;
|
|
|
|
char *hword, *nword, *hcont,*ncont;
|
2010-12-07 18:34:26 +11:00
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
if (strchr(needle, ' ') || strchr(haystack, ' ')) {
|
|
|
|
char lochaystack[BUFLEN], locneedle[BUFLEN];
|
|
|
|
strcpy(lochaystack, haystack);
|
|
|
|
strcpy(locneedle, needle);
|
|
|
|
|
|
|
|
// match word for word
|
|
|
|
nword = strtok_r(locneedle, " ", &ncont);
|
|
|
|
hword = strtok_r(lochaystack, " ", &hcont);
|
|
|
|
while (nword && hword) {
|
|
|
|
// all typed words must match
|
|
|
|
if (strcasestr(hword, nword)) {
|
|
|
|
matched = B_TRUE;
|
|
|
|
} else {
|
|
|
|
matched = B_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nword = strtok_r(NULL, " ", &ncont);
|
|
|
|
hword = strtok_r(NULL, " ", &hcont);
|
|
|
|
if (nword && !hword) {
|
|
|
|
matched = B_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (!matched && !strchr(needle, ' ')) {
|
|
|
|
// now try matching typed word against second word in spellname
|
|
|
|
strcpy(lochaystack, haystack);
|
|
|
|
hword = strtok_r(lochaystack, " ", &hcont);
|
|
|
|
while (hword) {
|
|
|
|
if (strcasestr(hword, needle)) {
|
|
|
|
matched = B_TRUE;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
matched = B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hword = strtok_r(NULL, " ", &hcont);
|
|
|
|
if (!hword) {
|
|
|
|
matched = B_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
if (strcasestr(haystack, needle)) {
|
|
|
|
matched = B_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matched;
|
|
|
|
}
|
|
|
|
|
2011-03-10 16:47:18 +11:00
|
|
|
int texttodice(char *text, int *ndice, int *nsides, int *bonus) {
|
|
|
|
char *dummy;
|
|
|
|
char *localtext;
|
2011-04-01 10:54:44 +11:00
|
|
|
char *p,*plusloc;
|
2011-03-10 16:47:18 +11:00
|
|
|
localtext = strdup(text);
|
|
|
|
// number of dice
|
|
|
|
p = strtok_r(localtext, "d", &dummy);
|
|
|
|
if (!p) {
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
if (ndice) {
|
|
|
|
*ndice = atoi(p);
|
|
|
|
}
|
|
|
|
// sides on each die
|
|
|
|
p = strtok_r(NULL, "d", &dummy);
|
|
|
|
if (!p) {
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
2011-04-01 10:54:44 +11:00
|
|
|
|
|
|
|
// strip out bonus
|
|
|
|
plusloc = strchr(p, '+');
|
|
|
|
if (plusloc) *plusloc = '\0';
|
|
|
|
plusloc = strchr(p, '-');
|
|
|
|
if (plusloc) *plusloc = '\0';
|
|
|
|
|
2011-03-10 16:47:18 +11:00
|
|
|
if (nsides) {
|
|
|
|
*nsides = atoi(p);
|
|
|
|
}
|
2011-04-01 10:54:44 +11:00
|
|
|
|
|
|
|
|
|
|
|
free(localtext);
|
|
|
|
localtext = strdup(text);
|
2011-03-10 16:47:18 +11:00
|
|
|
// bonus/plus
|
|
|
|
if (bonus) {
|
2011-04-01 10:54:44 +11:00
|
|
|
p = strchr(localtext, '+');
|
2011-03-10 16:47:18 +11:00
|
|
|
if (p) {
|
2011-04-01 10:54:44 +11:00
|
|
|
*bonus = atoi(p+1);
|
2011-03-10 16:47:18 +11:00
|
|
|
} else {
|
2011-04-01 10:54:44 +11:00
|
|
|
p = strchr(localtext, '-');
|
|
|
|
if (p) {
|
|
|
|
*bonus = -(atoi(p+1));
|
|
|
|
} else {
|
|
|
|
*bonus = 0;
|
|
|
|
}
|
2011-03-10 16:47:18 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(localtext);
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-03-22 18:06:28 +11:00
|
|
|
void texttospellopts(char *text, int *power, char *damstr, int *needgrab) {
|
|
|
|
char *p;
|
|
|
|
int n;
|
|
|
|
char *argname[] = {
|
|
|
|
"pw:",
|
|
|
|
"dam:",
|
|
|
|
"needgrab:",
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
void *argval[] = {
|
|
|
|
power,
|
|
|
|
damstr,
|
|
|
|
needgrab,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
char argtype[] = {
|
|
|
|
'i',
|
|
|
|
's',
|
|
|
|
'b',
|
|
|
|
'\0',
|
|
|
|
};
|
|
|
|
|
|
|
|
// defaults
|
|
|
|
if (power) *power = 0;
|
|
|
|
if (damstr) strcpy(damstr, "");
|
|
|
|
if (needgrab) *needgrab = B_FALSE;
|
|
|
|
|
2011-04-08 13:18:54 +10:00
|
|
|
if (!strlen(text)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-22 18:06:28 +11:00
|
|
|
// for each arg
|
|
|
|
for (n = 0; argname[n]; n++) {
|
|
|
|
// search for it in text...
|
|
|
|
for (p = text ; *p ; p++) {
|
|
|
|
if (!strncmp(p, argname[n], strlen(argname[n])) ) {
|
|
|
|
char localval[BUFLEN];
|
|
|
|
char *valfull;
|
|
|
|
|
|
|
|
strcpy(localval, p + strlen(argname[n]));
|
|
|
|
valfull = strtok(localval, ";");
|
|
|
|
if (valfull) {
|
|
|
|
if (argval[n]) {
|
|
|
|
if (argtype[n] == 'i') {
|
|
|
|
*((int *)argval[n]) = atoi(valfull);
|
|
|
|
} else if (argtype[n] == 'b') {
|
|
|
|
*((int *)argval[n]) = atoi(valfull) ? B_TRUE : B_FALSE;
|
|
|
|
} else if (argtype[n] == 's') {
|
|
|
|
strcpy((char *)argval[n], valfull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
char *you(lifeform_t *lf) {
|
|
|
|
if (isplayer(lf)) {
|
|
|
|
return "You";
|
|
|
|
}
|
|
|
|
return "It";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *you_l(lifeform_t *lf) {
|
|
|
|
if (isplayer(lf)) {
|
|
|
|
return "you";
|
|
|
|
}
|
|
|
|
return "it";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *your(lifeform_t *lf) {
|
|
|
|
if (isplayer(lf)) {
|
|
|
|
return "Your";
|
|
|
|
}
|
|
|
|
return "Its";
|
|
|
|
}
|
|
|
|
|
|
|
|
char *your_l(lifeform_t *lf) {
|
|
|
|
if (isplayer(lf)) {
|
|
|
|
return "your";
|
|
|
|
}
|
|
|
|
return "its";
|
|
|
|
}
|