Spawn fighters offscreen or off map.
This commit is contained in:
parent
c66b734e7e
commit
3bd78dbd20
|
@ -99,6 +99,42 @@ Entity *spawnFighter(char *name, int x, int y, int side)
|
|||
return e;
|
||||
}
|
||||
|
||||
void spawnScriptFighter(char *fighterTypes, char *sideStr, int num, char *location)
|
||||
{
|
||||
Entity *e;
|
||||
int i, numTypes, side, offscreen;
|
||||
char **types, *type;
|
||||
|
||||
types = toTypeArray(fighterTypes, &numTypes);
|
||||
side = lookup(sideStr);
|
||||
offscreen = strcmp(location, "OFFSCREEN") == 0;
|
||||
|
||||
for (i = 0 ; i < num ; i++)
|
||||
{
|
||||
type = types[rand() % numTypes];
|
||||
|
||||
e = spawnFighter(type, 0, 0, side);
|
||||
|
||||
if (offscreen)
|
||||
{
|
||||
e->x = player->x;
|
||||
e->y = player->y;
|
||||
}
|
||||
else
|
||||
{
|
||||
e->x = rand() % 2 ? 0 : BATTLE_AREA_WIDTH;
|
||||
e->y = rand() % 2 ? 0 : BATTLE_AREA_HEIGHT;
|
||||
}
|
||||
|
||||
e->x += (rand() % 2) ? -SCREEN_WIDTH : SCREEN_WIDTH;
|
||||
e->y += (rand() % 2) ? -SCREEN_HEIGHT : SCREEN_HEIGHT;
|
||||
|
||||
e->aiFlags |= AIF_UNLIMITED_RANGE;
|
||||
}
|
||||
|
||||
free(types);
|
||||
}
|
||||
|
||||
static void randomizeDart(Entity *dart)
|
||||
{
|
||||
char texture[MAX_DESCRIPTION_LENGTH];
|
||||
|
|
|
@ -47,6 +47,7 @@ extern void addDebris(int x, int y, int amount);
|
|||
extern char **getFileList(char *dir, int *count);
|
||||
extern char *getTranslatedString(char *string);
|
||||
extern int getJSONValue(cJSON *node, char *name, int defValue);
|
||||
extern char **toTypeArray(char *types, int *numTypes);
|
||||
|
||||
extern App app;
|
||||
extern Battle battle;
|
||||
|
|
|
@ -73,6 +73,38 @@ void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy)
|
|||
*dy /= steps;
|
||||
}
|
||||
|
||||
char **toTypeArray(char *types, int *numTypes)
|
||||
{
|
||||
int i;
|
||||
char **typeArray, *type;
|
||||
|
||||
*numTypes = 1;
|
||||
|
||||
for (i = 0 ; i < strlen(types) ; i++)
|
||||
{
|
||||
if (types[i] == ';')
|
||||
{
|
||||
*numTypes = *numTypes + 1;
|
||||
}
|
||||
}
|
||||
|
||||
typeArray = malloc(*numTypes * sizeof(char*));
|
||||
|
||||
i = 0;
|
||||
type = strtok(types, ";");
|
||||
while (type)
|
||||
{
|
||||
typeArray[i] = malloc(strlen(type) + 1);
|
||||
strcpy(typeArray[i], type);
|
||||
|
||||
type = strtok(NULL, ";");
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return typeArray;
|
||||
}
|
||||
|
||||
char *timeToString(long millis, int showHours)
|
||||
{
|
||||
static char TIME[MAX_NAME_LENGTH];
|
||||
|
|
Loading…
Reference in New Issue