void add_wall_loop(NODE *node, VECTOR p[], int n, int flag) { int i; for(i = 0; i < n - 1; i++) add_wall(node, p[i], p[i + 1]); if(flag) add_wall(node, p[i], p[0]); }
void reset_world(world* game_world) { reset_player(game_world->width / 2, game_world->height / 2, game_world->game_player); game_world->num_walls = 0; for (int i = 0; i < game_world->width; i++) { add_wall(i, 0, game_world); add_wall(i, game_world->height - 1, game_world); } for (int i = 0; i < game_world->height; i++) { add_wall(0, i, game_world); add_wall(game_world->width - 1, i, game_world); } random_inbounds_pos(game_world, game_world->pellet->pos); }
void compile_map(NODE *node, LINE_LOOP *loop, int t) { int i, j; for(j = 0; j < t; j++) { if(loop[j].n > 4 && !loop[j].closed) { int pn = loop[j].n / 2; add_wall_loop(node, loop[j].point, pn, loop[j].closed); for(i = 0; i < pn - 1; i++) add_wall(node, loop[j].point[i + pn], loop[j].point[i + pn + 1]); add_wall(node, loop[j].point[0], loop[j].point[pn]); add_wall(node, loop[j].point[pn - 1], loop[j].point[pn + pn - 1]); } if(loop[j].n > 2 && loop[j].closed) { int pn = loop[j].n; add_wall_loop(node, loop[j].point, loop[j].n, loop[j].closed); } if(loop[j].n == 4 && !loop[j].closed) { add_wall(node, loop[j].point[0], loop[j].point[1]); add_wall(node, loop[j].point[2], loop[j].point[3]); add_wall(node, loop[j].point[0], loop[j].point[2]); add_wall(node, loop[j].point[1], loop[j].point[3]); } } }
void LightCaster::compute_light_mesh(Mesh* result, Walls* walls, const Vector_& light) { long nwalls = walls->nwalls(); angle = restrict_angle(angle); WallPoint* wall_points = (WallPoint*)GIGGLE->renderer->alloc(sizeof(WallPoint) * nwalls * 2); Wall** open_set = (Wall**)GIGGLE->renderer->alloc(sizeof(Wall*) * nwalls); long nopen_set = 0; for(long ii = 0; ii < nwalls; ++ii) { Wall* wall = &walls->walls[ii]; float angle_start = atan2f(wall->start.y - light.y, wall->start.x - light.x); float angle_end = atan2f(wall->end.y - light.y, wall->end.x - light.x); float dangle = restrict_angle(angle_end - angle_start); long idx1 = 2*ii; long idx2 = idx1 + 1; wall_points[idx1].point = &wall->start; wall_points[idx1].wall = wall; wall_points[idx1].angle = angle_start; wall_points[idx1].begin = dangle > 0; wall_points[idx2].point = &wall->end; wall_points[idx2].wall = wall; wall_points[idx2].angle = angle_end; wall_points[idx2].begin = !wall_points[idx1].begin; } std::sort(wall_points, wall_points + (nwalls*2), WallPointCompare()); float beginAngle = 0; for(int kk = 0; kk < 2; ++kk) { for(long ii = 0; ii < nwalls * 2; ++ii) { WallPoint* wp = &wall_points[ii]; Wall* last_closest = (nopen_set == 0) ? NULL : open_set[0]; if(wp->begin) { add_wall(open_set, &nopen_set, wp->wall, &light); } else { remove_wall(open_set, &nopen_set, wp->wall); } Wall* next_closest = (nopen_set == 0) ? NULL : open_set[0]; if(last_closest != next_closest) { float nextAngle = wp->angle; if(last_closest) { if(kk == 1) { add_triangle(result, light, last_closest, beginAngle, nextAngle); } beginAngle = nextAngle; } } } } }
//--------------------------------------------------------------------- // Add a wall to markedside int wall_add_to_markedside(sbyte type) { int Connectside; segment *csegp; if (add_wall(Markedsegp, Markedside)) { int wall_num, cwall_num; csegp = &Segments[Markedsegp->children[Markedside]]; Connectside = find_connect_side(Markedsegp, csegp); wall_num = Markedsegp->sides[Markedside].wall_num; cwall_num = csegp->sides[Connectside].wall_num; Walls[wall_num].segnum = Markedsegp-Segments; Walls[cwall_num].segnum = csegp-Segments; Walls[wall_num].sidenum = Markedside; Walls[cwall_num].sidenum = Connectside; Walls[wall_num].flags = 0; Walls[cwall_num].flags = 0; Walls[wall_num].type = type; Walls[cwall_num].type = type; Walls[wall_num].trigger = -1; Walls[cwall_num].trigger = -1; Walls[wall_num].clip_num = -1; Walls[cwall_num].clip_num = -1; Walls[wall_num].keys = KEY_NONE; Walls[cwall_num].keys = KEY_NONE; if (type == WALL_BLASTABLE) { Walls[wall_num].hps = WALL_HPS; Walls[cwall_num].hps = WALL_HPS; Walls[wall_num].clip_num = 0; Walls[cwall_num].clip_num = 0; } if (type != WALL_DOOR) { Markedsegp->sides[Markedside].tmap_num2 = 0; csegp->sides[Connectside].tmap_num2 = 0; } Update_flags |= UF_WORLD_CHANGED; return 1; } else { editor_status( "Cannot add wall here, no children" ); return 0; } }
static void test_add_wall(void ** state) { Board b = init_board1(); int nWalls = b.nSize; int nb_snakes = 0; Serpent** snakes = malloc(nb_snakes * sizeof(Serpent*)); add_wall(&b, snakes, nb_snakes); assert_int_equal(b.nSize, nWalls+1); free_board(b); free_snakes(snakes, nb_snakes); }
static DskJsonValue * create_user_update (User *user) { Game *game = user->base.game; /* width/height in various units, rounded up */ unsigned tile_width = (user->width + TILE_SIZE - 1) / TILE_SIZE; unsigned tile_height = (user->height + TILE_SIZE - 1) / TILE_SIZE; unsigned cell_width = (tile_width + CELL_SIZE * 2 - 2) / CELL_SIZE; unsigned cell_height = (tile_height + CELL_SIZE * 2 - 2) / CELL_SIZE; /* left/upper corner, rounded down */ int min_tile_x = user->base.x - (tile_width+1) / 2; int min_tile_y = user->base.y - (tile_height+1) / 2; int min_cell_x = int_div (min_tile_x, CELL_SIZE); int min_cell_y = int_div (min_tile_y, CELL_SIZE); unsigned alloced = 16; DskJsonValue **elements = dsk_malloc (sizeof (DskJsonValue *) * alloced); unsigned n_elements = 0; unsigned x, y; for (x = 0; x < cell_width; x++) for (y = 0; y < cell_height; y++) { int ucx = x + min_cell_x; /* un-wrapped x, y */ int ucy = y + min_cell_y; int px = (ucx * CELL_SIZE - user->base.x) * TILE_SIZE + user->width / 2 - TILE_SIZE / 2; int py = (ucy * CELL_SIZE - user->base.y) * TILE_SIZE + user->height / 2 - TILE_SIZE / 2; unsigned cx, cy; Cell *cell; /* deal with wrapping (or not) */ if (ucx < 0) { if (!game->wrap) continue; cx = ucx + game->universe_width; } else if ((unsigned) ucx >= game->universe_width) { cx = ucx; if (game->wrap) cx -= game->universe_width; } else cx = ucx; if (ucy < 0) { if (!game->wrap) continue; cy = ucy + game->universe_height; } else if ((unsigned) ucy >= game->universe_height) { cy = ucy; if (game->wrap) cy -= game->universe_height; } else cy = ucy; /* render walls */ if (cy < game->universe_height && cx <= game->universe_width && game->v_walls[cx + cy * game->universe_width]) { /* render vertical wall */ add_wall (&n_elements, &elements, &alloced, px, py, TILE_SIZE, TILE_SIZE * (CELL_SIZE+1)); } if (cy <= game->universe_height && cx < game->universe_width && game->h_walls[cx + cy * game->universe_width]) { /* render horizontal wall */ add_wall (&n_elements, &elements, &alloced, px, py, TILE_SIZE * (CELL_SIZE+1), TILE_SIZE); } if (cx >= game->universe_width || cy >= game->universe_height) continue; cell = game->cells + (game->universe_width * cy + cx); /* render bullets */ Object *object; for (object = cell->objects[OBJECT_TYPE_BULLET]; object; object = object->next_in_cell) { int bx = px + (object->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; int by = py + (object->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; add_bullet (&n_elements, &elements, &alloced, bx, by); } /* render dudes */ for (object = cell->objects[OBJECT_TYPE_USER]; object; object = object->next_in_cell) { int bx = px + (object->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; int by = py + (object->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; add_user (&n_elements, &elements, &alloced, bx, by, user == (User*) object); } /* render bad guys */ for (object = cell->objects[OBJECT_TYPE_ENEMY]; object; object = object->next_in_cell) { int bx = px + (object->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; int by = py + (object->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; add_enemy (&n_elements, &elements, &alloced, bx, by); } /* render generators */ if (cell->generator) { int bx = px + (cell->generator->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE; int by = py + (cell->generator->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE; add_generator (&n_elements, &elements, &alloced, bx, by, user->base.game->latest_update); } } DskJsonValue *rv; rv = dsk_json_value_new_array (n_elements, elements); dsk_free (elements); user->last_update = game->latest_update; return rv; }
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; }
//--------------------------------------------------------------------- // Add a wall to curside int wall_add_to_side(segment *segp, int side, sbyte type) { int connectside; segment *csegp; if (add_wall(segp, side)) { csegp = &Segments[segp->children[side]]; connectside = find_connect_side(segp, csegp); Walls[segp->sides[side].wall_num].segnum = segp-Segments; Walls[csegp->sides[connectside].wall_num].segnum = csegp-Segments; Walls[segp->sides[side].wall_num].sidenum = side; Walls[csegp->sides[connectside].wall_num].sidenum = connectside; Walls[segp->sides[side].wall_num].flags = 0; Walls[csegp->sides[connectside].wall_num].flags = 0; Walls[segp->sides[side].wall_num].type = type; Walls[csegp->sides[connectside].wall_num].type = type; // Walls[segp->sides[side].wall_num].trigger = -1; // Walls[csegp->sides[connectside].wall_num].trigger = -1; Walls[segp->sides[side].wall_num].clip_num = -1; Walls[csegp->sides[connectside].wall_num].clip_num = -1; Walls[segp->sides[side].wall_num].keys = KEY_NONE; Walls[csegp->sides[connectside].wall_num].keys = KEY_NONE; if (type == WALL_BLASTABLE) { Walls[segp->sides[side].wall_num].hps = WALL_HPS; Walls[csegp->sides[connectside].wall_num].hps = WALL_HPS; //Walls[segp->sides[side].wall_num].clip_num = 0; //Walls[csegp->sides[connectside].wall_num].clip_num = 0; } if (type != WALL_DOOR) { segp->sides[side].tmap_num2 = 0; csegp->sides[connectside].tmap_num2 = 0; } if (type == WALL_DOOR) { Walls[segp->sides[side].wall_num].flags |= WALL_DOOR_AUTO; Walls[csegp->sides[connectside].wall_num].flags |= WALL_DOOR_AUTO; Walls[segp->sides[side].wall_num].clip_num = Current_door_type; Walls[csegp->sides[connectside].wall_num].clip_num = Current_door_type; } //Update_flags |= UF_WORLD_CHANGED; //return 1; // return NextWall(); //assign a clip num return wall_assign_door(Current_door_type); } else { editor_status( "Cannot add wall here, no children" ); return 0; } }
void parse_wall(FILE *fp, World *w) { Wall wall; char texture_name[STRING_TOKEN_MAX_LENGTH]; int texture_index; int front_region, back_region; int vertex1, vertex2; fixed wall_length; /* vertices */ if (get_integer_token(fp, &vertex1) != Token_integer) parse_error("integer expected"); if (get_integer_token(fp, &vertex2) != Token_integer) parse_error("integer expected"); if (vertex1 < 0 || vertex1 > TABLE_SIZE(w->vertices)) parse_error("invalid vertex number"); if (vertex2 < 0 || vertex2 > TABLE_SIZE(w->vertices)) parse_error("invalid vertex number"); wall.vertex1 = &WORLD_VERTEX(w, vertex1); wall.vertex2 = &WORLD_VERTEX(w, vertex2); /* texture */ if (get_string_token(fp, texture_name) != Token_string) parse_error("texture name expected"); texture_index = get_texture_index(texture_name); if (texture_index < 0 || texture_index > TABLE_SIZE(w->textures)) parse_error("non-existent texture"); else wall.surface_texture = WORLD_TEXTURE(w, texture_index); if (strcmp(texture_name, "sky") == 0) wall.sky = True; else wall.sky = False; /* front and back regions */ if (get_integer_token(fp, &front_region) != Token_integer) fatal_error("non-existent region"); if (get_integer_token(fp, &back_region) != Token_integer) fatal_error("non-existent region"); if (front_region < 0 || front_region > TABLE_SIZE(w->regions)) fatal_error("non-existent region"); if (back_region < 0 || back_region > TABLE_SIZE(w->regions)) fatal_error("non-existent region"); wall.front = &WORLD_REGION(w, front_region); wall.back = &WORLD_REGION(w, back_region); /* Texture phase and scale. This code is somewhat more complicated than ** you'd expect, since the texture scale must be normalized to the ** wall length. */ if (get_real_token(fp, &wall.xscale) != Token_real) parse_error("number expected"); if (get_real_token(fp, &wall.yscale) != Token_real) parse_error("number expected"); if (get_real_token(fp, &wall.xphase) != Token_real) parse_error("number expected"); if (get_real_token(fp, &wall.yphase) != Token_real) parse_error("number expected"); wall_length = FLOAT_TO_FIXED(sqrt(FIXED_TO_FLOAT(wall.vertex2->x - wall.vertex1->x) * FIXED_TO_FLOAT(wall.vertex2->x - wall.vertex1->x) + FIXED_TO_FLOAT(wall.vertex2->y - wall.vertex1->y) * FIXED_TO_FLOAT(wall.vertex2->y - wall.vertex1->y))); wall.yscale = fixmul(wall.yscale, INT_TO_FIXED(wall.surface_texture->height)); wall.xscale = fixmul(fixmul(wall.xscale, INT_TO_FIXED(wall.surface_texture->width)), wall_length); add_wall(w, &wall); }