Пример #1
0
 void my_init(void)
 {
   my_fthing0 = create_thing(0);
   my_fthing1 = create_thing(1);
   my_fthing2 = create_thing(2);
 }
Пример #2
0
int main() {
    struct thing t;
    char buf[500];
    char waypoint[50];
    //initialize(access_key, secret_key)
    initialize("1d2fb5c369863fd54afafde654c26dtd51122t8e", "f4e31122629etaeaa48d9c8c72b8cctfc9d63acc");
    //create_thing(struct thing *thing, char* key, char* name, char* description, instruction_handler handler)
    create_thing(&t, "6eattba747", "LivingRoom", "Example LivingRoom", execute_instruction);

    int response = 0;
    response = connect_datonis();
    if (response != ERR_OK) {
        fprintf(stderr, "Failed to connect to Datonis!\n");
        exit(1);
    }

    // Thing registration is optional to send event.
    /*response = register_thing(&t);
    if (response != ERR_OK) {
        fprintf(stderr, "Failed to Register Thing. Response Code: %d, Error: %s\n", response, get_error_code_message(response));
        exit(1);
    } else {
        printf("Successfully Registered thing with Datonis!\n");
    }*/

    if (1) {
        send_example_alerts(&t);
    }

    int counter = 5;
    while(1) {

        if (counter == 5) {
            transmit_heartbeat_to_datonis(&t);
            counter = 0;
        }
        counter++;

        yield(2000);
        yield(2000);

        sprintf(buf, "{\"temperature\":%ld,\"humidity\":%ld}", random(), random());
	//waypoint format: [latitude, longitude], where latitude and longitude must be double values.	
	sprintf(waypoint, "[19.%ld,73.%ld]", random() % 100000, random() % 100000);

        /* You can send data to Datonis in a compressed form.
         * This not only reduces the network bandwidth usage for your agent
         * But also improves network latency to the Datonis server
         * This happens at the cost of some extra processing power needed on the device
         * You can still chose to send data in a uncompressed form
         */
	//You can send both meta-data as well as waypoint in single request.
	//Pass NULL in place of buf or waypoint if you don't want to send that data.
	//Atleast one from buf or waypoint should be passed. Both cannot be NULL.
	response = transmit_compressed_thing_data(&t, buf, NULL);
	//response = transmit_compressed_thing_data(&t, NULL, waypoint);
	//response = transmit_compressed_thing_data(&t, buf, waypoint);
	
        /* Uncomment to send data in an uncompressed way */
        // response = transmit_thing_data(&t, buf, waypoint);

        if (response != ERR_OK) {
            fprintf(stderr, "Failed to send thing data. Response Code: %d, Error: %s\n", response, get_error_code_message(response));
        } else {
            printf("Transmitt Data Response: %d\n", response);
        }
        sleep(5);
    }

    return 0;
}
Пример #3
0
short thing_create_thing(struct InitThing *itng)
{
    struct Thing *thing;
    if (itng->owner == 7)
    {
        ERRORLOG("Invalid owning player %d, fixing to %d", (int)itng->owner, (int)game.hero_player_num);
        itng->owner = game.hero_player_num;
    } else
    if (itng->owner == 8)
    {
        ERRORLOG("Invalid owning player %d, fixing to %d", (int)itng->owner, (int)game.neutral_player_num);
        itng->owner = game.neutral_player_num;
    }
    if (itng->owner > 5)
    {
        ERRORLOG("Invalid owning player %d, thing discarded", (int)itng->owner);
        return false;
    }
    switch (itng->oclass)
    {
    case TCls_Object:
        thing = create_thing(&itng->mappos, itng->oclass, itng->model, itng->owner, itng->index);
        if (!thing_is_invalid(thing))
        {
            if (itng->model == 49) //HERO_GATE
                thing->byte_13 = itng->params[1];
            check_and_asimilate_thing_by_room(thing);
            // make sure we don't have invalid pointer
            thing = INVALID_THING;
        } else
        {
            ERRORLOG("Couldn't create object model %d", (int)itng->model);
            return false;
        }
        break;
    case TCls_Creature:
        thing = create_creature(&itng->mappos, itng->model, itng->owner);
        if (thing_is_invalid(thing))
        {
            ERRORLOG("Couldn't create creature model %d", (int)itng->model);
            return false;
        }
        init_creature_level(thing, itng->params[1]);
        break;
    case TCls_EffectGen:
        thing = create_effect_generator(&itng->mappos, itng->model, itng->range, itng->owner, itng->index);
        if (thing_is_invalid(thing))
        {
            ERRORLOG("Couldn't create effect generator model %d", (int)itng->model);
            return false;
        }
        break;
    case TCls_Trap:
        thing = create_thing(&itng->mappos, itng->oclass, itng->model, itng->owner, itng->index);
        if (thing_is_invalid(thing))
        {
            ERRORLOG("Couldn't create trap model %d", (int)itng->model);
            return false;
        }
        break;
    case TCls_Door:
        thing = create_door(&itng->mappos, itng->model, itng->params[0], itng->owner, itng->params[1]);
        if (thing_is_invalid(thing))
        {
            ERRORLOG("Couldn't create door model %d", (int)itng->model);
            return false;
        }
        break;
    case 10:
    case 11:
        thing = create_thing(&itng->mappos, itng->oclass, itng->model, itng->owner, itng->index);
        if (thing_is_invalid(thing))
        {
            ERRORLOG("Couldn't create thing class %d model %d", (int)itng->oclass, (int)itng->model);
            return false;
        }
        break;
    default:
        ERRORLOG("Invalid class %d, thing discarded", (int)itng->oclass);
        return false;
    }
    return true;
}
Пример #4
0
// keys_edit: Keys for the 2d editor
// ------------------------------ >>
void keys_edit()
{
    if (!map.opened)
        return;

    // Scroll up
    if (binds.pressed("view_up"))
    {
        yoff += ((MAJOR_UNIT / (int)zoom)) + 1;
        force_map_redraw(true, true);
    }

    // Scroll down
    if (binds.pressed("view_down"))
    {
        yoff -= ((MAJOR_UNIT / (int)zoom)) + 1;
        force_map_redraw(true, true);
    }

    // Scroll left
    if (binds.pressed("view_left"))
    {
        xoff += ((MAJOR_UNIT / (int)zoom)) + 1;
        force_map_redraw(true, true);
    }

    // Scroll right
    if (binds.pressed("view_right"))
    {
        xoff -= ((MAJOR_UNIT / (int)zoom)) + 1;
        force_map_redraw(true, true);
    }

    // Zoom in
    if (binds.pressed("view_zoomin"))
        view_zoom(true);

    // Zoom out
    if (binds.pressed("view_zoomout"))
        view_zoom(false);

    // Center view on mouse
    if (binds.pressed("view_mousecenter"))
    {
        xoff = -m_x(mouse.x) / MAJOR_UNIT;
        yoff = -m_y(mouse.y) / MAJOR_UNIT;
        force_map_redraw(true, true);
    }

    // Set offsets to 0, 0
    if (binds.pressed("view_origin"))
    {
        xoff = yoff = 0;
        force_map_redraw(true, true);
    }

    // Vertices mode
    if (binds.pressed("mode_vertices"))
        change_edit_mode(0);

    // Linedefs mode
    if (binds.pressed("mode_linedefs"))
        change_edit_mode(1);

    // Sectors mode
    if (binds.pressed("mode_sectors"))
        change_edit_mode(2);

    // Things mode
    if (binds.pressed("mode_things"))
        change_edit_mode(3);

    // Change mode
    if (binds.pressed("mode_change"))
        cycle_edit_mode();

    // Increase grid size
    if (binds.pressed("view_increasegrid"))
    {
        increase_grid();
        force_map_redraw(false, true);
    }

    // Decrease grid size
    if (binds.pressed("view_decreasegrid"))
    {
        decrease_grid();
        force_map_redraw(false, true);
    }

    // Clear selection
    if (binds.pressed("edit_clearselection"))
    {
        clear_selection();
        force_map_redraw(true);
    }

    // Delete item
    if (binds.pressed("edit_deleteitem"))
    {
        if (edit_mode == 0)
            delete_vertex();

        if (edit_mode == 1)
            delete_line();

        if (edit_mode == 2)
            delete_sector();

        if (edit_mode == 3)
            delete_thing();

        force_map_redraw(true);
    }

    // Create item
    if (binds.pressed("edit_createitem"))
    {
        if (edit_mode == 0)
        {
            if (!selection())
                create_vertex();
            else
                create_lines(false);

            force_map_redraw(true);
            return;
        }

        if (edit_mode == 1)
        {
            if (selection())
                create_sector();

            force_map_redraw(true);
            return;
        }

        if (edit_mode == 3)
        {
            create_thing();
            force_map_redraw(true);
            return;
        }

        binds.clear("edit_createitem");
    }

    // Sector height quick changes (8 units)
    if (binds.pressed("sector_upfloor8"))
    {
        if (edit_mode == 2)
            sector_changeheight(true, 8);
    }

    if (binds.pressed("sector_downfloor8"))
    {
        if (edit_mode == 2)
            sector_changeheight(true, -8);
    }

    if (binds.pressed("sector_upceil8"))
    {
        if (edit_mode == 2)
            sector_changeheight(false, 8);
    }

    if (binds.pressed("sector_downceil8"))
    {
        if (edit_mode == 2)
            sector_changeheight(false, -8);
    }

    if (binds.pressed("sector_upboth8"))
    {
        if (edit_mode == 2)
        {
            sector_changeheight(true, 8);
            sector_changeheight(false, 8);
        }
    }

    if (binds.pressed("sector_downboth8"))
    {
        if (edit_mode == 2)
        {
            sector_changeheight(true, -8);
            sector_changeheight(false, -8);
        }
    }

    // Sector height quick changes (1 unit)
    if (binds.pressed("sector_upfloor"))
    {
        if (edit_mode == 2)
            sector_changeheight(true, 1);
    }

    if (binds.pressed("sector_downfloor"))
    {
        if (edit_mode == 2)
            sector_changeheight(true, -1);
    }

    if (binds.pressed("sector_upceil"))
    {
        if (edit_mode == 2)
            sector_changeheight(false, 1);
    }

    if (binds.pressed("sector_downceil"))
    {
        if (edit_mode == 2)
            sector_changeheight(false, -1);
    }

    if (binds.pressed("sector_upboth"))
    {
        if (edit_mode == 2)
        {
            sector_changeheight(true, 1);
            sector_changeheight(false, 1);
        }
    }

    if (binds.pressed("sector_downboth"))
    {
        if (edit_mode == 2)
        {
            sector_changeheight(true, -1);
            sector_changeheight(false, -1);
        }
    }

    // Flip line
    if (binds.pressed("line_flip"))
    {
        if (edit_mode == 1)
            line_flip(true, false);

        force_map_redraw(true);
    }

    // Swap line sides
    if (binds.pressed("line_swapsides"))
    {
        if (edit_mode == 1)
            line_flip(false, true);

        force_map_redraw(true);
    }

    // Flip both line direction and sides
    if (binds.pressed("line_flipboth"))
    {
        if (edit_mode == 1)
            line_flip(true, true);

        force_map_redraw(true);
    }

    // Begin line draw
    if (binds.pressed("line_begindraw"))
    {
        if (!line_draw)
            line_draw = true;

        binds.clear("line_begindraw");
    }

    // Begin rectangle draw
    if (binds.pressed("line_begindraw_rect"))
    {
        if (!line_draw)
        {
            line_draw = true;
            sel_box.set(mouse.x, mouse.y, mouse.x, mouse.y);
        }

        binds.clear("line_begindraw_rect");
    }

    // Undo
    if (binds.pressed("edit_undo"))
    {
        undo();
        clear_selection();
        hilight_item = -1;
        force_map_redraw(true, true);
        //map_changelevel(3);
        map.change_level(MC_NODE_REBUILD);
        binds.clear("edit_undo");
    }

    // Edit item
    if (binds.pressed("edit_edititem"))
    {
        edit_item();
        binds.clear("edit_edititem");
    }

    // Merge sectors
    if (binds.pressed("sector_merge"))
    {
        sector_merge(false);
        binds.clear("sector_merge");
    }

    // Join sectors
    if (binds.pressed("sector_join"))
    {
        sector_merge(true);
        binds.clear("sector_join");
    }

    if (binds.pressed("view_3dmode"))
    {
        binds.clear("view_3dmode");
        binds.clear("3d_exit");
        start_3d_mode();
    }

    if (binds.pressed("open_console"))
    {
        binds.clear("open_console");
        popup_console();
    }

    if (binds.pressed("copy"))
    {
        binds.clear("copy");
        clipboard.Copy();
    }

    if (binds.pressed("paste"))
    {
        binds.clear("paste");
        paste_mode = true;
        clear_selection();
    }

    if (binds.pressed("cancel_paste"))
    {
        binds.clear("cancel_paste");
        paste_mode = false;
        force_map_redraw(true, false);
    }
}