<commit_before>/*See LICENSE file for copyright and license details.*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_scancode.h>
#include <SDL_image.h>
#include "bool.h"
#include "list.h"
#include "math.h"
#include "mutant3d.h"
#include "misc.h"
#include "md5.h"
#include "obj.h"
#include "gl.h"
#include "path.h"

float rotate_x = 45.0f;
float rotate_z = 180.0f;
const float rotations_per_tick = 1.5;
V3f map_pos = {0, 0, 0};
float zoom = 100.0f;
bool done = false;
V3i active_block_pos = {0, 0, 0};

typedef enum {
  M_NORMAL,
  M_SET_WALLS,
  M_SET_HEIGHTS,
  M_COUNT
} Mode;

Mode mode = M_NORMAL;

#define BLOCK_SIZE 1.0f

GLfloat LightAmbient[4] = {0.1f, 0.1f, 0.1f, 0.2f};
GLfloat LightDiffuse[4] = {0.5, 0.5, 0.5, 0.5};
GLfloat LightPosition[4] = {
  BLOCK_SIZE * (MAP_X / 2.0),
  BLOCK_SIZE * (MAP_Y / 2.0),
  BLOCK_SIZE * MAP_Z,
  1.0};

Block3 *map[MAP_Z][MAP_Y][MAP_X];

float *map_verts = NULL; /*ground*/
float *pick_verts = NULL;
float *walls_verts = NULL;
float *obj_verts = NULL;
float *path_verts = NULL;
int map_verts_count = 0;
int pick_verts_count = 0;
int walls_verts_count = 0;
int obj_verts_count = 0;
int path_verts_count = 0;

float *map_tex_coord = NULL;
float *wall_tex_coord = NULL;
float *obj_tex_coord = NULL;

GLubyte *pick_colors = NULL;

bool enabled_levels[20] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

Md5_model m;
Md5_anim anim;

Obj_model obj_m;
GLuint obj_tex;

GLuint floor_texture;
GLuint wall_texture;

static SDL_GLContext context;
SDL_Window *win = NULL;

/*Program segfaults if set this to {0, 0}*/
V2i mouse_pos = {1, 1};

/*TODO: remove me*/
void build_map_array(void);
void build_walls_array(void);
void build_path_array(void);
bool pick_block(V3i *block);
void build_picking_blocks_array(void);

bool inboard(V3i p){
  return p.x >= 0 && p.y >= 0 && p.z >= 0
      && p.x < MAP_X && p.y < MAP_Y && p.z < MAP_Z;
}

Block3 *block(V3i p){
  assert(inboard(p));
  return map[p.z][p.y][p.x];
}

/*TODO check if unit can stand here (enough vertical space)*/
bool is_block_walkable(V3i pos){
  Block3 *b;
  if(!inboard(pos))
    return false;
  b = block(pos);
  if(!b)
    return false;
  return b->t == B_FLOOR;
}

bool check_height_diff(V3i p1, V3i p2, int max_diff){
  Block3 *b1;
  Block3 *b2;
  int h1, h2;
  if(!inboard(p1) || !inboard(p2))
    return false;
  b1 = block(p1);
  b2 = block(p2);
  if(!b1 || !b2)
    return false;
  h1 = (p1.z * BLOCK_HEIGHT) + b1->h;
  h2 = (p2.z * BLOCK_HEIGHT) + b2->h;
  return abs(h1 - h2) <= max_diff;
}

/*TODO стена должна отображаться сразу у двух клеток.*/
static bool check_wall(V3i a_pos, V3i b_pos){
  bool *a;
  bool *b;
  Dir d;
  {
    int dx = b_pos.x - a_pos.x;
    int dy = b_pos.y - a_pos.y;
    if(dx > 1) dx = 1;
    if(dx < -1) dx = -1;
    if(dy > 1) dy = 1;
    if(dy < -1) dy = -1;
    a_pos.x = b_pos.x - dx;
    a_pos.y = b_pos.y - dy;
  }
  a = block(a_pos)->walls;
  b = block(b_pos)->walls;
  d = m2dir(a_pos, b_pos);
  if(d == D_ERROR)
    exit(0);
#if 0
  if(d == D_F && (a[0] || b[1] || b[2])) return false;
  if(d == D_R && (a[1] || b[0] || b[3])) return false;
  if(d == D_FR && (a[0] || a[1] || b[2] || b[3])) return false;
#else
  if(d == D_F && (a[0] || b[1] || b[2])) return false;
  if(d == D_R && (a[1] || a[0] || b[3])) return false;
  if(d == D_FR && (a[0] || a[1] || b[2] || b[3])) return false;
#endif
  return true;
}

bool check_xxx(V3i orig_pos, V3i pos, int height){
  return check_height_diff(orig_pos, pos, height)
      && is_block_walkable(pos)
      && check_wall(orig_pos, pos);
}

/*TODO:
  Проверять разницу в высоте не с начальным блоком,
  а с прилегающими!*/
