Esempio n. 1
0
/***********************************
Write a new filename in a character's sprite list
return RET_NOK on error
***********************************/
int character_set_sprite(const char * id, int index, const char * filename)
{
	if(id == NULL || filename == NULL) {
		return RET_NOK;
	}

	if( entry_write_list_index(CHARACTER_TABLE, id, filename, index,CHARACTER_KEY_SPRITE,NULL ) == RET_NOK ) {
		return RET_NOK;
	}

	return RET_OK;
}
Esempio n. 2
0
/***********************************
 Write a new filename in a character's moving sprite list
 return RET_NOK on error
 ***********************************/
int character_set_sprite_move(const char * id, const char * dir, int index,
		const char * filename)
{
	const char * key;

	if (id == nullptr || filename == nullptr || dir == nullptr)
	{
		return RET_NOK;
	}

	switch (dir[0])
	{
	case 'N':
	case 'n':
		key = CHARACTER_KEY_MOV_N_SPRITE;
		break;
	case 'S':
	case 's':
		key = CHARACTER_KEY_MOV_S_SPRITE;
		break;
	case 'W':
	case 'w':
		key = CHARACTER_KEY_MOV_W_SPRITE;
		break;
	case 'E':
	case 'e':
		key = CHARACTER_KEY_MOV_E_SPRITE;
		break;
	default:
		return RET_NOK;
		break;
	}

	if (entry_write_list_index(CHARACTER_TABLE, id, filename, index, key,
			nullptr) == RET_NOK)
	{
		return RET_NOK;
	}

	return RET_OK;
}
Esempio n. 3
0
/***********************************
 Write a new tile type into a map file
 return RET_NOK if fails
 ***********************************/
ret_code_t map_set_tile_type(const char * map, int layer, const char * type,
		int x, int y, int network_broadcast)
{
	char * previous_type = nullptr;
	int width = -1;
	int index;
	char layer_name[SMALL_BUF];

	if (map == nullptr || type == nullptr)
	{
		return RET_NOK;
	}

	if (x < 0 || y < 0)
	{
		return RET_NOK;
	}

	sprintf(layer_name, "%s%d", MAP_KEY_LAYER, layer);

	// Manage concurrent access to map files
	SDL_LockMutex(map_mutex);

	// read size of map grid
	if (entry_read_int(MAP_TABLE, map, &width, MAP_KEY_WIDTH,
			nullptr) == RET_NOK)
	{
		SDL_UnlockMutex(map_mutex);
		return RET_NOK;
	}

	index = width * y + x;

	// read previous map type
	if (entry_read_list_index(MAP_TABLE, map, &previous_type, index, layer_name,
			MAP_KEY_TYPE, nullptr) == RET_OK)
	{
		/* Do not change the type if it already the requested type
		 Avoid calling useless context_broadcast_file */
		if (strcmp(previous_type, type) == 0)
		{
			free(previous_type);
			SDL_UnlockMutex(map_mutex);
			return RET_OK;
		}
		free(previous_type);
	}

	if (entry_write_list_index(MAP_TABLE, map, type, index, layer_name,
			MAP_KEY_TYPE, nullptr) == RET_OK)
	{
		if (network_broadcast)
		{
			context_broadcast_map(map);
		}
	}

	SDL_UnlockMutex(map_mutex);

	return RET_OK;
}