Exemple #1
0
void		*malloc(size_t size)
{
	void	*ptr;

	size = 0 ? 1 : size;
	if (!g_map.tiny && !g_map.small && !g_map.large)
		init_glob();
	if (size + sizeof(t_header) > g_map.max_size || size > g_map.max_size)
		return (NULL);
	size += sizeof(t_block);
	if (size - sizeof(t_block) <= g_map.size_tiny)
	{
		if (!g_map.tiny && new_map(g_map.size_tiny, &g_map.tiny, NULL) < 0)
			return (NULL);
		ptr = find_free_space(g_map.size_tiny, size, &g_map.tiny);
	}
	else if (size - sizeof(t_block) <= g_map.size_small)
	{
		if (!g_map.small && new_map(g_map.size_small, &g_map.small, NULL) < 0)
			return (NULL);
		ptr = find_free_space(g_map.size_small, size, &g_map.small);
	}
	else
		ptr = large_alloc(size, &g_map.large);
	if (ptr)
		ptr = (void *)ptr + sizeof(t_block);
	return (ptr);
}
Exemple #2
0
void init_maps() {
    //map used for save the state of a transation
    map_session_smpp = new_map(free_uint32, NULL, compare_uint32, free_smpp_session, NULL, NULL);
    map_session_sip  = new_map(free_string, NULL, compare_string, free_sip_session,  NULL, NULL);
    //map used for save all sm in transation in memory
    map_sm           = new_map(free_uint32, NULL, compare_uint32, free_sm_data, NULL, NULL);
    //map used for sar msg
    map_sar_msg      = new_map(free_uint16, NULL, compare_uint16, free_tab_string, NULL, NULL);
}
Exemple #3
0
int			main(int argc, char **argv)
{
	int		fd;
	t_env	e;

	if (argc == 2)
	{
		if ((fd = new_map(argv[1])) == 0)
			return (0);
		if (get_map(fd, &e) == 1)
		{
			ft_putendl_fd("Error loading the map.", 2);
			return (0);
		}
		if (close(fd) != 0)
		{
			ft_putendl_fd("Error closing the file.", 2);
			return (0);
		}
		if (fdf(&e, argv[1]) == 1)
			ft_putendl_fd("fdf Error.", 2);
	}
	else
		ft_putendl_fd("Enter only one valid map.", 2);
	return (0);
}
Exemple #4
0
//-----------------------------------------------------------------------------
// name: Temp_layer_map( )
// desc: ...
//-----------------------------------------------------------------------------
Temp_Map Temp_layer_map( Temp_Map over, Temp_Map under )
{
    if ( over==NULL )
        return under;
    else
        return new_map( over->tab, Temp_layer_map( over->under, under ) );
}
Exemple #5
0
struct map_t *map_preset_sand(void)
{
        struct map_t *sandmap;
        double **sand;
        int i;
        int j;

        sand = empty_simplex_matrix(LINES, COLS);

        for (i=0; i<LINES; i++) {
        for (j=0; j<COLS; j++) {
                sand[i][j] = BEACH_F;
        }
        }

        sandmap = new_map(FULLSCREEN);
        map_gen(sandmap, sandmap->pmap, MAP_NOSMOOTH);

        /*sandmap->asset[1] = new_asset(0);*/
        /*sandmap->asset[1]->put(sandmap, 1, ((LINES/2)-(LINES/3)), ((COLS/2)-2));*/

        map_render(sandmap);

        return sandmap;
}
void init_statistics(struct Statistics *stats)
{
  int i;
  /* Initialize occurrence counts */
  for(i=0; i<256; i++)
    stats->occurrence.single[i] = 0;
  stats->occurrence.multi = NULL;
  stats->occurrence.multi = (struct Map **)malloc(2 * sizeof(struct Map *));
  if(stats->occurrence.multi == NULL)
  {
    printf("Failed to initialize occurrence counts\n");
    exit(EXIT_FAILURE);
  }
  stats->occurrence.multi[0] = new_map(2, 256*256);
  stats->occurrence.multi[1] = new_map(3, 256*256*256);
}
Exemple #7
0
static void	*find_free_space(int bsize, size_t size, void **map)
{
	t_header	*header;
	t_block		*block;

	header = (t_header *)*map;
	while (header)
	{
		block = (t_block *)header->first;
		while (block && (void *)block + block->next <= header->end)
		{
			if (block->flag == FREE && block->next >= size)
				return (set_block(bsize, size, block, header->end));
			if ((void *)block + block->next == header->end)
				block = NULL;
			else
				block = (void *)block + block->next;
		}
		if (!header->next)
		{
			if (new_map(bsize, map, header) < 0)
				return (NULL);
		}
		else
			header = header->next;
	}
	return (NULL);
}
Exemple #8
0
void start_all_threads_interfaces() {
    if(!m_threads) {
        m_threads = new_map(free_string, NULL, compare_string, free_uli, NULL, compare_uli);
    }
    if(cfg_sip) {
        iterator_map *p_it = cfg_sip->begin;
        while(p_it) {
            config_sip_t *sip = p_it->value;
            char *name = calloc(sizeof(sip->name)+1, sizeof(char));
            strcpy(name, sip->name);
            pthread_t *p_thread = calloc(1, sizeof(pthread_t));
            pthread_create(p_thread, NULL, func_listen_sip, sip);
            map_set(m_threads, name, p_thread);
            p_it = p_it->next;
        }
    }
    if(cfg_smpp) {
        iterator_map *p_it = cfg_smpp->begin;
        while(p_it) {
            config_smpp_t *smpp = p_it->value;
            char *name = calloc(sizeof(smpp->name)+1, sizeof(char));
            strcpy(name, smpp->name);
            pthread_t *p_thread = calloc(1, sizeof(pthread_t));
            pthread_create(p_thread, NULL, func_listen_smpp, smpp);
            map_set(m_threads, name, p_thread);
            p_it = p_it->next;
        }
    }
    return;
}
Exemple #9
0
int main(int argc, char *argv[])
{
    scew_parser *parser = NULL;
    if (init() != 0) {
        return 1;
    }

    if (argc == 2) {
        if (exists(argv[1])) {
            parser = scew_parser_create();
            scew_parser_ignore_whitespaces(parser, 1);
            scew_parser_load_file(parser, argv[1]);
            maptree = scew_parser_tree(parser);
        } else {
            allegro_message("Cannot load file: %s", argv[1]);
            close_program = 1;
        }
    } else if (argc == 4) {
        maptree = new_map(0, MAP_WIN.w / TILE_W, atoi(argv[1]), 1, argv[2]);
        map_offset = atoi(argv[1]) * TILE_H - EDITOR_WIN_H;
    } else {
        /* print usage */
        allegro_message
            ("Usage:\n\"editor.exe <filename>\" to load a file\n \"editor.exe <height_in_tiles> <default_tile_name> <newmapfile>\" to create a new map");

        close_program = 1;
    }

    while (!close_program) {
        /* get input */
        parse_mouse();
        get_grid_item();
        if (keypressed()) {
            parse_keyboard();
        }

        /* blit virtual screen */
        clear_to_color(vscreen, DEAD_COLOR);
        draw_select_lists(vscreen);
        draw_ctrl_box(vscreen);

        update_screen();
    }

    if (argc == 2) {
        write_map(argv[1], maptree);
        scew_parser_free(parser);
    } else if (argc == 4) {
        write_map(argv[3], maptree);
        scew_tree_free(maptree);
    }
    destroy_bitmap(vscreen);
    cleanup();
    return 0;
}
Exemple #10
0
struct map_t* create_inimap(const char* inifile)
{
    struct map_t* inimap = new_map();
    map_set_free_func(inimap, free_ini_value);

