static int compile(const char *filename) { char c; char tcmFilenameBuf[TCM_FILENAME_BUF_SIZE]; char *tcmFilename = tcmFilenameBuf; int tcmAllocated = 0; /* see if we need to free the memory */ char *p; FILE *fin; FILE *fout; int i = 0; int j, k; char line[MAX_LINE_SIZE] = {""}; /* reset counters */ mc = wc = tc = lc = oc = pc = cc = fc = ac = 0; if(hidden(filename)) { fprintf(stderr, "Warning: ignoring hidden file: '%s'\n", filename); return 1; } if(strlen(filename) + strlen(".tcm") + 1 > sizeof(tcmFilenameBuf)) { tcmAllocated = 1; tcmFilename = calloc(sizeof(char), strlen(filename) + strlen(".tcm") + 1); /* not enough room for tcm filename, so allocate more memory for it */ } strcpy(tcmFilename, filename); /* change .trm to .tcm or else append .tcm */ p = tcmFilename; while(*p) p++; if((p - tcmFilename) > strlen(".tcm") + 1 && *(p - 4) == '.' && *(p - 3) == 't' && *(p - 2) == 'r' && *(p - 1) == 'm') /* NOTE: strlen(...) _+ 1_ doesn't match ".tcm" exactly (we don't want to match hidden files) */ { /* filename ends in .trm; change tcmFilename to .tcm */ *(p - 2) = 'c'; } else { /* append .tcm */ *p++ = '.'; *p++ = 't'; *p++ = 'c'; *p++ = 'm'; *p++ = 0; } /* we have the filename for the input and ouput files, so open the streams */ /* first check we aren't overwriting anything undesirably */ fin = fopen(tcmFilename, "r"); if(fin) { fclose(fin); if(!m_force) { if(tcmAllocated) free(tcmFilename); fprintf(stderr, "Not overwriting file: '%s'. (Use -f to override.)\n", tcmFilename); return 1; } } if(!(fin = fopen(filename, "r"))) { if(tcmAllocated) free(tcmFilename); perror(NULL); fprintf(stderr, "Error opening file for reading: '%s'\n", filename); return 0; } /* read map and store all of map into memory */ while((c = fgetc(fin)) != EOF) { if(c == '\n') { if(i) { char entity[MAX_STRING_SIZE]; if(!read_reset(line)) { fprintf(stderr, "Error reading file: '%s'\n", filename); fclose(fin); return 0; } read_string(entity); if(strncmp(entity, "map", sizeof(entity)) == 0) { char name[MAX_STRING_SIZE]; char title[MAX_STRING_SIZE]; char description[MAX_STRING_SIZE]; char song[MAX_STRING_SIZE]; char authors[MAX_STRING_SIZE]; char version_s[MAX_STRING_SIZE]; int version; int staticCamera; char script[MAX_STRING_SIZE]; read_string(name); read_string(title); read_string(description); read_string(song); read_string(authors); read_string(version_s); version = read_int(); staticCamera = read_int(); read_string(script); add_map(name, title, description, song, authors, version_s, version, staticCamera, script); } else if(strncmp(entity, "wall", sizeof(entity)) == 0) { int quad; double x1, y1; double x2, y2; double x3, y3; double x4, y4; double tht; double tvt; double ths; double tvs; double tr; char texture[MAX_STRING_SIZE]; int level; char target[MAX_STRING_SIZE]; int path; int detail; int staticW; char misc[MAX_STRING_SIZE]; quad = read_int(); x1 = read_double(); y1 = read_double(); x2 = read_double(); y2 = read_double(); x3 = read_double(); y3 = read_double(); x4 = read_double(); y4 = read_double(); tht = read_double(); tvt = read_double(); ths = read_double(); tvs = read_double(); tr = read_double(); read_string(texture); level = read_int(); read_string(target); path = read_int(); detail = read_int(); staticW = read_int(); read_string(misc); add_wall(quad, x1, y1, x2, y2, x3, y3, x4, y4, tht, tvt, ths, tvs, tr, texture, level, target, path, detail, staticW, misc); } else if(strncmp(entity, "teleporter", sizeof(entity)) == 0) { char targetName[MAX_STRING_SIZE]; char target[MAX_STRING_SIZE]; double x1, y1; int enabled; char misc[MAX_STRING_SIZE]; read_string(targetName); read_string(target); x1 = read_double(); y1 = read_double(); enabled = read_int(); read_string(misc); add_teleporter(targetName, target, x1, y1, enabled, misc); } else if(strncmp(entity, "playerSpawnPoint", sizeof(entity)) == 0) { double x1, y1; char misc[MAX_STRING_SIZE]; x1 = read_double(); y1 = read_double(); read_string(misc); add_playerSpawnPoint(x1, y1, misc); } else if(strncmp(entity, "powerupSpawnPoint", sizeof(entity)) == 0) { double x1, y1; char powerupsToEnable[MAX_STRING_SIZE]; int linked; double repeat; double initial; int focus; char misc[MAX_STRING_SIZE]; x1 = read_double(); y1 = read_double(); read_string(powerupsToEnable); linked = read_int(); repeat = read_double(); initial = read_double(); focus = read_int(); read_string(misc); add_powerupSpawnPoint(x1, y1, powerupsToEnable, linked, repeat, initial, focus, misc); } else if(strncmp(entity, "path", sizeof(entity)) == 0) { char targetName[MAX_STRING_SIZE]; char target[MAX_STRING_SIZE]; double x1, y1; int enabled; double time; char misc[MAX_STRING_SIZE]; read_string(targetName); read_string(target); x1 = read_double(); y1 = read_double(); enabled = read_int(); time = read_double(); read_string(misc); add_path(targetName, target, x1, y1, enabled, time, misc); } else if(strncmp(entity, "controlPoint", sizeof(entity)) == 0) { double x1, y1; int red; char misc[MAX_STRING_SIZE]; x1 = read_double(); y1 = read_double(); red = read_int(); read_string(misc); add_controlPoint(x1, y1, red, misc); } else if(strncmp(entity, "flag", sizeof(entity)) == 0) { double x1, y1; int red; char misc[MAX_STRING_SIZE]; x1 = read_double(); y1 = read_double(); red = read_int(); read_string(misc); add_flag(x1, y1, red, misc); } else if(strncmp(entity, "wayPoint", sizeof(entity)) == 0) { double x1, y1; char misc[MAX_STRING_SIZE]; x1 = read_double(); y1 = read_double(); read_string(misc); add_wayPoint(x1, y1, misc); } else { fclose(fin); if(tcmAllocated) free(tcmFilename); fprintf(stderr, "Unknown entity when reading '%s': '%s'\n", filename, entity); return 0; } i = line[0] = 0; } } else { line[i++] = c; line[i] = 0; } } if(line[0]) { fprintf(stderr, "Warning: ignored trailing line missing a newline character while reading '%s'\n", filename); } fclose(fin); if(!(fout = fopen(tcmFilename, "wb"))) { if(tcmAllocated) free(tcmFilename); perror(NULL); fprintf(stderr, "Error opening file for writing: '%s'\n", tcmFilename); return 0; } /* header */ put_cchar(fout, 0x00); put_cchar(fout, 0x54); put_cchar(fout, 0x43); put_cchar(fout, 0x4D); put_cchar(fout, 0x01); put_cint(fout, MAGIC); put_cchar(fout, VERSION); put_str(fout, maps[0].name, 64); put_str(fout, maps[0].title, 64); put_str(fout, maps[0].description, 1024); put_str(fout, maps[0].song, 512); put_str(fout, maps[0].authors, 512); put_str(fout, maps[0].version_s, 64); put_cint(fout, maps[0].version); put_cchar(fout, maps[0].staticCamera); put_str(fout, maps[0].script, 64); put_cint(fout, wc); put_cint(fout, tc); put_cint(fout, lc); put_cint(fout, oc); put_cint(fout, pc); put_cint(fout, cc); put_cint(fout, fc); put_cint(fout, ac); for(i = 0; i < wc; i++) { int id = 0; vec2_t t[4]; wall_t *wall = &walls[i]; /* find the target (it might not exist) */ for(j = 0; j < pc; j++) { path_t *path = &paths[j]; if(strcmp(wall->target, path->targetName) == 0) { id = j; break; } } calculateTextureCoordinates(wall, t); put_cint(fout, i); put_cchar(fout, ((wall->quad) ? (1) : (0))); put_cdouble(fout, wall->x1); put_cdouble(fout, wall->y1); put_cdouble(fout, wall->x2); put_cdouble(fout, wall->y2); put_cdouble(fout, wall->x3); put_cdouble(fout, wall->y3); put_cdouble(fout, wall->x4); put_cdouble(fout, wall->y4); for(j = 0; j < 4; j++) { for(k = 0; k < 2; k++) { put_cdouble(fout, t[j][k]); } } put_str(fout, wall->texture, 256); put_cint(fout, wall->level); put_cint(fout, id); put_cchar(fout, ((wall->path) ? (1) : (0))); put_cchar(fout, ((wall->detail) ? (1) : (0))); put_cchar(fout, ((wall->staticW) ? (1) : (0))); put_str(fout, wall->misc, 512); } for(i = 0; i < tc; i++) { int id = 0; teleporter_t *teleporter = &teleporters[i]; /* find the target (it might not exist) */ for(j = 0; j < tc; j++) { teleporter_t *teleporter2 = &teleporters[j]; if(strcmp(teleporter->target, teleporter2->targetName) == 0) { id = j; break; } } put_cint(fout, i); put_cint(fout, id); put_cdouble(fout, teleporter->x1); put_cdouble(fout, teleporter->y1); put_cchar(fout, ((teleporter->enabled) ? (1) : (0))); put_str(fout, teleporter->misc, 512); } for(i = 0; i < lc; i++) { playerSpawnPoint_t *playerSpawnPoint = &playerSpawnPoints[i]; put_cint(fout, i); put_cdouble(fout, playerSpawnPoint->x1); put_cdouble(fout, playerSpawnPoint->y1); put_str(fout, playerSpawnPoint->misc, 512); } for(i = 0; i < oc; i++) { unsigned int powerups[16] = {0}; powerupSpawnPoint_t *powerupSpawnPoint = &powerupSpawnPoints[i]; if(strstr(powerupSpawnPoint->powerupsToEnable, "machinegun")) { powerups[0] |= 0x00000001; } if(strstr(powerupSpawnPoint->powerupsToEnable, "shotgun")) { powerups[0] |= 0x00000002; } if(strstr(powerupSpawnPoint->powerupsToEnable, "railgun")) { powerups[0] |= 0x00000004; } if(strstr(powerupSpawnPoint->powerupsToEnable, "coilgun")) { powerups[0] |= 0x00000008; } if(strstr(powerupSpawnPoint->powerupsToEnable, "saw")) { powerups[0] |= 0x00000010; } if(strstr(powerupSpawnPoint->powerupsToEnable, "ammo")) { powerups[0] |= 0x00000020; } if(strstr(powerupSpawnPoint->powerupsToEnable, "aim-aid")) { powerups[0] |= 0x00000040; } if(strstr(powerupSpawnPoint->powerupsToEnable, "health")) { powerups[0] |= 0x00000080; } if(strstr(powerupSpawnPoint->powerupsToEnable, "acceleration")) { powerups[0] |= 0x00000100; } if(strstr(powerupSpawnPoint->powerupsToEnable, "shield")) { powerups[0] |= 0x00000200; } if(strstr(powerupSpawnPoint->powerupsToEnable, "rocket-launcher")) { powerups[0] |= 0x00000400; } if(strstr(powerupSpawnPoint->powerupsToEnable, "laser-gun")) { powerups[0] |= 0x00000800; } if(strstr(powerupSpawnPoint->powerupsToEnable, "plasma-gun")) { powerups[0] |= 0x00001000; } put_cint(fout, i); put_cdouble(fout, powerupSpawnPoint->x1); put_cdouble(fout, powerupSpawnPoint->y1); for(j = 0; j < sizeof(powerups) / sizeof(powerups[0]); j++) { put_cint(fout, powerups[j]); } put_cchar(fout, powerupSpawnPoint->linked); put_cdouble(fout, powerupSpawnPoint->repeat); put_cdouble(fout, powerupSpawnPoint->initial); put_cchar(fout, powerupSpawnPoint->focus); put_str(fout, powerupSpawnPoint->misc, 512); } for(i = 0; i < pc; i++) { int id = 0; path_t *path = &paths[i]; /* find the target (it might not exist) */ for(j = 0; j < pc; j++) { path_t *path2 = &paths[j]; if(strcmp(path->target, path2->targetName) == 0) { id = j; break; } } put_cint(fout, i); put_cdouble(fout, path->x1); put_cdouble(fout, path->y1); put_cchar(fout, ((path->enabled) ? (1) : (0))); put_cdouble(fout, path->time); put_cint(fout, id); put_str(fout, path->misc, 512); } for(i = 0; i < cc; i++) { controlPoint_t *controlPoint = &controlPoints[i]; put_cint(fout, i); put_cdouble(fout, controlPoint->x1); put_cdouble(fout, controlPoint->y1); put_cchar(fout, ((controlPoint->red) ? (1) : (0))); put_str(fout, controlPoint->misc, 512); } for(i = 0; i < fc; i++) { flag_t *flag = &flags[i]; put_cint(fout, i); put_cdouble(fout, flag->x1); put_cdouble(fout, flag->y1); put_cchar(fout, ((flag->red) ? (1) : (0))); put_str(fout, flag->misc, 512); } for(i = 0; i < ac; i++) { wayPoint_t *wayPoint = &wayPoints[i]; put_cint(fout, i); put_cdouble(fout, wayPoint->x1); put_cdouble(fout, wayPoint->y1); put_str(fout, wayPoint->misc, 512); } fclose(fout); if(tcmAllocated) free(tcmFilename); return 1; }
void fdc_pll_t::reset(const attotime &when) { read_reset(when); write_position = 0; write_start_time = attotime::never; }