コード例 #1
0
ファイル: datreader.cpp プロジェクト: kbok/datreader
void extract_map(std::string const &filename, std::string const &output_dir) {
	std::ifstream ifs;
	ifs.exceptions(std::ios::badbit | std::ios::failbit | std::ios::eofbit);
	ifs.open(filename.c_str(), std::ios::binary);

	map_header header;
	read_to(header, ifs);

	std::vector<char> minimap(header.width * header.height);
	read_to(minimap, ifs);

	std::vector<unsigned short> map_index(header.width * header.height);
	read_to(map_index, ifs);

	unsigned short terrains_count;
	read_to(terrains_count, ifs);

	typedef char tile_gfx[64*64];
	std::vector<tile_gfx> map_gfx(terrains_count);
	read_to(map_gfx, ifs);

	std::vector<char> palette(3 * 256);
	read_to(palette, ifs);

	std::vector<char> tile_types(terrains_count);
	read_to(tile_types, ifs);

	png_encoder encoder;
	CreateDirectoryA(output_dir.c_str(), 0);

	image minimap_img = decode_simple_buffer(header.width, header.height, minimap.data(), palette.data());
	minimap_img.swap_pixels();
	encoder.save_png(output_dir + "/minimap.png", minimap_img);

	for (size_t i = 0; i < terrains_count; ++i) {
		image tile_gfx = decode_simple_buffer(64, 64, map_gfx[i], palette.data());
		tile_gfx.swap_pixels();
		std::ostringstream foss;
		foss << output_dir << "/" << i << ".png";
		encoder.save_png(foss.str(), tile_gfx);
	}

	std::ofstream maptxt(output_dir + "/map.txt");
	maptxt << header.width << " " << header.height << std::endl;

	maptxt << tile_types.size() << std::endl;
	for (int type : tile_types)
		maptxt << type << " ";
	maptxt << std::endl;
	
	maptxt << map_index.size() << std::endl;
	for (int idx : map_index)
		maptxt << idx << " ";
	maptxt << std::endl;
}
コード例 #2
0
ファイル: player.c プロジェクト: ediiknorand/ld25
void player_refresh(double delta)
{
  int dx = (int)(float)dbt_input.mouse_x/MAP_TILE_W;
  int dy = (int)(float)dbt_input.mouse_y/MAP_TILE_H;

  player_cooldown += delta;

  if(player_cooldown < 10.0f)
    return;
  if(player_cooldown >= 10.0f)
    player_cooldown = 10.0f;

  if(dx < 0 || dx >= MAP_WIDTH || dy < 0 || dy >= MAP_HEIGHT)
    return;

  if(dbt_input.mouse_left && player_skill)
  {
    switch(player_skill)
    {
    case PLAYER_SKILL1:
      if(dbt_map.emap[map_index(dx,dy)] < 0)
        entity_spawn(ENTITY_BUNNY, dx, dy);
      else
      {
        player_cooldown = 10.0f;
	return;
      }
      break;
    case PLAYER_SKILL2:
      if(dbt_map.emap[map_index(dx,dy)] == ENTITY_SOLDIER || dbt_map.emap[map_index(dx,dy)] == ENTITY_ARCHER)
        dbt_map.amap[map_index(dx,dy)] += 200;
      else
      {
        player_cooldown = 10.0f;
	return;
      }
    }
    player_skill = PLAYER_SKILL0;
    player_cooldown = 0.0f;
  }
}
コード例 #3
0
ファイル: Des.cpp プロジェクト: SiteView/eccmeteor
bool Des::Decrypt(const char *szInput, char *szOutput)
{
	int i = 0;
	int inlen = strlen(szInput);
	int datalen = 0;

	if(inlen <= 8 || inlen > 512)
		return false;

	i = 0;
	char src[MAX_LEN] = {0};
	while(i < inlen)
	{
		int len = 0;
		int hi = map_index(szInput[i], len);
		i += len;
		int lo = map_index(szInput[i], len);
		i += len;

		if(hi == 99 || lo == 99)
			return false;

		src[datalen++] = hi * 0x10 + lo;
	}
	
    des_key_setup(GET_32BIT_MSB_FIRST(key8),
		  GET_32BIT_MSB_FIRST(key8 + 4), &crkey);

	unsigned char dest[256] = {0};
	des_cbc_decrypt(dest, (unsigned char *)src, datalen, &crkey);

	sprintf(szOutput, "%s", dest);

	//memset(key, 0, 8);
	//memset(map, 0, 256);

	return true;

}
コード例 #4
0
ファイル: meta_sampler.c プロジェクト: timburks/highland
int sampler_get(sampler s, size_t entity_id, size_t i, long long* pval)
{
	size_t idx;

	assert(s != NULL);
	assert(entity_id < s->nentity);
	assert(i < s->nvalue);
	assert(pval != NULL);

	idx = map_index(s, i);
	*pval = s->entities[entity_id].data[idx];

	return *pval != LLONG_MIN;
}
コード例 #5
0
ファイル: meta_sampler.c プロジェクト: timburks/highland
time_t sampler_time(sampler s, size_t i)
{
	size_t idx;
	time_t t;

	assert(s != NULL);
	assert(i < s->nvalue);

	idx = map_index(s, i);
	t = s->times[i];

	assert(t != (time_t)-1);
	return t;
}
コード例 #6
0
    element& operator() (chunk_index i, uint8_t dir)
    {
        chunk_index p (0,0,0);

        switch (dir)
        {
            case 0: p = chunk_index( i.y, i.z, i.x); break;
            case 1: p = chunk_index( 15 - i.y, i.z, 15 - i.x); break;
            case 2: p = chunk_index( 15 - i.x, i.z, i.y); break;
            case 3: p = chunk_index( i.x, i.z, 15 - i.y); break;
            case 4: p = chunk_index( i.x, i.y, i.z); break;
            case 5: p = chunk_index( i.x, 15 - i.y, 15 - i.z); break;
            default: assert(false);
        }

        return dirs[dir][p.z][map_index(p)];
    }