    if (ini_parse(inifile, handler, inimap) < 0) {
        destroy_map(&inimap);
        inimap = NULL;
    }

    return inimap;
}
Exemple #11
0
int main( int argc, char **argv){
	
	int c_height,c_width;
	map_t *map;

	map = NULL;
	
	c_height = 0;
	c_width = 0;

	if(argc < 4){
		printf("Usage: mars <map> <court width> <court height> \n");
	}else{
		c_height = atoi(argv[3]);
		c_width = atoi(argv[2]);
		map = ld_map_img(argv[1]);
	}
	
	map->c_width = c_width;
	map->c_height = c_height;
	map->min = map_min(map);
	map->max = map_max(map);
	map->count = count(map);	

	/*if(chk_slope_map(map)){
		printf("Yay, it's right!\n");
	}*/
	int k;	
	map_t *best;
	map_t *current;
	best = new_map(map->side);
	best->cost = 1000000;
	//find_best(map);
	
	for(k=1; k<256; k++){
		current = test_pos(map,k,13,509);
		current->cost = cost(map,current);
		printf("%ld\t%d\n",current->cost,k);
		if(current->cost < best->cost){
			free_map(best);
			best = current;
			best->cost = cost(map,best);
			best->h = k;
		}
		
	}
	printf("%ld (%d,%d,%d)\n",best->cost,best->x,best->y,best->h);
	
	exit(1);

	

}
Exemple #12
0
static int
handle_end_map(void *ctx)
{
    struct parse_context *pctx = (struct parse_context *)ctx;
    Var map = new_map();
    Var k, v;
    for (v = POP(pctx->top), k = POP(pctx->top);
	 (int)v.type > MAP_SENTINEL && (int)k.type > MAP_SENTINEL;
	 v = POP(pctx->top), k = POP(pctx->top)) {
	map = mapinsert(map, k, v);
    }
    PUSH(pctx->top, map);
    return 1;
}
Exemple #13
0
void Map::optimize(const fs::path& directory, const fs::path& target,
                   const Options& options) {
  const auto descriptor = internal::Descriptor::readFromDirectory(directory);
  checkDescriptor(descriptor, directory);
  fs::path prefix = directory / getPartitionPrefix(0);
  const Stats stats = internal::Partition::stats(prefix);
  Options new_options = options;
  new_options.error_if_exists = true;
  new_options.create_if_missing = true;
  if (options.block_size == 0) {
    new_options.block_size = stats.block_size;
  }
  if (options.num_partitions == 0) {
    new_options.num_partitions = descriptor.num_partitions;
  }
  Map new_map(target, new_options);

  for (int i = 0; i < descriptor.num_partitions; i++) {
    prefix = directory / getPartitionPrefix(i);
    if (options.verbose) {
      mt::log() << "Optimizing partition " << (i + 1) << " of "
                << descriptor.num_partitions << std::endl;
    }
    if (options.compare) {
      Arena arena;
      std::vector<Slice> values;
      internal::Partition::forEachEntry(
          prefix, [&new_map, &arena, &options, &values](const Slice& key,
                                                        Iterator* iter) {
            arena.deallocateAll();
            values.reserve(iter->available());
            values.clear();
            while (iter->hasNext()) {
              values.push_back(iter->next().makeCopy(&arena));
            }
            std::sort(values.begin(), values.end(), options.compare);
            for (const auto& value : values) {
              new_map.put(key, value);
            }
          });
    } else {
      internal::Partition::forEachEntry(
          prefix, [&new_map](const Slice& key, Iterator* iter) {
            while (iter->hasNext()) {
              new_map.put(key, iter->next());
            }
          });
    }
  }
}
Exemple #14
0
struct map_t *map_preset_arena(void)
{
        struct map_t *arena;
        struct map_t *cave;
        double **armap;
        int i;
        int j;

        armap = empty_simplex_matrix(FULLSCREEN);
       
        for (i=0; i<LINES; i++) {
        for (j=0; j<COLS; j++) {
                if (i >= ARENA_H/2 && i <= LINES-ARENA_H/2
                &&  j >= ARENA_W/2 && j <= COLS-ARENA_W/2)
                        armap[i][j] = BEACH_F;
                else if (i > ISLAND_H_LO && i < ISLAND_H_HI 
                &&       j > ISLAND_W_LO-2 && j < ISLAND_W_HI)
                {
                        if (i > ISLAND_H_LO+ISLAND_FAT+5
                        &&  i < ISLAND_H_HI-ISLAND_FAT
                        &&  j < ISLAND_W_LO+ISLAND_FAT+1) {
                                if (j > ISLAND_W_LO+ISLAND_FAT-2)
                                        armap[i][j] = BEACH_F;
                                else
                                        armap[i][j] = -0.05;
                        } else {
                                armap[i][j] = TERRA_F;
                        }
                }
                else
                        armap[i][j] = -0.05;
        }
        }
       
        arena = new_map(FULLSCREEN);
        map_gen(arena, armap, MAP_NOSMOOTH);

        /* Make a cave entrance */
        cave = new_dungeon();
        put_door(CAVE_DOOR, arena, cave, 
                 1, 1, ARENA_H/2-1, COLS/2,
                 1, 1, LINES/2-10, COLS/2);

        cave_connect_door(cave);
        map_render(arena);
        map_render(cave);

        return arena;
}
Exemple #15
0
/*
 * this function should be changed--the mask map stack is misused as
 * to define the topology of variogram maps.
 *
 * use min/max coordinates for block diagonal as maximum cutoff
 * Returns: about 1/3 the max. dist between any two points in data. 
 */
