Esempio n. 1
0
void
group_create_actions(resource_t * rsc, pe_working_set_t * data_set)
{
    action_t *op = NULL;
    const char *value = NULL;
    GListPtr gIter = rsc->children;

    pe_rsc_trace(rsc, "Creating actions for %s", rsc->id);

    for (; gIter != NULL; gIter = gIter->next) {
        resource_t *child_rsc = (resource_t *) gIter->data;

        child_rsc->cmds->create_actions(child_rsc, data_set);
        group_update_pseudo_status(rsc, child_rsc);
    }

    op = start_action(rsc, NULL, TRUE /* !group_data->child_starting */ );
    set_bit(op->flags, pe_action_pseudo | pe_action_runnable);

    op = custom_action(rsc, started_key(rsc),
                       RSC_STARTED, NULL, TRUE /* !group_data->child_starting */ , TRUE, data_set);
    set_bit(op->flags, pe_action_pseudo | pe_action_runnable);

    op = stop_action(rsc, NULL, TRUE /* !group_data->child_stopping */ );
    set_bit(op->flags, pe_action_pseudo | pe_action_runnable);

    op = custom_action(rsc, stopped_key(rsc),
                       RSC_STOPPED, NULL, TRUE /* !group_data->child_stopping */ , TRUE, data_set);
    set_bit(op->flags, pe_action_pseudo | pe_action_runnable);

    value = g_hash_table_lookup(rsc->meta, "stateful");
    if (crm_is_true(value)) {
        op = custom_action(rsc, demote_key(rsc), RSC_DEMOTE, NULL, TRUE, TRUE, data_set);
        set_bit(op->flags, pe_action_pseudo);
        set_bit(op->flags, pe_action_runnable);
        op = custom_action(rsc, demoted_key(rsc), RSC_DEMOTED, NULL, TRUE, TRUE, data_set);
        set_bit(op->flags, pe_action_pseudo);
        set_bit(op->flags, pe_action_runnable);

        op = custom_action(rsc, promote_key(rsc), RSC_PROMOTE, NULL, TRUE, TRUE, data_set);
        set_bit(op->flags, pe_action_pseudo);
        set_bit(op->flags, pe_action_runnable);
        op = custom_action(rsc, promoted_key(rsc), RSC_PROMOTED, NULL, TRUE, TRUE, data_set);
        set_bit(op->flags, pe_action_pseudo);
        set_bit(op->flags, pe_action_runnable);
    }
}
Esempio n. 2
0
static int start_action(int tok, int val)
{
    audio_play(AUD_MENU, 1.0f);

    switch (tok)
    {
    case GUI_BACK:
        return goto_state(&st_set);

    case START_CHALLENGE:
        if (config_cheat())
        {
            progress_init(curr_mode() == MODE_CHALLENGE ?
                          MODE_NORMAL : MODE_CHALLENGE);
            gui_toggle(challenge_id);
            return 1;
        }
        else
        {
            progress_init(MODE_CHALLENGE);
            return start_action(START_LEVEL, 0);
        }
        break;

    case GUI_SCORE:
        gui_score_set(val);
        start_over(gui_active(), 0);
        return 1;

    case START_LOCK_GOALS:
        config_set_d(CONFIG_LOCK_GOALS, val);
        return goto_state(&st_start);

    case START_LEVEL:
        if (progress_play(get_level(val)))
            return goto_state(&st_level);

        break;
    }

    return 1;
}
void set_default_actions(void)
{
#define SPEED 50
    action[0].d_pattern		= 0x003;	// red
    action[0].d_length		= 10;
    action[0].d_speed		= SPEED;
    action[0].d_repeat		= 0;
    action[0].d_color0[0]	= 0;
    action[0].d_color0[1]	= 0;
    action[0].d_color0[2]	= 0;
    action[0].d_color1[0]	= 64;
    action[0].d_color1[1]	= 0;
    action[0].d_color1[2]	= 0;
    action[0].d_soft		= true;

    action[1].d_pattern		= 0x00c;	// green
    action[1].d_length		= 10;
    action[1].d_speed		= SPEED;
    action[1].d_repeat		= 0;
    action[1].d_color0[0]	= 0;
    action[1].d_color0[1]	= 0;
    action[1].d_color0[2]	= 0;
    action[1].d_color1[0]	= 0;
    action[1].d_color1[1]	= 64;
    action[1].d_color1[2]	= 0;
    action[1].d_soft		= true;

    action[2].d_pattern		= 0x030;	// magenta
    action[2].d_length		= 10;
    action[2].d_speed		= SPEED;
    action[2].d_repeat		= 0;
    action[2].d_color0[0]	= 0;
    action[2].d_color0[1]	= 0;
    action[2].d_color0[2]	= 0;
    action[2].d_color1[0]	= 64;
    action[2].d_color1[1]	= 0;
    action[2].d_color1[2]	= 48;
    action[2].d_soft		= true;

    action[3].d_pattern		= 0x0c0;	// yellow
    action[3].d_length		= 10;
    action[3].d_speed		= SPEED;
    action[3].d_repeat		= 0;
    action[3].d_color0[0]	= 0;
    action[3].d_color0[1]	= 0;
    action[3].d_color0[2]	= 0;
    action[3].d_color1[0]	= 64;
    action[3].d_color1[1]	= 20;
    action[3].d_color1[2]	= 0;
    action[3].d_soft		= true;

    action[4].d_pattern		= 0x300;	// blue
    action[4].d_length		= 10;
    action[4].d_speed		= SPEED;
    action[4].d_repeat		= 0;
    action[4].d_color0[0]	= 0;
    action[4].d_color0[1]	= 0;
    action[4].d_color0[2]	= 0;
    action[4].d_color1[0]	= 0;
    action[4].d_color1[1]	= 0;
    action[4].d_color1[2]	= 64;
    action[4].d_soft		= true;

    action[5].d_pattern		= 0x2aa;	// five fast white flashes
    action[5].d_length		= 11;
    action[5].d_override	= 11;
    action[5].d_speed		= 2;
    action[5].d_repeat		= 1;
    action[5].d_color0[0]	= 0;
    action[5].d_color0[1]	= 5;
    action[5].d_color0[2]	= 0;
    action[5].d_color1[0]	= 64;
    action[5].d_color1[1]	= 64;
    action[5].d_color1[2]	= 64;
    action[5].d_soft		= false;

    action[6].d_pattern		= 0x2a;		// red triple pulses for 5 min
    action[6].d_length		= 32;
    action[6].d_override	= 7;
    action[6].d_speed		= 10;
    action[6].d_repeat		= 46;
    action[6].d_color0[0]	= 0;
    action[6].d_color0[1]	= 0;
    action[6].d_color0[2]	= 0;
    action[6].d_color1[0]	= 64;
    action[6].d_color1[1]	= 0;
    action[6].d_color1[2]	= 0;
    action[6].d_soft		= false;

    action[7].d_pattern		= 0x5555;	// red/blue flashing forever
    action[7].d_length		= 16;
    action[7].d_override	= 16;
    action[7].d_speed		= 4;
    action[7].d_repeat		= 0;
    action[7].d_color0[0]	= 64;
    action[7].d_color0[1]	= 0;
    action[7].d_color0[2]	= 0;
    action[7].d_color1[0]	= 0;
    action[7].d_color1[1]	= 0;
    action[7].d_color1[2]	= 64;
    action[7].d_soft		= true;

    action[8].d_pattern		= 0x55;		// blue flashing, 1 min
    action[8].d_length		= 8;
    action[8].d_override	= 2;
    action[8].d_speed		= 2;
    action[8].d_repeat		= 185;
    action[8].d_color0[0]	= 64;
    action[8].d_color0[1]	= 0;
    action[8].d_color0[2]	= 0;
    action[8].d_color1[0]	= 0;
    action[8].d_color1[1]	= 0;
    action[8].d_color1[2]	= 0;
    action[8].d_soft		= false;

    action[9].d_pattern		= 0x55;		// red flashing, 1 min
    action[9].d_length		= 8;
    action[9].d_override	= 8;
    action[9].d_speed		= 2;
    action[9].d_repeat		= 185;
    action[9].d_color0[0]	= 0;
    action[9].d_color0[1]	= 0;
    action[9].d_color0[2]	= 64;
    action[9].d_color1[0]	= 0;
    action[9].d_color1[1]	= 0;
    action[9].d_color1[2]	= 0;
    action[9].d_soft		= false;

    start_action(0);
    start_action(1);
    start_action(2);
    start_action(3);
    start_action(4);
}
void parse_serial(void)
{
    int a = (serial_buf[1] - '0');
    if (a >= NACTIONS) a = 0;
    Action *ap = &action[a];

    switch(serial_buf[0]) {
      case '+':					// command '+': start action
	    start_action(a);
	    return;

      case '-':					// command '-': stop action
	    stop_action(a);
	    return;

      case '=':					// command '=': define action
	    ap->i_active = false;		// deactivate redefined action
	    uchar i = 2;
	    while (i < serial_len)
		switch(serial_buf[i++]) {
		  case 'p':			// p 0000   = pattern
			ap->d_pattern = get_hex16(serial_buf+i);
			i += 4;
			break;
		  case 's':			// s 0000   = speed
			ap->d_speed = get_hex16(serial_buf+i);
			i += 4;
			break;
		  case 'l':			// l 00     = length
			ap->d_length = get_hex8(serial_buf+i);
			i += 2;
		  case 'o':			// o 00     = override length
			ap->d_override = get_hex8(serial_buf+i);
			i += 2;
			break;
		  case 'r':			// r 00     = repeat
			ap->d_repeat = get_hex8(serial_buf+i);
			i += 2;
			break;
		  case 'f':			// f 000000 = fg color
			ap->d_color1[0] = get_hex8(serial_buf+i);
			ap->d_color1[1] = get_hex8(serial_buf+i+2);
			ap->d_color1[2] = get_hex8(serial_buf+i+4);
			i += 6;
			break;
		  case 'b':			// b 000000 = bg color
			ap->d_color0[0] = get_hex8(serial_buf+i);
			ap->d_color0[1] = get_hex8(serial_buf+i+2);
			ap->d_color0[2] = get_hex8(serial_buf+i+4);
			i += 6;
			break;
		  case 'S':			// S        = soft
			ap->d_soft = true;
			break;
		  case 'H':			// H        = hard
			ap->d_soft = false;
			break;
		  case 'C':			// C        = clear
			{int j;
			for (j=0; j < sizeof(Action); j++)
			    ((char *)ap)[i] = 0;
			break;}
		  case 'A':			// A        = activate
			start_action(a);
		}
    }
}
Esempio n. 5
0
Generator::Generator(Engine *engine)
	:
	OptionNode{"Generator"},
	assetmanager{engine->get_data_dir()},
	spec{std::make_shared<GameSpec>(this->assetmanager)} {

	// node settings
	this->set_parent(engine);
	this->add("generation_seed", 4321);
	this->add("terrain_size", 2);
	this->add("terrain_base_id", 0);
	this->add("player_area", 850);
	this->add("player_radius", 10);
	this->add("load_filename", "/tmp/default_save.oas");
	this->add("player_names", options::option_list{"name1", "name2"});

	// Save game functions
	options::OptionAction save_action("save_game", [this]() {
		Engine &engine = Engine::get();
		if (!engine.get_game()) {
			return options::OptionValue("Error: no open game to save");
		}
		auto filename = this->get_variable("load_filename").value<std::string>();
		gameio::save(engine.get_game(), filename);
		return options::OptionValue("Game saved");
	});
	this->add_action(save_action);

	// Load game function
	options::OptionAction load_action("load_game", [this]() {
		Engine &engine = Engine::get();
		if (engine.get_game()) {
			return options::OptionValue("Error: close existing game before loading");
		}
		else if (!this->spec->load_complete()) {
			return options::OptionValue("Error: game data has not finished loading");
		}
		auto filename = this->get_variable("load_filename").value<std::string>();

		// create an empty game
		this->regions.clear();
		engine.start_game(*this);
		gameio::load(engine.get_game(), filename);
		return options::OptionValue("Game loaded");
	});
	this->add_action(load_action);

	// create a game using this generator
	options::OptionAction start_action("generate_game", [this]() {
		if (this->create()) {
			return options::OptionValue("Game generated");
		}
		return options::OptionValue("Error: game data has not finished loading");
	});
	this->add_action(start_action);

	// stop game
	options::OptionAction end_action("end_game", [this]() {
		Engine &engine = Engine::get();
		engine.end_game();
		return options::OptionValue("Game ended");
	});
	this->add_action(end_action);

	// reload all assets
	options::OptionAction reload_action("reload_assets", [this]() {
		if (!this->spec->load_complete()) {
			return options::OptionValue("Error: game data has not finished loading");
		}
		this->assetmanager.check_updates();
		this->spec = std::make_shared<GameSpec>(this->assetmanager);
		return options::OptionValue("Starting asset reload");
	});
	this->add_action(reload_action);
}
Esempio n. 6
0
static int start_click(int b, int d)
{
    if (d && b < 0)
        return start_action(gui_token(gui_click()));
    return 1;
}
Esempio n. 7
0
void controller::mouse_down(const MouseEvent& e) {
    mouse_action_ = start_action(e);
}