Пример #1
0
void TWCloudDrift::check_velocities(int time)
{
    if(debug_enabled()) debug_printf(DL_DEBUG, "Updating velocity");

    // Obtain the current location and velocity
    SService<IObjectSrv> obj_srv(g_pScriptManager);
    cScrVec position;
    obj_srv -> Position(position, ObjId());

	SService<IPhysSrv> phys_srv(g_pScriptManager);
    cScrVec velocity;
    phys_srv -> GetVelocity(ObjId(), velocity);

    // And the initial location
    const mxs_vector *location = start_position;

    // Recalculate any velocities that need changing
    if(driftrange.x && minrates.x && maxrates.x)
        velocity.x = calculate_velocity(location -> x, driftrange.x, minrates.x, maxrates.x, position.x, velocity.x);

    if(driftrange.y && minrates.y && maxrates.y)
        velocity.y = calculate_velocity(location -> y, driftrange.y, minrates.y, maxrates.y, position.y, velocity.y);

    if(driftrange.z && minrates.z && maxrates.z)
        velocity.z = calculate_velocity(location -> z, driftrange.z, minrates.z, maxrates.z, position.z, velocity.z);

    phys_srv -> SetVelocity(ObjId(), velocity);

    if(debug_enabled())
        debug_printf(DL_DEBUG, "Pos/Vel,%d,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f", time, position.x, position.y, position.z, velocity.x, velocity.y, velocity.z);

    // This shouldn't be needed, but check anyway
    if(update_timer) {
        cancel_timed_message(update_timer);
    }

    // And schedule the next update.
    update_timer = set_timed_message("CheckVelocity", refresh, kSTM_OneShot);
}
Пример #2
0
void log_hex(fr_log_t const *log, fr_log_type_t type, fr_log_lvl_t lvl, uint8_t const *data, size_t data_len)
{
	size_t i, j, len;
	char *p;
	char buffer[(0x10 * 3) + 1];

	if (!debug_enabled(L_DBG, lvl)) return;

	for (i = 0; i < data_len; i += 0x10) {
		len = 0x10;
		if ((i + len) > data_len) len = data_len - i;

		for (p = buffer, j = 0; j < len; j++, p += 3) sprintf(p, "%02x ", data[i + j]);
		fr_log(log, type, "%04x: %s", (int)i, buffer);
	}
}
Пример #3
0
void TWBaseScript::init(int time)
{
    char* design_note = GetObjectParams(ObjId());

    if(design_note) {
        debug = get_scriptparam_bool(design_note, "Debug");

        if(debug_enabled()) {
            debug_printf(DL_DEBUG, "Attached %s version %s", Name(), SCRIPT_VERSTRING);
            debug_printf(DL_DEBUG, "Script debugging enabled");
        }

        g_pMalloc -> Free(design_note);
    }

    // Set up randomisation
    uint seed = std::chrono::system_clock::now().time_since_epoch().count();
    randomiser.seed(seed);
}
Пример #4
0
void TWCloudDrift::init(int time)
{
    TWBaseScript::init(time);

    // Fetch the initial position if needed
    if(!start_position.Valid()) {
        fetch_initial_location();

        if(debug_enabled()) {
            const mxs_vector *location = start_position;
            debug_printf(DL_WARNING, "Initial location: %f, %f, %f", location -> x, location -> y, location -> z);
        }
    }

    // Fetch the contents of the object's design note
    char *design_note = GetObjectParams(ObjId());
    if(!design_note) {
        debug_printf(DL_WARNING, "No Editor -> Design Note. Doing nothing.");

    } else {

        // Nothing can be done if there's no drift setting
        if(get_scriptparam_floatvec(design_note, "Range", driftrange)) {
            // Drifts must be positive. Divide by two so the range is relative to the start pos.
            driftrange.x = fabs(driftrange.x) / 2.0;
            driftrange.y = fabs(driftrange.y) / 2.0;
            driftrange.z = fabs(driftrange.z) / 2.0;

            // And there needs to be actual drift
            if(driftrange) {
                const mxs_vector *location = start_position;

                get_scriptparam_floatvec(design_note, "MaxRate", maxrates, 0.5, 0.5, 0.5);
                get_scriptparam_floatvec(design_note, "MinRate", minrates, 0.05, 0.05, 0.05);

                std::string dummy;
                refresh = get_scriptparam_time(design_note, "Refresh", 1000, dummy);

                char *facmode = get_scriptparam_string(design_note, "Mode");
                if(facmode) {
                    if(!::_stricmp(facmode, "LINEAR")) {
                        factormode = LINEAR;
                    } else if(!::_stricmp(facmode, "LOG")) {
                        factormode = LOGARITHMIC;
                    }

                    g_pMalloc -> Free(facmode);
                }

                // Dump the settings for reference
                if(debug_enabled()) {
                    debug_printf(DL_DEBUG, "Initialised on object. Settings:");
                    debug_printf(DL_DEBUG, "Initial location: (%.3f, %.3f, %.3f)", location -> x, location -> y, location -> z);
                    debug_printf(DL_DEBUG, "Drift amount: (%.3f, %.3f, %.3f)"    , driftrange.x * 2.0, driftrange.y * 2.0, driftrange.z * 2.0);
                    debug_printf(DL_DEBUG, "Minimum rate: (%.3f, %.3f, %.3f)"    , minrates.x , minrates.y , minrates.z);
                    debug_printf(DL_DEBUG, "Maximum rate: (%.3f, %.3f, %.3f)"    , maxrates.x , maxrates.y , maxrates.z);
                    debug_printf(DL_DEBUG, "Update mode: %d", factormode);
                    debug_printf(DL_DEBUG, "Update rate: %d", refresh);
                }

                // Check the velocities and start the refresh timer.
                check_velocities(time);

            // All drift values are zero, there's no point in doing anything
            } else {
                debug_printf(DL_WARNING, "All Drift values are zero. Doing nothing.");
            }

        // Can't do anything if there is no drift information
        } else {
            debug_printf(DL_WARNING, "No Drift specified. Doing nothing.");
        }

        g_pMalloc -> Free(design_note);
    }
}
Пример #5
0
int TWBaseScript::get_linked_object(const int from, const std::string& obj_name, const std::string& link_name, const int fallback)
{
    SInterface<IObjectSystem> ObjectSys(g_pScriptManager);
    SService<IObjectSrv>      ObjectSrv(g_pScriptManager);
    SService<ILinkSrv>        LinkSrv(g_pScriptManager);
    SService<ILinkToolsSrv>   LinkToolsSrv(g_pScriptManager);

    // Can't do anything if there is no archytype name set
    if(!obj_name.empty()) {

        // Attempt to locate the object requested
        int object = StrToObject(obj_name.c_str());
        if(object) {

            // Convert the link to a liny type ID
            long flavourid = LinkToolsSrv -> LinkKindNamed(link_name.c_str());

            if(flavourid) {
                // Does the object have a link of the specified flavour?
                true_bool has_link;
                LinkSrv -> AnyExist(has_link, flavourid, from, 0);

                // Only do anything if there is at least one particle attachment.
                if(has_link) {
                    linkset links;
                    true_bool inherits;

                    // Check all the links of the appropriate flavour, looking for a link either to
                    // the named object, or to an object that inherits from it
                    LinkSrv -> GetAll(links, flavourid, from, 0);
                    while(links.AnyLinksLeft()) {
                        sLink link = links.Get();

                        // If the object is an archetype, check whether the destination inherits from it.
                        if(object < 0) {
                            ObjectSrv -> InheritsFrom(inherits, link.dest, object);

                            // Found a link from a concrete instance of the archetype? Return that object.
                            if(inherits) {
                                return link.dest;
                            }

                        // If the target object is concrete, is the link to that object?
                        } else if(link.dest == object) {
                            return link.dest;
                        }

                        links.NextLink();
                    }

                    if(debug_enabled())
                        debug_printf(DL_WARNING, "Object has no %s link to a object named or inheriting from %s", link_name.c_str(), obj_name.c_str());
                }
            } else {
                debug_printf(DL_ERROR, "Request for non-existent link flavour %s", link_name.c_str());
            }
        } else if(debug_enabled()) {
            debug_printf(DL_WARNING, "Unable to find object named '%s'", obj_name.c_str());
        }
    } else {
        debug_printf(DL_ERROR, "obj_name name is empty.");
    }

    return fallback;
}