void fill_cutoff_width(DATA *data /* pointer to DATA structure to derive
		the values from */,
		VARIOGRAM *v /* pointer to VARIOGRAM structure */)
{
	double d = 0.0;
	int i;
	GRIDMAP *m;
	SAMPLE_VGM *ev;

	assert(data);
	assert(v);

	ev = v->ev;
	if (get_n_masks() > 0) {
		m = new_map();
		m->is_write = 0;
		m->filename = get_mask_name(0);
		if ((m = map_read(m)) == NULL)
			ErrMsg(ER_READ, "cannot open map");
		ev->iwidth = 1.0;
		ev->cutoff = m->rows * m->cols; 
			/* not a real cutoff, but rather the size of the container array */
		ev->map = m;
	} else if (gl_bounds != NULL) {
		i = 0;
		while (gl_bounds[i] >= 0.0) /* count length */
			i++;
		ev->cutoff = gl_bounds[i-1];
		ev->iwidth = ev->cutoff / i;
	} else {
		if (is_mv_double(&(ev->cutoff))) {
			if (gl_cutoff < 0.0) {
				d = data_block_diagonal(data);
				if (d == 0.0)
					ev->cutoff = 1.0; /* ha ha ha */
				else
					ev->cutoff = d * gl_fraction;
			} else
				ev->cutoff = gl_cutoff;
		}
		if (is_mv_double(&(ev->iwidth))) {
			if (gl_iwidth < 0.0)
				ev->iwidth = ev->cutoff / gl_n_intervals;
			else
				ev->iwidth = gl_iwidth;
		}
	}
}
Exemple #16
0
void init_world(
  WORLD *world,
  char *spr,
  int tile_index,
  int x,
  int y,
  int w,
  int h,
  int cw,
  int ch
  )
{
  init_world_map(world, w, h);

  /* Load tiles */
  world->tiles=load_sprite(spr, WORLD_TILE_WIDTH, WORLD_TILE_HEIGHT);
  if (world->tiles == NULL) {

    fprintf(stderr, "Unable to load tiles %s\n", spr);
    exit(1);

  }

  world->map=new_map(WORLD_TILE_WIDTH,
                     WORLD_TILE_HEIGHT,
                     WORLD_NUM_TILES, w, h);
  if (world->map == NULL) {

    free_sprite(world->tiles);
    fprintf(stderr, "Unable to load create new map\n");
    exit(1);

  }

  world->tile_base = tile_index;
  world->tile_width = WORLD_TILE_WIDTH;
  world->tile_height = WORLD_TILE_HEIGHT;
  world->width = world->tile_width * w;
  world->height = world->tile_height * h;

  world->map->tiles[world->tile_base + WORLD_EMPTY_TILE].type = 1;
  world->map->tiles[world->tile_base + WORLD_BLOCK_TILE_LO].type = 1;
  world->map->tiles[world->tile_base + WORLD_BLOCK_TILE_HI].type = 1;

  clear_map(world->map, world->tile_base + WORLD_EMPTY_TILE);
  init_world_terrain(world, x, y, cw, ch);
}
OBJ build_map(OBJ *keys, OBJ *values, uint32 size) {
  if (size == 0)
    return make_empty_rel();

  uint32 actual_size = sort_and_check_no_dups(keys, values, size);

  BIN_REL_OBJ *map = new_map(actual_size);
  OBJ *ks  = map->buffer;
  OBJ *vs  = ks + map->size;

  for (uint32 i=0 ; i < actual_size ; i++) {
    ks[i] = keys[i];
    vs[i] = values[i];
  }

  return make_map(map);
}
Exemple #18
0
static GRIDMAP *check_open(const char *name, int i) {
	GRIDMAP *mask;
	unsigned int r, c;

	mask = new_map(READ_ONLY);
	mask->filename = name;
	if ((mask = map_read(mask)) == NULL)
		ErrMsg(ER_READ, name);
	if (i == 0) {
		for (r = n_pred_locs = 0; r < mask->rows; r++)
			for (c = 0; c < mask->cols; c++)
				if (! map_cell_is_mv(mask, r, c))
					n_pred_locs++;
	} else if (! map_equal(mask, masks[0]))
		ErrMsg(ER_NULL, "mask map location is different from first mask map");
	return mask;
}
Exemple #19
0
int is_valid_strata_map(const char *name, int n_vars) {
	GRIDMAP *mp;
	int check_failed = 1;

	mp = new_map(READ_ONLY);
	mp->filename = name;
	if ((mp = map_read(mp)) == NULL)
		ErrMsg(ER_READ, name);
	/* 
	 * check min/max: enough strata? this check was:
	 * check_failed = (mp->cellmax - mp->cellmin < n_vars - 1);
	 */
	check_failed = (mp->cellmax - mp->cellmin < 1.0);
	if (! check_failed && mp->cellmax - mp->cellmin < n_vars - 1)
		pr_warning("fewer mask map categories than data variables present");
	map_free(mp);
	return (check_failed == 0);
}
Exemple #20
0
int		apply_map(char *line, t_map **map)
{
	t_map	*room;
	char	**str;

	str = ft_strsplit(line, ' ');
	if (!(room = new_map(str[0], ft_atoi(str[1]), ft_atoi(str[2]))))
		return (0);
	room->room->start = 0;
	room->room->end = 0;
	if (g_nb == 0)
	{
		g_nb = 1;
		(*map) = room;
	}
	else
		ft_lstaddend_room(map, room);
	return (1);
}
Exemple #21
0
void ossfim2map(double **table, const char *name, double s, double S,
	double b, double B, int dx, int dy) {
	
	GRIDMAP *m;
	TICKS x, y;
	char str[100];
	int i, j;
	extern int nice_legend;
	double bs;
	
	m = new_map();
	m->filename = name;
	m->rows = dy + 1;
	m->cols = dx + 1;
	m->cellsizex = m->cellsizey = 1.0;
	m->x_ul = m->y_ul = 1.0;
	alloc_mv_grid(m);
	for (i = 0; i <= dx; i++) /* row */
		for (j = 0; j <= dy; j++) /* col */
			map_put_cell(m, dy - j, i, table[i][j]); /* flips */

	/* fill ticks */
	x.every = y.every = 1;
	x.n = dx + 1;
	y.n = dy + 1;
	x.entries = (char **) emalloc(x.n * sizeof(char *));
	for (i = 0; i <= dx; i++) { /* sample spacings: */
		sprintf(str, "%3g", s + i * (S - s) / dx);
		x.entries[i] = string_dup((char *) str);
	}
	y.entries = (char **) emalloc(y.n * sizeof(char *));
	for (i = 0; i <= dy; i++) { /* sample spacings: */
		bs = b + i * (B - b) / dy;
		sprintf(str, "%g x %g", bs, bs);
		y.entries[dy - i] = string_dup((char *) str);
	}
	nice_legend = 1;
	one_map2gd(m, name, &y, &x, 1);
	return;
}
Exemple #22
0
void loop() {
	  //put your main code here, to run repeatedly: 
	delay(1000);
        
        //rundiagnostic();
	
        //rundiagnostic();
	utrasonic_espi.getReadings(es);
	//Serial.println(es.ultrasonic0); 
        
	printf("%d %d %d %d\n", es.ultrasonic0, es.ultrasonic90, es.ultrasonic180, es.ultrasonic270);
	
        struct Map* beliefs;
	
	beliefs = new_map();

         // debug - need to add defensive code that means function poitners are all valid prior to entry into function
	 struct Actn action = collision_avoidance_str(beliefs, 0, 0, 0, TURN_PROBABILITY);// 0% prob of turn
	 //printf("Action is 1  %d with magnitude 10 %d\n", action.c, action.m);
         if(action.c == MOVE) {
	   printf("forward %d cm\n", action.m);
         } else if(action.c == TURN) {
           printf("turn %d deg\n",action.m);
         } else if(action.c == NOP) {
           printf("NOP\n");
         } else {
           printf("dunno\n");
         }

         char inputdata[20];
         Serial.println("done\n");

         ReadLine(inputdata); 

         Serial.println("you clicked\n");

	 Serial.flush();
}
Exemple #23
0
vm
read_vm(int task_id)
{
    unsigned i, top, func_id, max;
    int vector;
    char c;
    vm the_vm;

    Var local;
    if (dbio_input_version >= DBV_TaskLocal)
	local = dbio_read_var();
    else
	local = new_map();

    if (dbio_scanf("%u %d %u%c", &top, &vector, &func_id, &c) != 4
	|| (c == ' '
	    ? dbio_scanf("%u%c", &max, &c) != 2 || c != '\n'
	    : (max = DEFAULT_MAX_STACK_DEPTH, c != '\n'))) {
	free_var(local);
	errlog("READ_VM: Bad vm header\n");
	return 0;
    }
    the_vm = new_vm(task_id, local, top + 1);
    the_vm->max_stack_size = max;
    the_vm->top_activ_stack = top;
    the_vm->root_activ_vector = vector;
    the_vm->func_id = func_id;

    for (i = 0; i <= top; i++)
	if (!read_activ(&the_vm->activ_stack[i],
			i == 0 ? vector : MAIN_VECTOR)) {
	    errlog("READ_VM: Bad activ number %d\n", i);
	    return 0;
	}
    return the_vm;
}
Exemple #24
0
//-----------------------------------------------------------------------------
// name: Temp_empty( )
// desc: ...
//-----------------------------------------------------------------------------
Temp_Map Temp_empty( void )
{
    return new_map( TAB_empty( ), NULL );
}
Exemple #25
0
void link_sub_map(tile_t *tile, int maptype, int width, int length) {
/* Link a tile to a relevant sub map */
    tile->sub_map = new_map(maptype, width, length);
}
Exemple #26
0
void process_message_from_server(unsigned char *in_data, int data_lenght)
{
	//see what kind of data we got
	switch (in_data[PROTOCOL])
		{
		case RAW_TEXT:
			{
				// do filtering and ignoring
				data_lenght=filter_or_ignore_text(&in_data[3],data_lenght-3)+3;
				if(data_lenght > 3)
					{
						//how to display it
						if(interface_mode!=interface_opening)
							put_text_in_buffer(&in_data[3],data_lenght-3,0);
						else put_text_in_buffer(&in_data[3],data_lenght-3,54);
						//lets log it
						write_to_log(&in_data[3],data_lenght-3);
					}
			}
			break;
		
		case SMALL_WINDOW_TEXT:
			{
				add_text_to_small_text_buffer(in_data+3, data_lenght-3);
				display_small_text_window();
			}
			break;

		case ADD_NEW_ACTOR:
			{
				add_actor_from_server(&in_data[3]);
			}
			break;

		case ADD_NEW_ENHANCED_ACTOR:
			{
				add_enhanced_actor_from_server(&in_data[3]);
			}
			break;

		case ADD_ACTOR_COMMAND:
			{
				add_command_to_actor(*((short *)(in_data+3)),in_data[5]);
			}
			break;

		case REMOVE_ACTOR:
			{
				destroy_actor(*((short *)(in_data+3)));
			}
			break;

		case KILL_ALL_ACTORS:
			{
				destroy_all_actors();
			}
			break;

		case NEW_MINUTE:
			{
				game_minute=*((short *)(in_data+3));
				new_minute();
			}
			break;

		case LOG_IN_OK:
			{
				interface_mode=interface_game;
				previously_logged_in=1;
			}
			break;

		case HERE_YOUR_STATS:
			{
				get_the_stats((Sint16 *)(in_data+3));
			}
			break;

		case SEND_PARTIAL_STAT:
			{
				get_partial_stat(*((Uint8 *)(in_data+3)),*((Sint32 *)(in_data+4)));
			}
			break;

		case GET_KNOWLEDGE_LIST:
			{
				get_knowledge_list(*(Uint16 *)(in_data+1)-1, in_data+3);
			}
			break;

		case GET_NEW_KNOWLEDGE:
			{
				get_new_knowledge(*(Uint16 *)(in_data+3));
			}
			break;

		case HERE_YOUR_INVENTORY:
			{
				get_your_items(in_data+3);
			}
			break;

		case GET_NEW_INVENTORY_ITEM:
			{
				get_new_inventory_item(in_data+3);
			}
			break;

		case REMOVE_ITEM_FROM_INVENTORY:
			{
				remove_item_from_inventory(*((Uint8 *)(in_data+3)));
			}
			break;

		case INVENTORY_ITEM_TEXT:
			{
				put_small_text_in_box(&in_data[3],data_lenght-3,6*51+100,items_string);
				if(!(get_show_window(items_win)||get_show_window(trade_win)))
					{
						put_text_in_buffer(&in_data[3],data_lenght-3,0);
					}
			}
			break;

		case GET_KNOWLEDGE_TEXT:
			{
				put_small_text_in_box(&in_data[3],data_lenght-3,6*51+150,knowledge_string);
			}
			break;

		case CHANGE_MAP:
			{
				current_sector=-1;
				if(map_file_name[0]!=0)
					save_map(map_file_name);
				object_under_mouse=-1;//to prevent a nasty crash, while looking for bags, when we change the map
				close_dialogue();	// close the dialogue window if open
				destroy_all_particles();

				if(!load_map(&in_data[4])){ // creating map if it does not exist
					int size=(in_data[3]&0x1f)<<4;
					new_map(size,size);
					dungeon=(in_data[3]&0x20)?1:0;
					strcpy(map_file_name,&in_data[4]);
					save_map(map_file_name);
				}
				kill_local_sounds();
#ifndef	NO_MUSIC
				playing_music=0;
#endif	//NO_MUSIC
				get_map_playlist();
				have_a_map=1;
				//also, stop the rain
				seconds_till_rain_starts=-1;
				seconds_till_rain_stops=-1;
				is_raining=0;
				rain_sound=0;//kill local sounds also kills the rain sound
				weather_light_offset=0;
				rain_light_offset=0;
			}
			break;

		case GET_TELEPORTERS_LIST:
			{
				add_teleporters_from_list(&in_data[3]);
			}
			break;

		case PLAY_MUSIC:
			{
				if(!no_sound)play_music(*((short *)(in_data+3)));
			}
			break;

		case PLAY_SOUND:
			{
				if(!no_sound)add_sound_object(*((short *)(in_data+3)),*((short *)(in_data+5)),*((short *)(in_data+7)),*((char *)(in_data+9)),*((short *)(in_data+10)));
			}
			break;

		case TELEPORT_OUT:
			{
				add_particle_sys_at_tile("./particles/teleport_in.part",*((short *)(in_data+3)),*((short *)(in_data+5)));
				if(!no_sound)add_sound_object(snd_tele_out,*((short *)(in_data+3)),*((short *)(in_data+5)),1,0);
			}
			break;

		case TELEPORT_IN:
			{
				add_particle_sys_at_tile("./particles/teleport_in.part",*((short *)(in_data+3)),*((short *)(in_data+5)));
				if(!no_sound)add_sound_object(snd_tele_in,*((short *)(in_data+3)),*((short *)(in_data+5)),1,0);
			}
			break;

		case LOG_IN_NOT_OK:
			{
				sprintf(log_in_error_str,"%s: %s",reg_error_str,invalid_pass);
			}
			break;

		case REDEFINE_YOUR_COLORS:
			{
				strcpy(log_in_error_str,redefine_your_colours);
			}
			break;

		case YOU_DONT_EXIST:
			{
				sprintf(log_in_error_str,"%s: %s",reg_error_str,char_dont_exist);
			}
			break;


		case CREATE_CHAR_NOT_OK:
			{
				sprintf(create_char_error_str,"%s: %s",reg_error_str,char_name_in_use);
				return;
			}
			break;


		case CREATE_CHAR_OK:
			{
				login_from_new_char();
			}
			break;

		case YOU_ARE:
			{
				yourself=*((short *)(in_data+3));
			}
			break;

		case START_RAIN:
			{
				seconds_till_rain_starts=*((Uint8 *)(in_data+3));
				seconds_till_rain_stops=-1;
			}
			break;

		case STOP_RAIN:
			{
				seconds_till_rain_stops=*((Uint8 *)(in_data+3));
				seconds_till_rain_starts=-1;
			}
			break;

		case THUNDER:
			{
				add_thunder(rand()%5,*((Uint8 *)(in_data+3)));
			}
			break;


		case SYNC_CLOCK:
			{
				server_time_stamp=*((int *)(in_data+3));
				client_time_stamp=SDL_GetTicks();
				client_server_delta_time=server_time_stamp-client_time_stamp;
			}
			break;

		case PONG:
			{
				Uint8 str[160];
				sprintf(str,"%s: %i MS",server_latency, SDL_GetTicks()-*((Uint32 *)(in_data+3)));
				log_to_console(c_green1,str);
			}
			break;

		case UPGRADE_NEW_VERSION:
			{
				log_to_console(c_red1,update_your_client);
				log_to_console(c_red1,(char*)web_update_address);
			}
			break;

		case UPGRADE_TOO_OLD:
			{
				log_to_console(c_red1,client_ver_not_supported);
				log_to_console(c_red1,(char*)web_update_address);
				this_version_is_invalid=1;
			}
			break;

		case GET_NEW_BAG:
			{
				put_bag_on_ground(*((Uint16 *)(in_data+3)),*((Uint16 *)(in_data+5)),*((Uint8 *)(in_data+7)));
			}
			break;

		case GET_BAGS_LIST:
			{
				add_bags_from_list(&in_data[3]);
			}
			break;

		case SPAWN_BAG_PARTICLES:
			{
			  add_particle_sys_at_tile("./particles/bag_in.part",*((Uint16 *)(in_data+3)),*((Uint16 *)(in_data+5)));
			}
			break;

		case GET_NEW_GROUND_ITEM:
			{
				get_bag_item(in_data+3);
			}
			break;

		case HERE_YOUR_GROUND_ITEMS:
			{
				get_bags_items_list(&in_data[3]);
			}
			break;

		case CLOSE_BAG:
			{
				hide_window(ground_items_win);
			}
			break;

		case REMOVE_ITEM_FROM_GROUND:
			{
				remove_item_from_ground(in_data[3]);
			}
			break;

		case DESTROY_BAG:
			{
				remove_bag(in_data[3]);
			}
			break;

		case NPC_TEXT:
			{
				put_small_text_in_box(&in_data[3],data_lenght-3,dialogue_menu_x_len-70,dialogue_string);
				display_dialogue();
				if(in_data[3]>=127 && in_data[4]>=127)
					{
						add_questlog(&in_data[4],data_lenght-4);
					}
			}
			break;

		case SEND_NPC_INFO:
			{
				my_strcp(npc_name,&in_data[3]);
				cur_portrait=in_data[23];
			}
			break;

		case NPC_OPTIONS_LIST:
			{
				build_response_entries(&in_data[3],*((Uint16 *)(in_data+1)));
			}
			break;

		case GET_TRADE_ACCEPT:
			{
				if(!in_data[3])trade_you_accepted=1;
				else
					trade_other_accepted=1;
			}
			break;

		case GET_TRADE_REJECT:
			{
				if(!in_data[3])trade_you_accepted=0;
				else
					trade_other_accepted=0;
			}
			break;

		case GET_TRADE_EXIT:
			{
				hide_window(trade_win);
			}
			break;

		case GET_YOUR_TRADEOBJECTS:
			{
				get_your_trade_objects(in_data+3);
			}
			break;

		case GET_TRADE_OBJECT:
			{
				put_item_on_trade(in_data+3);
			}
			break;

		case REMOVE_TRADE_OBJECT:
			{
				remove_item_from_trade(in_data+3);
			}
			break;

		case GET_TRADE_PARTNER_NAME:
			{
				get_trade_partner_name(&in_data[3],*((Uint16 *)(in_data+1))-1);
			}
			break;

		case GET_ACTOR_DAMAGE:
			{
				get_actor_damage(*((Uint16 *)(in_data+3)),in_data[5]);
			}
			break;

		case GET_ACTOR_HEAL:
			{
				get_actor_heal(*((Uint16 *)(in_data+3)),in_data[5]);
			}
			break;

		case ACTOR_UNWEAR_ITEM:
			{
				unwear_item_from_actor(*((Uint16 *)(in_data+3)),in_data[5]);
			}
			break;

		case ACTOR_WEAR_ITEM:
			{
				actor_wear_item(*((Uint16 *)(in_data+3)),in_data[5],in_data[6]);
			}
			break;

		case NPC_SAY_OVERTEXT:
			{
				add_displayed_text_to_actor(
					get_actor_ptr_from_id( *((Uint16 *)(in_data+3)) ), in_data+5 );
			}
			break;

		case BUDDY_EVENT:
			{
				if(in_data[3]==1)
					add_buddy(&in_data[5],in_data[4],data_lenght-5);
				else if(in_data[3]==0)
					del_buddy(&in_data[4],data_lenght-4);
			}
			break;

		// BARREN MOON NEW MESSAGES
		case THIS_IS_ACTIVE_SECTOR:
			active_sector=*((Uint16 *)(in_data+3));
			break;

		case GET_TILE_DATA:
			get_tile_data(in_data+3);
			break;

		case GET_3D_OBJECTS:
			get_3d_objects(in_data+3);
			break;

		case GET_2D_OBJECTS:
			get_2d_objects(in_data+3);
			break;

		case GET_LIGHT_OBJECTS:
			get_light_objects(in_data+3);
			break;

		case GET_PARTICLE_OBJECTS:
			get_particle_objects(in_data+3);
			break;

		case GET_3D_OBJECTS_FULL_ROTATION:
			get_3d_objects_full_rotation(in_data+3);
			break;

		case GET_CHECKSUMS:
		{
			actor *actor=pf_get_our_actor();
			get_checksums(in_data+3, sector_get(actor->x_pos,actor->y_pos));
			break;
		}

		case ADD_3D_OBJECT:
			add_3d_object(in_data+3);
			break;

		case ADD_3D_OBJECT_FULL_ROTATION:
			add_3d_object_fullrotation(in_data+3);
			break;

		case DELETE_3D_OBJECT:
			delete_3d_object(in_data+3);
			break;

		case REPLACE_3D_OBJECT:
			replace_3d_object(in_data+3);
			break;

		case ADD_2D_OBJECT:
			add_2d_object(in_data+3);
			break;

		case DELETE_2D_OBJECT:
			delete_2d_object(in_data+3);
			break;

		case REPLACE_2D_OBJECT:
			replace_2d_object(in_data+3);
			break;

		case ADD_LIGHT:
			add_lights(in_data+3);
			break;

		case DELETE_LIGHT:
			delete_light(in_data+3);
			break;

		case ADD_PARTICLE:
			add_particle(in_data+3);
			break;

		case DELETE_PARTICLE:
			delete_particle(in_data+3);
			break;

		case REPLACE_PARTICLE:
			replace_particle(in_data+3);
			break;

		default:
			{
				/* Unknown data type?? */;
			}
			break;
		}
}
Exemple #27
0
void init_stuff()
{
	int i;
	int seed;

	chdir(DATA_DIR);
	
#ifndef WINDOWS
	setlocale(LC_NUMERIC,"en_US");
#endif
	init_translatables();

	//create_error_mutex();
	init_globals();
	init_crc_tables();
	init_zip_archives();
	cache_system_init(MAX_CACHE_SYSTEM);
	init_texture_cache();

	init_vars();
	
	read_config();

	file_check_datadir();

#ifdef LOAD_XML
	//Well, the current version of the map editor doesn't support having a datadir - will add that later ;-)
	load_translatables();
#endif

#ifdef LINUX
#ifdef GTK2
	init_filters();
#else
	file_selector = create_fileselection();
#endif
#endif	//LINUX

	init_gl();

	window_resize();
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);
//	glDepthFunc(GL_LEQUAL);
    glEnable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);
	glFrontFace(GL_CCW);
	glCullFace(GL_BACK);
	glEnable(GL_NORMALIZE);
	glClearColor( 0.0, 0.0, 0.0, 0.0 );
	glClearStencil(0);

	seed = time (NULL);
  	srand (seed);

	init_texture_cache();
	init_particles ();
	init_e3d_cache();
	init_2d_obj_cache();

	for(i=0; i<256; i++)
        tile_list[i]=0;

	for (i = 0; i < MAX_LIGHTS; i++)
		lights_list[i] = NULL;

	new_map(256,256);
	load_all_tiles();

	//lights setup
	build_global_light_table();
	build_sun_pos_table();
	reset_material();
	init_lights();
	//disable_local_lights();
	//clear_error_log();

	// Setup the new eye candy system
