#include #include #include #include "Aw.h" /** * Creates and initializes a zone object. * * The initialized structure must be manually destroyed using free(). * The remaining fields of the zone are to be set by yourself. * * The value NULL may be specified for one or more strings to indicate * that string is not to be used. * * @param footstep String specifying footstep sound. * @param ambient String specifying ambient sound. * @param camera String specifying camera object to use. * @return An initialized aw_object_data_zone structure. */ aw_object_data_zone* new_zone(const char* footstep, const char* ambient, const char* camera) { size_t flen = (footstep == NULL)? 0 : strlen(footstep); size_t alen = (ambient == NULL)? 0 : strlen(ambient); size_t clen = (camera == NULL)? 0 : strlen(camera); size_t psiz = flen + alen + clen + sizeof(aw_object_data_zone); aw_object_data_zone* zone = NULL; zone = (aw_object_data_zone*)malloc(psiz); memset(zone, 0, psiz); zone->footstep_len = (unsigned short)(flen); zone->ambient_len = (unsigned short)(alen); zone->camera_len = (unsigned char)(clen); if (flen != 0) memcpy(zone->str_data, footstep, flen); if (alen != 0) memcpy(zone->str_data + flen, ambient, alen); if (clen != 0) memcpy(zone->str_data + flen + alen, camera, clen); return zone; } /** * Prepares an initialized zone structure to be built in the world. * * After calling this function use either the aw_object_add or * aw_object_load SDK methods after setting additional attributes * defining the zone location, etc. * * @param zone The zone to be built. */ void prepare_zone(const aw_object_data_zone* zone) { unsigned int psiz = 0; psiz = sizeof(aw_object_data_zone); psiz += zone->footstep_len; psiz += zone->ambient_len; psiz += zone->camera_len; aw_string_set(AW_OBJECT_DESCRIPTION, ""); aw_string_set(AW_OBJECT_ACTION, ""); aw_int_set(AW_OBJECT_TYPE, AW_OBJECT_TYPE_ZONE); aw_data_set(AW_OBJECT_DATA, (char*)(zone), psiz); }