Example #1
0
void controlObject(struct Creature *go)
{
	controlled = go;
	
	action_create(&move_act, ACT_MOVE);
	
	struct ActionObject* user;
	action_obj_create(&user, ACT_OBJ_CREATURE);
	user->creature = controlled;
	action_add(move_act, user, ACT_ROLE_USER);
	
	struct ActionObject* mag;
	action_obj_create(&mag, ACT_OBJ_FLOAT);
	mag->fvalue = 5.0f;
	action_add(move_act, mag, ACT_ROLE_MAGNITUDE);
	
	action_obj_create(&move_angle, ACT_OBJ_FLOAT);
	move_angle->fvalue = 0.0f;
	action_add(move_act, move_angle, ACT_ROLE_ANGLE);
	
	// make sure it's disabled at the start
	action_add_subtype(move_act, SACT_DISABLED);
	
	game_add_action(&(mainGame->acts), move_act);
}
Example #2
0
int cmd_add(int argc, char **argv, char * daz) {
        int f_date = -1,
            f_compound = -1,
            f_dz = -1,
            f_type = -1,
            f_input = -1;
        char *type_args = NULL;

        if (argc < 0) {
                printf("error no args for add\n");
                return -1;
        }

        argc = check_option_add(argc, argv, &f_date, &f_compound, &f_dz,
                        &f_type, &f_input);

        if (f_type >= 0) {
                type_args = (char *) malloc(sizeof(*type_args)* argc);
                char *tmp = argv[f_type];
                if (f_type < (argc -1)) {
                        /* deleted type args in argv*/
                        int i;
                        for (i = (f_type + 1); i < (argc); i++) {
                                argv[i-1] = argv[i];
                        }
                        /* shift flag if it after type args */
                        f_date  = (f_date > f_type ? f_date -1 : f_date);
                        f_compound = (f_compound > f_type ? f_compound-1 :
                                        f_compound);
                        f_input = (f_input > f_type ? f_input-1 : f_input);
                        f_dz = (f_dz > f_type ? f_dz-1 : f_dz);
                }
                argc--;
                if (check_type_args(argc, type_args, tmp, f_dz) < 0) {
                        printf("check_args_no_op failed\n");
                        free(type_args);
                        return -1;
                }
        } else if ( argc > (f_dz >= 0 ? 1:0) + (f_input >= 0 ? 1:0)) {
                printf("check_type_args failed\n");
                return -1;
        }

        if (check_args(argc, argv, &f_dz, &f_compound, &f_date)) {
                printf("check path args failed\n");
                return -1;
        }

        if (action_add(argc, argv, f_compound, f_dz, f_date, f_input,
                type_args, daz) == -1) {
                printf("error action add\n");
                return -1;
        }
        if (f_type >= 0) {
                free(type_args);
        }
        return 0;
}
Example #3
0
void trace_tree_emit_rule(struct xswitch *sw, struct trace_tree *tree)
{
	struct match *ma = match();
	struct action *ac_pi = action();
	action_add(ac_pi, AC_PACKET_IN, 0);
	emit_rule(sw, sw->table0, tree, ma, 1, ac_pi);
	action_free(ac_pi);
	match_free(ma);
}
Example #4
0
static int json_printer_ft1(char *buf, int pos, struct trace_tree *tree)
{
	int i;
	int priority;
	struct trace_tree_V *tv;
	struct trace_tree_T *tt;
	struct trace_tree_D *td;
	struct trace_tree_G *tg;
	struct match *ma;
	struct action *ac_pi;

	switch(tree->type) {
	case TT_L:
	case TT_E:
		return pos;
	case TT_D:
		td = (struct trace_tree_D *)tree;
		return json_printer_ft1(buf, pos, td->t);
	case TT_V:
		tv = (struct trace_tree_V *)tree;
		for(i = 0; i < tv->num_branches; i++) {
			pos = json_printer_ft1(buf, pos, tv->branches[i].tree);
		}
		return pos;
	case TT_T:
		tt = (struct trace_tree_T *)tree;
		pos = json_printer_ft1(buf, pos, tt->f);
		pos = json_printer_ft1(buf, pos, tt->t);
		return pos;
	case TT_G:
		tg = (struct trace_tree_G *)tree;
		priority = 0;
		ac_pi = action();
		action_add(ac_pi, AC_PACKET_IN, 0);
		ma = match();
		pos += sprintf(buf+pos, "{\"tid\":\"%d\",", flow_table_get_tid(tg->ft));
		pos += sprintf(buf+pos, "\"columns\":[\"priority\",\"in_port\",");
		pos += header_print_json(tg->new_spec, buf+pos);
		if(buf[pos-1] == ',')
			pos--;
		pos += sprintf(buf+pos, ",\"actions\"],");
		pos += sprintf(buf+pos, "\"data\":[");
		pos = json_printer_ft(buf, pos, tg->t, ma, &priority, ac_pi, tg->new_spec);
		if(buf[pos-1] == ',')
			pos--;
		pos += sprintf(buf+pos, "]},");
		action_free(ac_pi);
		match_free(ma);
		pos = json_printer_ft1(buf, pos, tg->t);
		return pos;
	}
	assert(0);
}
Example #5
0
static int conf_add_action(const char *rel, const char *full) {
  char *cmd;

  cmd = read_data_string(full);
  if(!cmd) {
    parse_error(full,"unable to read data",xsyserr());
    return -1;
  }

  action_add(ActionShell, rel, cmd);

  free(cmd);
  return 0;
}
Example #6
0
/* helper */
static void init_entry(struct xswitch *sw, struct flow_table *ft)
{
	struct match *ma;
	struct msgbuf *msg;
	struct action *ac;
	int index;
	ma = match();
	ac = action();
	action_add(ac, AC_PACKET_IN, 0);
	index = flow_table_get_entry_index(ft);
	assert(index == 0);
	msg = msg_flow_entry_add(ft, index, 0, ma, ac);
	match_free(ma);
	action_free(ac);
	xswitch_send(sw, msg);
}
Example #7
0
void generateLevel(struct TileElement** tiles, int num_tiles, struct CreatureElement** creatures, int num_creatures, struct ActionElement** actions)
{
	int curr = 0;
	srand(time(NULL));
	fprintf(stderr, "rnd: %i\n", rand());
	fprintf(stderr, "rnd2: %f\n", (float)rand()/(float)RAND_MAX);
	
	/*
	struct Room r1;
	r1.pos.x = 1;
	r1.pos.y = 2;
	r1.dim.x = 5;
	r1.dim.y = 6;
	curr += addRoom(tiles, r1, curr);
	
	
	struct Room r2;
	r2.pos.x = 8;
	r2.pos.y = 3;
	r2.dim.x = 4;
	r2.dim.y = 7;
	
	curr += addRoom(tiles, r2, curr);
	*/
	//struct Room path;
	/*
	while (curr < num_tiles)
	{
		struct Tile t;
		t.pos.x = curr;
		t.pos.y = curr;
		tiles[curr] = t;
		++curr;
	}*/
	
	
	struct CaveRoom cr1;
	struct CaveRoomGenerator caveGen;
	gen_cave_gen(&caveGen, 
		7, 
		8, 
		7, 7, 
		9, 9, 
		4, 4, 
		6, 6, 
		0, M_PI*2);

	//create_cave_room(&cr1, 0, 0, 7, 2.0f, 3, 2, 4, 5);
	gen_cave_room(&cr1, caveGen);
	gen_exits(&cr1);
	struct CaveRoom cr2;
	cave_branch(&cr1, &caveGen, &cr2);
	addCaveRoom(tiles, &cr1, curr);
	//pos_print(cr2.origin);
	addCaveRoom(tiles, &cr2, curr);
	
	
	
	struct Creature *creat = malloc(sizeof(*creat));
	creature_create(creat, TYP_GAS_BALL);
	creat->pos.x = 2;
	creat->pos.y = 4;
	creature_add_sub_type(creat, STYP_EXISTS);
	game_add_creature(creatures, creat);
	
	struct Creature *bj = malloc(sizeof(*bj));
	creature_create(bj, TYP_BLUE_JELLY);
	bj->pos.x = 4;
	bj->pos.y = 4;
	creature_add_sub_type(bj, STYP_EXISTS);
	game_add_creature(creatures, bj);
	
	bj->items = malloc(sizeof(*bj->items));
	bj->items->next = NULL;
	bj->items->elem = malloc(sizeof(*bj->items->elem));
	item_create(bj->items->elem, ITM_BLUE_JELLY);
	
	struct Action* follow_act;
	action_create(&follow_act, ACT_FOLLOW);
	
	struct ActionObject* user;
	action_obj_create(&user, ACT_OBJ_CREATURE);
	user->creature = mainGame->player;
	action_add(follow_act, user, ACT_ROLE_USER);
	
	struct ActionObject* creatActObj;
	action_obj_create(&creatActObj, ACT_OBJ_CREATURE);
	creatActObj->creature = creat;
	action_add(follow_act, creatActObj, ACT_ROLE_TARGET);
	
	struct ActionObject* mag;
	action_obj_create(&mag, ACT_OBJ_FLOAT);
	mag->fvalue = 1.0f;
	action_add(follow_act, mag, ACT_ROLE_MAGNITUDE);
	
	// make sure it's disabled at the start
	//action_add_subtype(follow_act, SACT_DISABLED);
	
	game_add_action(actions, follow_act);
	
	struct TileElement* currTile = *tiles;
	while(currTile != NULL)
	{
		tile_make_walls(*tiles, currTile->elem);
		currTile = currTile->next;
	}
	
};
pointArrayValueItem::pointArrayValueItem( pointArray* point_array, unsigned int idx, pointArrayValue* parent ): QWidget( parent ){
	if( !icons_loaded ){
		icon_up.addFile( ":/edit/move_up.png" );
		icon_down.addFile( ":/edit/move_down.png" );
		icon_add.addFile( ":/edit/add.png" );
		icon_remove.addFile( ":/edit/remove.png" );
		icons_loaded = true;
	}
	
	points = point_array;
	index = idx;
	container = parent;
	
	setAttribute( Qt::WA_DeleteOnClose );
	
	//Create widget
	QHBoxLayout* layout = new QHBoxLayout( this );
	layout->setContentsMargins( 0, 0, 0, 0 );
	
	//Add move buttons
	if( points && !points->get_keep_sorted() ){
		QPushButton *btn_down = new QPushButton( this );
		QPushButton *btn_up = new QPushButton( this );
		
		btn_up->setIcon( icon_up );
		btn_down->setIcon( icon_down );
		btn_up->setIconSize( icon_size );
		btn_down->setIconSize( icon_size );
		btn_up->setSizePolicy( fixed_policy );
		btn_down->setSizePolicy( fixed_policy );
		connect( btn_up, SIGNAL( clicked() ), this, SLOT( action_move_up() ) );
		connect( btn_down, SIGNAL( clicked() ), this, SLOT( action_move_down() ) );
		
		layout->addWidget( btn_up );
		layout->addWidget( btn_down );
	}
	
	//Add spinboxes
	sbx_x = new QSpinBox( this );
	sbx_y = new QSpinBox( this );
	sbx_x->setMaximum( 65535 );
	sbx_y->setMaximum( 65535 );
	layout->addWidget( sbx_x );
	layout->addWidget( sbx_y );
	
	//Add add/remove buttons
	QPushButton *btn_add = new QPushButton( this );
	btn_add->setIcon( icon_add );
	btn_add->setIconSize( icon_size );
	btn_add->setSizePolicy( fixed_policy );
	layout->addWidget( btn_add );
	connect( btn_add, SIGNAL( clicked() ), this, SLOT( action_add() ) );
	
	QPushButton *btn_remove = new QPushButton( this );
	btn_remove->setIcon( icon_remove );
	btn_remove->setIconSize( icon_size );
	btn_remove->setSizePolicy( fixed_policy );
	layout->addWidget( btn_remove );
	connect( btn_remove, SIGNAL( clicked() ), this, SLOT( action_remove() ) );
	
	//Update spinboxes
	if( points ){
		const point *item = points->index( index );
		if( item ){
			sbx_x->setValue( item->X );
			sbx_y->setValue( item->Y );
			
			connect( sbx_x, SIGNAL( valueChanged(int) ), this, SLOT( action_x_changed() ) );
			connect( sbx_y, SIGNAL( valueChanged(int) ), this, SLOT( action_y_changed() ) );
			
			return;
		}
	}
	
	//Something went wrong, disable the widget!
	setEnabled( false );
}
Example #9
0
TApiStatus GenerateFilters(TNetworkElement* element)
{
    TApiStatus s;
    onep_status_t rc;
    onep_collection_t* tables = NULL;
    onep_policy_table_cap_t* table_cap = 0;
    onep_policy_pmap_op_t* pmap_op = NULL;
    onep_policy_op_list_t* pmap_op_list = NULL;
    onep_policy_op_list_t* cmap_op_list = NULL;
    int cmap_counter = 0;

    // Get traffic action table
    rc = router_get_table(element->ne, &tables, &table_cap);
    if(rc != ONEP_OK) {
        PrintErrorMessage("GenerateFilters", "action table");
        return API_ERROR;
    }

    // Init policy map
    policy_map_begin(
        element->ne,
        table_cap,
        &pmap_op_list,
        &pmap_op
    );

    // Create class map for every filter item
    unsigned entry_number = 100;
    TFilterItem* filter = FilterList.head;
    while(filter != NULL)
    {
        TFilterData* data = filter->data;

        onep_policy_entry_op_t *entry_op;

        // Add entry to policy map
        policy_map_add_entry(
            table_cap,
            pmap_op,
            entry_number,
            &entry_op
        );
        entry_number++;

        // Add rules
        onep_policy_op_list_t *cmap_op_list = NULL;
        onep_policy_cmap_op_t *cmap_op = NULL;
        onep_policy_match_holder_t *mh = NULL;

        // Begin class map
        class_map_begin(
            element->ne,
            table_cap,
            ONEP_POLICY_CMAP_ATTR_MATCH_ALL,
            entry_op,
            "onep-tahoe-cmap-1",                        // TODO
            &cmap_op_list,
            &cmap_op,
            &mh
        );

        // Add ACL
        onep_acl_t* acl = NULL;
        s = GenerateALC(element, data, &acl);
        if(s != API_OK)
        {
            PrintErrorMessage("GenerateFilters", "ACL");
            return API_ERROR;
        }

        if(acl != NULL)
        {
            class_map_add_acl(
                mh,
                (onep_policy_access_list_t *)acl
            );
        }


        // L7 protocol
        char* proto_str = NULL;
        if(data->protocol != NONE)
        {
            s = L7ProtocolToString(data->protocol, &proto_str);
            if(s != API_OK)
            {
                PrintErrorMessage("GenerateFilters", "protocol string");
                return API_ERROR;
            }

            class_map_add_l7_protocol(
                mh,
                proto_str
            );
        }

        // Class map finish
        class_map_finish(
            table_cap,
            cmap_op_list,
            cmap_op,
            &entry_op
        );

        // Add action
        action_add(
            entry_op,
            //ONEP_DPSS_ACTION_DIVERT,
            ONEP_DPSS_ACTION_COPY,
            FilterList.callback
        );

        cmap_counter++;
        filter = filter->next;
    }

    // Try to set policy map persistent with name
    policy_map_try_set_persistent(
        table_cap,
        pmap_op,
        "onep-tahoe-pmap"
    );

    // Finish policy map
    policy_map_finish(
        pmap_op,
        pmap_op_list,
        &(FilterList.pmap_handle)
    );

    // Clean up
    if(cmap_op_list) {
        rc = onep_policy_op_list_destroy(&cmap_op_list);
        if(rc != ONEP_OK) {
            // Warning only
            PrintErrorMessage("GenerateFilters", "Destroy: cmap_op_list");
        }
    }
    if(pmap_op_list) {
        rc = onep_policy_op_list_destroy(&pmap_op_list);
        if(rc != ONEP_OK) {
            // Warning only
            PrintErrorMessage("GenerateFilters", "Destroy: cmap_op_list");
        }
    }

    return API_OK;
}