#ifdef	EYE_CANDY
	ec_init();
#endif	//EYE_CANDY

	init_gl_extensions();

	if(have_multitexture)
#ifdef	NEW_TEXTURES
		ground_detail_text = load_texture_cached("./textures/ground_detail.bmp", tt_mesh);
#else	/* NEW_TEXTURES */
		ground_detail_text = load_texture_cache ("./textures/ground_detail.bmp",255);
#endif	/* NEW_TEXTURES */

	//load the fonts texture
	init_fonts();
#ifdef	NEW_TEXTURES
	icons_text=load_texture_cached("./textures/gamebuttons.bmp", tt_gui);
	buttons_text=load_texture_cached("./textures/buttons.bmp", tt_gui);
#else	/* NEW_TEXTURES */
	icons_text=load_texture_cache("./textures/gamebuttons.bmp",0);
	buttons_text=load_texture_cache("./textures/buttons.bmp",0);
#endif	/* NEW_TEXTURES */
	//get the application home dir

	have_multitexture=0;//debug only

#ifndef LINUX
	GetCurrentDirectory(sizeof(exec_path),exec_path);
#else
	exec_path[0]='.';exec_path[1]='/';exec_path[2]=0;
#endif
	init_browser();

    if(SDL_InitSubSystem(SDL_INIT_TIMER)<0)
    { 
        char str[120];
        snprintf(str, sizeof(str), "Couldn't initialize the timer: %s\n", SDL_GetError());
        log_error(__FILE__, __LINE__, str);
        SDL_Quit();
	    exit(1);
    }

	SDL_SetTimer (1000/(18*4), my_timer);

	SDL_EnableUNICODE(1);

    //we might want to do this later.

	// creating windows
	display_browser();
	toggle_window(browser_win);

	display_o3dow();
	toggle_window(o3dow_win);

	display_replace_window();
	toggle_window(replace_window_win);

	display_edit_window();
	toggle_window(edit_window_win);

	create_particles_window ();
}
Exemple #28
0
int main(int argc, char *argv[])
{
    int result = init_all();
    if(result != 0)
        return result;
    //init array
    new_map();
    //init cursor
    Cursor* cursor = new Cursor(renderer);
    //init tiles
    summon_tiles();

    //Main Loop
    while(true)
    {
        SDL_RenderClear(renderer);
        while(SDL_PollEvent(&Event))
        {
            if(Event.type == SDL_QUIT)
                goto fin;
            if(Event.type == SDL_KEYDOWN)
            {
                switch(Event.key.keysym.sym)
                {
                case SDLK_ESCAPE:
                    goto fin;
                    break;
                case SDLK_LEFT:
                    if(cursor_x == 0)
                        cursor_x = 14;
                    else
                        --cursor_x;
                    break;
                case SDLK_RIGHT:
                    if(cursor_x == 14)
                        cursor_x = 0;
                    else
                        ++cursor_x;
                    break;
                case SDLK_UP:
                    if(cursor_y == 0)
                        cursor_y = 14;
                    else
                        --cursor_y;
                    break;
                case SDLK_DOWN:
                    if(cursor_y == 14)
                        cursor_y = 0;
                    else
                        ++cursor_y;
                    break;
                case SDLK_RETURN:

                    break;
                }
            }

        }
        for(int i = 0; i < 15; i++)
        {
            for(int j = 0; j < 15; j++)
            {
                SDL_RenderCopy(renderer,blocks[i][j]->texture, NULL, &blocks[i][j]->rect_block);
            }
        }

        cursor->rect.x = cursor_x*32;
        cursor->rect.y = cursor_y*32;
        SDL_RenderCopy(renderer,cursor->texture,NULL,&cursor->rect);
        SDL_RenderPresent(renderer);
    }

    //Clear everything
    fin:
    for(int i = 0; i < 15; i++)
    {
        for(int j = 0; j < 15; j++)
        {
            free(blocks[i][j]);
        }
    }
    SDL_Quit();
    //system("cls");
    //printf("\nI seriously hope you remembered to save.");
    //printf("\nI also seriously hope we finish this shit by the deadline.\n\n");
    //printf("\nThank you for putting the \"dung\" in \"dungeon\"! \n\n\n\n\n");
    printf("\n\n\n\n\n\n\nJUST v0.0.1 - Copyup (c)1984 SOME AMOUNT OF RIGHTS RESERVED, BITCH\n\"F**k FLOSS, F**k Liberty, and especially, F**k You :^)\"\n\n");
    //system("pause");
    return 0;

}
Exemple #29
0
int main(int argc, char *argv[])
{
	int	i;
	char buf[512];
	SDL_Surface	*screen = NULL,
							*message = NULL;
	SDL_PixelFormat fmt;
	TTF_Font *tmp_font;
	SDL_Color text_color_black = {0,0,0};
	SDL_Color text_color_white = {255, 255, 255};
	//Mix_Music *music = NULL;
	//Mix_Chunk *scratch = NULL;
	Uint32 timer_start = 0, timer_last_frame = 0;
	struct game game;
	
	// initialisation
	if(init_game(&game))
		return 1;
	screen = SDL_GetVideoSurface();
	fmt = *(screen->format);
	///////////////
	// main loop //
	///////////////
	timer_start = SDL_GetTicks();
	timer_last_frame = SDL_GetTicks();
	
	while(!game.quit)
	{
		// update time
		game.timer_delta = ((double)(SDL_GetTicks() - (double)timer_last_frame) / 1000);
		timer_last_frame = SDL_GetTicks();
		
		///////////
		// Input //
		///////////
		read_input(&game);
		
		///////////
		// Logic //
		///////////
		if(game.finished)
		{
			//game.menu = MAPBROWSER;
			sscanf(game.map, "%d", &i);
			i++;
			sprintf(game.map, "%d", i);
			
			game.reset = 1;
			game.update = 1;
			game.finished = 0;
		}
		
		// Ingame
		if(game.menu == INGAME)
		{
			if(!game.paused || game.reset)
			{
				if(game.pause_screen)
					game.pause_screen = 0;
			
				// reset game
				if(game.reset)
				{
					if(!load_map(&game))
					{
						printf("Invalid map!\n");
						game.menu = MAINMENU;
					}
					game.reset = 0;
					game.paused = 0;
					game.update = 1;
					game.moves = 0;
					game.keys = 0;
				}
				
				// loop through all objects
				for(i=0; i<game.num_objects; i++)
				{
					// save old position
					game.object[i].x_Prev = game.object[i].x;
					game.object[i].y_Prev = game.object[i].y;
				
					// move object
					move(i, &game);
					
					// configure cursor
					if(!strcmp(game.object[i].type, "player"))
					{
						set_cursor (&game, i);
					}
					
					// check if screen refresh is needed
					if( (int)game.object[i].x != (int)game.object[i].x_Prev ||
							(int)game.object[i].y != (int)game.object[i].y_Prev)
					{
						game.update = 1;
					}
				}
				
				// set camera to player
				for(i=0; i<game.num_objects; i++)
				{
					if(!strcmp(game.object[i].type, "player"))
					{
						game.camera.x = (game.object[i].x + game.object[i].w / 2) - game.screen_width / 2;
						game.camera.y = (game.object[i].y + game.object[i].h / 2) - game.screen_height / 2;
					}
				}
				if(game.camera.x < 0)
					game.camera.x = 0;
				if(game.camera.x + game.camera.w > game.level_width)
					game.camera.x = game.level_width - game.camera.w;
				if(game.camera.y < 0)
					game.camera.y = 0;
				if(game.camera.y + game.camera.h > game.level_height)
					game.camera.y = game.level_height - game.camera.h;
				
			}
		}
		
		// Editor
		else if(game.menu == EDITOR)
		{
			game.num_buttonlist = 0;
			
			if(game.mouse.x_input != game.mouse.x_prev || game.mouse.y_input != game.mouse.y_prev)
				process_buttons(&game);
			
			game.paused = 0;
			if(game.reset)
			{
				if(!game.map[0])// && !game.enter_mapname)
					new_map(&game);
				else
					load_map(&game);

				// remove "player" from toolbox
				// if the map contains a player tile
				game.tool_object[PLAYER].visible = 1;
				for(i=0; i<game.num_objects; i++)
					if(!strcmp(game.object[i].type, "player"))
						game.tool_object[PLAYER].visible = 0;
											
				game.reset = 0;
			}
			set_map_properties(&game);
			scroll_map(&game);
			drag_objects(&game);
			handle_tools(&game);
			if(game.enter_mapname)
				enter_mapname(&game);
			
			if(strcmp(game.map_prev, game.map))
			{
				if(game.save_as)
					SDL_FreeSurface(game.save_as);
				game.save_as = TTF_RenderUTF8_Blended(game.font_yo_frankie, game.map, text_color_white);
				strcpy(game.map_prev, game.map);
				game.update = 1;
			}
		}
		
		// Mainmenu
		else if(game.menu == MAINMENU)
		{
			game.num_buttonlist = 0;
			
			if(game.mouse.x_input != game.mouse.x_prev || game.mouse.y_input != game.mouse.y_prev)
				process_buttons(&game);
			
			// reset cursor
			for(i=1; i<5; i++)
			{
				game.mouse.clip[i].x = 0; game.mouse.clip[1].y = 0;
				game.mouse.clip[i].x = 0;  game.mouse.clip[2].y = 0;
				game.mouse.clip[i].x = 0; game.mouse.clip[3].y = 0;
				game.mouse.clip[i].x = 0; game.mouse.clip[4].y = 0;
				game.mouse.point_dir = 0;
			}
		}
		
		// Mapbrowser
		else if(game.menu == MAPBROWSER)
		{
			process_list(&game);
			// reset cursor
			for(i=1; i<5; i++)
			{
				game.mouse.clip[i].x = 0; game.mouse.clip[1].y = 0;
				game.mouse.clip[i].x = 0;  game.mouse.clip[2].y = 0;
				game.mouse.clip[i].x = 0; game.mouse.clip[3].y = 0;
				game.mouse.clip[i].x = 0; game.mouse.clip[4].y = 0;
				game.mouse.point_dir = 0;
			}
		}
		
		if(game.mouse.x_input != game.mouse.x_prev || game.mouse.y_input != game.mouse.y_prev)
		{
			game.mouse.x_prev = game.mouse.x_input;
			game.mouse.y_prev = game.mouse.y_input;
			//if(SDL_GetTicks() % 2 == 0)
				game.update = 1;
		}

		////////////
		// Render //
		////////////
		
		// don't update screen if it is not required
		if(game.update)
		{
			//printf("updating screen\n");
			//SDL_SetAlpha(wall_surface, SDL_SRCALPHA, 0); 
			//printf("%d | %d » %d | %d || %d\n", game.mouse.x_prev, game.mouse.y_prev, game.mouse.x, game.mouse.y, game.mouse.click);
			if(game.menu == INGAME)
			{
				render_game(&game);
				
				message = SDL_CreateRGBSurface(0, 300, 50, fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, fmt.Amask);
				SDL_SetAlpha(message, SDL_SRCALPHA, 150);
				SDL_FillRect(message, &message->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
				apply_surface(0, game.screen_height - message->h, message, screen, NULL);
				SDL_FreeSurface(message);
				
				sprintf(buf, "Moves: %d  Keys: %d", game.moves, game.keys);
				message = TTF_RenderUTF8_Blended(game.font_yo_frankie, buf, text_color_black);
				apply_surface(5, game.screen_height - message->h - 5, message, screen, NULL);
				SDL_FreeSurface(message);
			}
			else if(game.menu == EDITOR)
			{
				render_game(&game);
				/*tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 18);
				message = TTF_RenderUTF8_Blended(tmp_font, "By Sören Wegener", text_color_black);
				apply_surface(game.screen_width / 2 - message->w / 2, 150, message, screen, NULL);
				TTF_CloseFont(tmp_font);
				SDL_FreeSurface(message);*/
				render_toolbox(&game);
				render_buttons(&game);
				if(game.enter_mapname)
				{
					i = 450;
					
					if(game.save_as && game.save_as->w > 430)
							i = game.save_as->w + 20;
					
					message = SDL_CreateRGBSurface(0, i, 70, fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, fmt.Amask);
					SDL_SetAlpha(message, SDL_SRCALPHA, 180);
					SDL_FillRect(message, &message->clip_rect, SDL_MapRGB(screen->format, 0x00, 0x00, 0x00));
					apply_surface(game.screen_width / 2 - message->w / 2, game.screen_height / 2 - message->h / 2, message, screen, NULL);
					SDL_FreeSurface(message);
					
					message = TTF_RenderUTF8_Blended(game.font_yo_frankie, "Enter Mapname and press Enter", text_color_white);
					apply_surface(game.screen_width / 2 - message->w / 2, game.screen_height / 2 - message->h / 2 - 15, message, screen, NULL);
					if(game.save_as)
						apply_surface(game.screen_width / 2 - game.save_as->w / 2, game.screen_height / 2 - game.save_as->h / 2 + 15, game.save_as, screen, NULL);
				}
			}
			else if(game.menu == MAINMENU)
			{
				SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
				render_buttons(&game);
				
				tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 56);
				message = TTF_RenderUTF8_Blended(tmp_font, "<Lustiger Spielname hier>", text_color_black);
				apply_surface(game.screen_width / 2 - message->w / 2, 50, message, screen, NULL);
				TTF_CloseFont(tmp_font);
				SDL_FreeSurface(message);
				
				tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 18);
				message = TTF_RenderUTF8_Blended(tmp_font, "By Sören Wegener", text_color_black);
				apply_surface(game.screen_width / 2 - message->w / 2, 150, message, screen, NULL);
				TTF_CloseFont(tmp_font);
				SDL_FreeSurface(message);
				
				tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 14);
				message = TTF_RenderUTF8_Blended(tmp_font, "Yo Frankie font created by Pablo Vazquez and converted by Mango Jambo using FontForge 2.0", text_color_black);
				apply_surface(0, game.screen_height - message->h, message, screen, NULL);
				TTF_CloseFont(tmp_font);
				SDL_FreeSurface(message);
			}
			else if(game.menu == MAPBROWSER)
			{
				SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
				render_list(&game);
			}
			
			render_cursor(&game);
						
			// refresh screen
			SDL_Flip(screen);
			game.update = 0;
		}
		
		// needed to prevent 100% CPU usage
		SDL_Delay(0);
	}
	
	cleanup(&game);
	return 0;
}
Exemple #30
0
/**
 * Makes the count of a map add up to the count of the original.
 * @param	omap	original map
 * @param	nmap	new map
 */