int calc_block_clearence(V3i p, int max_size){
  int i, j;
  int h = MAX_HEIGHT_DIFF;
  assert(inboard(p));<commit_msg>mutant3d.c: check_wall(): Removed commented-out code.<commit_after>/*See LICENSE file for copyright and license details.*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_scancode.h>
#include <SDL_image.h>
#include "bool.h"
#include "list.h"
#include "math.h"
#include "mutant3d.h"
#include "misc.h"
#include "md5.h"
#include "obj.h"
#include "gl.h"
#include "path.h"

float rotate_x = 45.0f;
float rotate_z = 180.0f;
const float rotations_per_tick = 1.5;
V3f map_pos = {0, 0, 0};
float zoom = 100.0f;
bool done = false;
V3i active_block_pos = {0, 0, 0};

typedef enum {
  M_NORMAL,
  M_SET_WALLS,
  M_SET_HEIGHTS,
  M_COUNT
} Mode;

Mode mode = M_NORMAL;

#define BLOCK_SIZE 1.0f

GLfloat LightAmbient[4] = {0.1f, 0.1f, 0.1f, 0.2f};
GLfloat LightDiffuse[4] = {0.5, 0.5, 0.5, 0.5};
GLfloat LightPosition[4] = {
  BLOCK_SIZE * (MAP_X / 2.0),
  BLOCK_SIZE * (MAP_Y / 2.0),
  BLOCK_SIZE * MAP_Z,
  1.0};

Block3 *map[MAP_Z][MAP_Y][MAP_X];

float *map_verts = NULL; /*ground*/
float *pick_verts = NULL;
float *walls_verts = NULL;
float *obj_verts = NULL;
float *path_verts = NULL;
int map_verts_count = 0;
int pick_verts_count = 0;
int walls_verts_count = 0;
int obj_verts_count = 0;
int path_verts_count = 0;

float *map_tex_coord = NULL;
float *wall_tex_coord = NULL;
float *obj_tex_coord = NULL;

GLubyte *pick_colors = NULL;

bool enabled_levels[20] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

Md5_model m;
Md5_anim anim;

Obj_model obj_m;
GLuint obj_tex;

GLuint floor_texture;
GLuint wall_texture;

static SDL_GLContext context;
SDL_Window *win = NULL;

/*Program segfaults if set this to {0, 0}*/
V2i mouse_pos = {1, 1};

/*TODO: remove me*/
void build_map_array(void);
void build_walls_array(void);
void build_path_array(void);
bool pick_block(V3i *block);
void build_picking_blocks_array(void);

bool inboard(V3i p){
  return p.x >= 0 && p.y >= 0 && p.z >= 0
      && p.x < MAP_X && p.y < MAP_Y && p.z < MAP_Z;
}

Block3 *block(V3i p){
  assert(inboard(p));
  return map[p.z][p.y][p.x];
}

/*TODO check if unit can stand here (enough vertical space)*/
bool is_block_walkable(V3i pos){
  Block3 *b;
  if(!inboard(pos))
    return false;
  b = block(pos);
  if(!b)
    return false;
  return b->t == B_FLOOR;
}

bool check_height_diff(V3i p1, V3i p2, int max_diff){
  Block3 *b1;
  Block3 *b2;
  int h1, h2;
  if(!inboard(p1) || !inboard(p2))
    return false;
  b1 = block(p1);
  b2 = block(p2);
  if(!b1 || !b2)
    return false;
  h1 = (p1.z * BLOCK_HEIGHT) + b1->h;
  h2 = (p2.z * BLOCK_HEIGHT) + b2->h;
  return abs(h1 - h2) <= max_diff;
}

/*TODO стена должна отображаться сразу у двух клеток.*/
static bool check_wall(V3i a_pos, V3i b_pos){
  bool *a;
  bool *b;
  Dir d;
  {
    int dx = b_pos.x - a_pos.x;
    int dy = b_pos.y - a_pos.y;
    if(dx > 1) dx = 1;
    if(dx < -1) dx = -1;
    if(dy > 1) dy = 1;
    if(dy < -1) dy = -1;
    a_pos.x = b_pos.x - dx;
    a_pos.y = b_pos.y - dy;
  }
  a = block(a_pos)->walls;
  b = block(b_pos)->walls;
  d = m2dir(a_pos, b_pos);
  if(d == D_ERROR)
    exit(0);
  if(d == D_F && (a[0] || b[1] || b[2])) return false;
  if(d == D_R && (a[1] || a[0] || b[3])) return false;
  if(d == D_FR && (a[0] || a[1] || b[2] || b[3])) return false;
  return true;
}

bool check_xxx(V3i orig_pos, V3i pos, int height){
  return check_height_diff(orig_pos, pos, height)
      && is_block_walkable(pos)
      && check_wall(orig_pos, pos);
}

/*TODO:
  Проверять разницу в высоте не с начальным блоком,
  а с прилегающими!*/
int calc_block_clearence(V3i p, int max_size){
  int i, j;
  int h = MAX_HEIGHT_DIFF;
  assert(inboard(p));
{'fraction_non_alphanumeric': 0.1699667774086379, 'fraction_numerical': 0.037475083056478405, 'mean_word_length': 3.603058103975535, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2579321', 'n_tokens_mistral': 3571, 'n_tokens_neox': 3449, 'n_words': 863}