コード例 #7
0
static void resubmit(struct ploop_request * preq)
{
	struct ploop_delta * delta = ploop_top_delta(preq->plo);
	unsigned long sec;

	switch (preq->eng_state) {
	case PLOOP_E_INDEX_WB:
		delta = map_writable_delta(preq);
		map_index(delta, preq, &sec);
		nfsio_write_page(&delta->io, preq,
				 preq->sinfo.wi.tpage,
				 sec, 0);
		break;
	case PLOOP_E_DATA_WBI:
		if (preq->aux_bio) {
			struct bio_list tbl;
			tbl.head = tbl.tail = preq->aux_bio;
			nfsio_submit_write_pad(&delta->io, preq, &tbl,
					       preq->iblock, 1<<preq->plo->cluster_log);
		} else {
			nfsio_submit_write_pad(&delta->io, preq, &preq->bl,
					       preq->iblock, preq->req_size);
		}
		break;
	case PLOOP_E_COMPLETE:
	case PLOOP_E_RELOC_NULLIFY:
		if (preq->aux_bio) {
			struct bio_list tbl;
			tbl.head = tbl.tail = preq->aux_bio;
			nfsio_submit_write(&delta->io, preq, &tbl,
					   preq->iblock, 1<<preq->plo->cluster_log);
		} else {
			nfsio_submit_write(&delta->io, preq, &preq->bl,
					   preq->iblock, preq->req_size);
		}
		break;
	default:
		printk("Resubmit bad state %lu\n\n", preq->eng_state);
		BUG();
	}
}
コード例 #8
0
stream_port_input_get_audio_map_response_imp::stream_port_input_get_audio_map_response_imp(uint8_t * frame, size_t frame_len, ssize_t pos)
{
    m_position = pos;
    m_size = frame_len;
    m_frame = (uint8_t *)malloc(m_size * sizeof(uint8_t));
    memcpy(m_frame, frame, m_size);

    offset = m_position + JDKSAVDECC_AEM_COMMAND_GET_AUDIO_MAP_RESPONSE_OFFSET_MAPPINGS + (8 * map_index());

    for (unsigned int i = 0; i < (unsigned int)number_of_mappings(); i++)
    {
        struct stream_port_input_audio_mapping map;

        map.stream_index = jdksavdecc_uint16_get(frame, offset);
        map.stream_channel = jdksavdecc_uint16_get(frame, offset + 2);
        map.cluster_offset = jdksavdecc_uint16_get(frame, offset + 4);
        map.cluster_channel = jdksavdecc_uint16_get(frame, offset + 6);
        maps.push_back(map);
        offset += sizeof(struct stream_port_input_audio_mapping);
    }
}
コード例 #9
0
ファイル: hash.c プロジェクト: alethea/SoftwareSystems
/* Looks up a key and returns the corresponding value, or NULL. */
Value *map_lookup(Map *map, Hashable *key)
{
    return list_lookup(map->lists[map_index(map, key)], key);
}
コード例 #10
0
ファイル: hash.c プロジェクト: alethea/SoftwareSystems
/* Adds a key-value pair to a map. */
void map_add(Map *map, Hashable *key, Value *value)
{
    int i = map_index(map, key);

    map->lists[i] = prepend(key, value, map->lists[i]);
}