void construct(map_t *omap, map_t *nmap){
	int i,j;
	int side;
	int **omat,**nmat;
	int **tmat;
	map_t *tmap;
	int x,y,x1,y1;
	long int diff;

	if(omap->count==0) count(omap);
	if(nmap->count==0) count(nmap);

	diff = nmap->count - omap->count;

	x = nmap->x;
	y = nmap->y;
	
	x1 = x+nmap->c_width-1;
	y1 = y+nmap->c_height-1;

	side = omap->side;

	omat = omap->matrix;
	nmat = nmap->matrix;

	tmap = new_map(side);

	tmat = tmap->matrix;
	if(x1 < 0){ 
		x1 = side+x1%side;
	}else{
		x1 = x1 % side;
	}
	if(y1 < 0){ 
		y1 = side+y1%side;
	}else{
		y1 = y1 % side;
	}

	for(i=0; i<side; i++){
		for(j=0; j<side; j++){

			if(!(i <= x1 && i >= x && j <= y1 && j >= y)){
				tmat[i][j] = (nmat[i][j]-omat[i][j]);
			}
		}
	}
	
	while(diff > 0){
		for(i=0; i<side; i++){
			for(j=0; j<side; j++){
				if(!(i <= x1 && i >= x && j <= y1 && j >= y)){
					if(tmat[i][j]==0){
						nmat[i][j]--;
						if(chk_slope(nmap,i,j)==0){
							nmat[i][j]++;
						}else{
							diff--;
							if(diff==0)break;
						}	
						if(diff==0)break;
					}
					if(diff==0)break;
				}
				if(diff==0)break;
		
			}
			if(diff==0)break;
		}
	}


	while(diff < 0){
		for(i=0; i<side; i++){
			for(j=0; j<side; j++){
				if(!(i <= x1 && i >= x && j <= y1 && j >= y)){
					if(tmat[i][j]==0){
						nmat[i][j]++;
						if(chk_slope(nmap,i,j)==0){
							nmat[i][j]--;

						}else{
							diff++;
							if(diff==0)break;
						}	
						if(diff==0)break;
					}
					if(diff==0)break;
				}
				if(diff==0)break;

			}
			if(diff==0)break;
		}
	}
	free_map(tmap);	

}