示例#1
0
/**
 * The function called by the parser when the text between tags is read.
 * This function is responsible for filling in the variables (e.g. team names)
 * when a file gets loaded.
 * @see The GLib manual (Simple XML parser).
 */
void
xml_team_read_text         (GMarkupParseContext *context,
			   const gchar         *text,
			   gsize                text_len,  
			   gpointer             user_data,
			   GError             **error)
{
#ifdef DEBUG
    printf("xml_team_read_text\n");
#endif

    gchar buf[text_len + 1];
    gint int_value;
    gfloat float_value;

    strncpy(buf, text, text_len);
    buf[text_len] = '\0';

    int_value = (gint)g_ascii_strtod(buf, NULL);
    float_value = (gfloat)g_ascii_strtod(buf, NULL);

    if(state == STATE_TEAM_NAME)
	misc_string_assign(&team->name, buf);
    else if(state == STATE_STADIUM_NAME)
    {
	g_free(team->stadium.name);
	misc_string_assign(&team->stadium.name, buf);
    }
    else if(state == STATE_SYMBOL)
	misc_string_assign(&team->symbol, buf);
    else if(state == STATE_AVERAGE_TALENT && opt_int("int_opt_load_defs") == 1)
	team->average_talent = 
	    (float_value / 10000) * const_float("float_player_max_skill");
    else if(state == STATE_FORMATION)
	team->structure = int_value;
    else if(state == STATE_NAMES_FILE)
	misc_string_assign(&team->names_file, buf);
    else if(state == STATE_PLAYER_NAME)
	misc_string_assign(&new_player.name, buf);
    else if(state == STATE_PLAYER_BIRTH_YEAR && opt_int("int_opt_load_defs") == 1)
	birth_year = int_value;
    else if(state == STATE_PLAYER_BIRTH_MONTH && opt_int("int_opt_load_defs") == 1)
	new_player.age = misc_get_age_from_birth(birth_year, int_value);
    else if(state == STATE_PLAYER_SKILL && opt_int("int_opt_load_defs") == 1)
	new_player.skill = ((gfloat)int_value / 10000) * 
	    const_float("float_player_max_skill");
    else if(state == STATE_PLAYER_TALENT && opt_int("int_opt_load_defs") == 1)
	new_player.talent = ((gfloat)int_value / 10000) * 
	    const_float("float_player_max_skill");
    else if(state == STATE_PLAYER_POSITION)
	new_player.pos = int_value;
}
示例#2
0
文件: bet.c 项目: kashifsoofi/bygfoot
/** Calculate the odds for the bet. */
void
bet_get_odds(BetMatch *bet)
{
#ifdef DEBUG
    printf("bet_get_odds\n");
#endif

    const Fixture *fix = fixture_from_id(bet->fix_id, TRUE);
    gfloat home_advantage = (fix->home_advantage) ?
	(const_float("float_game_home_advantage_lower") +
	 const_float("float_game_home_advantage_upper")) / 2 : 0;
    gfloat av_skill[2] = {0, 0}, skilldiff;
    gint i, j, better_idx;

    for(i=0;i<2;i++)
    {
	for(j=0;j<11;j++)
	    av_skill[i] += 
		player_get_game_skill(player_of_idx_team(fix->teams[i], j),
				      FALSE, TRUE);

	av_skill[i] /= 11;
    }

    av_skill[0] *= (1 + home_advantage);

    skilldiff = ABS(av_skill[0] - av_skill[1]);

    better_idx = 2 * (av_skill[0] < av_skill[1]);

    bet->odds[better_idx] = 
	0.33 + skilldiff * const_float("float_bet_better_factor");
    bet->odds[2 - better_idx] = 
	0.33 + skilldiff * const_float("float_bet_worse_factor");

    for(i=0;i<2;i++)
	bet->odds[i * 2] = CLAMP(bet->odds[i * 2],
				 const_float("float_bet_lower_limit"),
				 1 - const_float("float_bet_lower_limit"));
    
    bet->odds[1] = (1 - bet->odds[0] - bet->odds[2]);
    bet->odds[1] = CLAMP(bet->odds[1],
			 const_float("float_bet_lower_limit"),
			 1 - const_float("float_bet_lower_limit"));

    for(i=0;i<3;i++)
	bet->odds[i] = 
	    bet_round_odd((1 / bet->odds[i]) * 
			  (1 - const_float("float_bet_commission_decrease")));
}
示例#3
0
/** Handle a click on the contract offer button. */
void
misc2_callback_contract_offer(void)
{
#ifdef DEBUG
    printf("misc2_callback_contract_offer\n");
#endif

    gint i;
    gchar buf[SMALL];
    GtkSpinButton *spinbutton;
    gint value = 0;
    Player *pl = (Player*)statp;

    gtk_widget_set_sensitive(lookup_widget(window.contract, "button_contract_cancel"), FALSE);

    for(i=0;i<4;i++)
    {
	sprintf(buf, "radiobutton_contract%d", i + 1);

	if(gtk_toggle_button_get_active(
	       GTK_TOGGLE_BUTTON(lookup_widget(window.contract, buf))))
	{
	    sprintf(buf, "spinbutton_contract%d", i + 1);
	    spinbutton = GTK_SPIN_BUTTON(lookup_widget(window.contract, buf));
	    value = gtk_spin_button_get_value_as_int(spinbutton);

	    if(value >= (gint)rint((gfloat)stat1 * 
				   (1 + (i * const_float("float_contract_scale_factor") *
					 powf(-1, (pl->age > pl->peak_age))))))
	    {
		pl->contract += (i + 1);
		pl->offers = 0;
		pl->wage = value;
		game_gui_show_warning(_("%s accepts your offer."), pl->name);
		window_destroy(&window.contract);
	    }
	    else
	    {
		pl->offers++;
		if(pl->offers < const_int("int_contract_max_offers"))
		    game_gui_show_warning(_("%s rejects your offer. You may still make %d offers."), 
					  pl->name, 
					  const_int("int_contract_max_offers") - pl->offers);
		else
		{
		    game_gui_show_warning(_("%s rejects your offer and won't negotiate with you anymore. You should sell him before his contract expires (he'll simply leave your team otherwise)."), 
					  pl->name);
		    window_destroy(&window.contract);
		}
	    }

	    break;
	}
    }
}
示例#4
0
void
xml_team_read_start_element (GMarkupParseContext *context,
			    const gchar         *element_name,
			    const gchar        **attribute_names,
			    const gchar        **attribute_values,
			    gpointer             user_data,
			    GError             **error)
{
#ifdef DEBUG
    printf("xml_team_read_start_element\n");
#endif

    if(strcmp(element_name, TAG_TEAM) == 0)
	state = STATE_TEAM;
    else if(strcmp(element_name, TAG_TEAM_NAME) == 0)
	state = STATE_TEAM_NAME;
    else if(strcmp(element_name, TAG_STADIUM_NAME) == 0)
	state = STATE_STADIUM_NAME;
    else if(strcmp(element_name, TAG_SYMBOL) == 0)
	state = STATE_SYMBOL;
    else if(strcmp(element_name, TAG_AVERAGE_TALENT) == 0)
	state = STATE_AVERAGE_TALENT;
    else if(strcmp(element_name, TAG_FORMATION) == 0)
	state = STATE_FORMATION;
    else if(strcmp(element_name, TAG_NAMES_FILE) == 0)
	state = STATE_NAMES_FILE;
    else if(strcmp(element_name, TAG_PLAYER) == 0)
    {
	state = STATE_PLAYER;
	new_player = player_new(team, ((gfloat)team->average_talent / 10000) * 
				const_float("float_player_max_skill"), TRUE);
    }
    else if(strcmp(element_name, TAG_PLAYER_NAME) == 0)
	state = STATE_PLAYER_NAME;
    else if(strcmp(element_name, TAG_PLAYER_BIRTH_YEAR) == 0)
	state = STATE_PLAYER_BIRTH_YEAR;
    else if(strcmp(element_name, TAG_PLAYER_BIRTH_MONTH) == 0)
	state = STATE_PLAYER_BIRTH_MONTH;
    else if(strcmp(element_name, TAG_PLAYER_SKILL) == 0)
	state = STATE_PLAYER_SKILL;
    else if(strcmp(element_name, TAG_PLAYER_TALENT) == 0)
	state = STATE_PLAYER_TALENT;
    else if(strcmp(element_name, TAG_PLAYER_POSITION) == 0)
	state = STATE_PLAYER_POSITION;
    else
	debug_print_message("xml_team_read_start_element: unknown tag: %s; I'm in state %d\n",
		  element_name, state);
}
示例#5
0
文件: bet.c 项目: kashifsoofi/bygfoot
/** Place a new bet. 
    @return TRUE on success, FALSE otherwise. */
gboolean
bet_place(gint fix_id, gint outcome, gint wager)
{
#ifdef DEBUG
    printf("bet_place\n");
#endif

    gint max_wager = (gint)rint(finance_wage_unit(current_user.tm) * 
				const_float("float_bet_wager_limit_factor"));
    BetUser new_bet;
    gchar buf[SMALL];

    if(wager <= 0)
	return TRUE;

    if(wager > BUDGET(cur_user))
    {
	game_gui_show_warning(_("You don't have the money."));
	return FALSE;
    }

    if(wager > max_wager)
    {
	misc_print_grouped_int(max_wager, buf);
	game_gui_show_warning(_("The betting office doesn't allow you to wager more than %s."), buf);
	gtk_spin_button_set_value(
	    GTK_SPIN_BUTTON(lookup_widget(window.digits, "spinbutton1")),
	    (gdouble)max_wager);
	return FALSE;
    }

    new_bet.fix_id = fix_id;
    new_bet.outcome = outcome;
    new_bet.wager = wager;

    g_array_append_val(current_user.bets[1], new_bet);

    if(window.bets != NULL)
	treeview2_show_bets();

    return TRUE;
}
示例#6
0
Expr Simplify::visit(const Cast *op, ExprInfo *bounds) {
    // We don't try to reason about bounds through casts for now
    Expr value = mutate(op->value, nullptr);

    if (may_simplify(op->type) && may_simplify(op->value.type())) {
        const Call *call = value.as<Call>();
        const Cast *cast = value.as<Cast>();
        const Broadcast *broadcast_value = value.as<Broadcast>();
        const Ramp *ramp_value = value.as<Ramp>();
        double f = 0.0;
        int64_t i = 0;
        uint64_t u = 0;
        if (call && (call->is_intrinsic(Call::indeterminate_expression) ||
                     call->is_intrinsic(Call::signed_integer_overflow))) {
            if (call->is_intrinsic(Call::indeterminate_expression)) {
                return make_indeterminate_expression(op->type);
            } else {
                return make_signed_integer_overflow(op->type);
            }
        } else if (value.type() == op->type) {
            return value;
        } else if (op->type.is_int() &&
                   const_float(value, &f) &&
                   std::isfinite(f)) {
            // float -> int
            return IntImm::make(op->type, safe_numeric_cast<int64_t>(f));
        } else if (op->type.is_uint() &&
                   const_float(value, &f) &&
                   std::isfinite(f)) {
            // float -> uint
            return UIntImm::make(op->type, safe_numeric_cast<uint64_t>(f));
        } else if (op->type.is_float() &&
                   const_float(value, &f)) {
            // float -> float
            return FloatImm::make(op->type, f);
        } else if (op->type.is_int() &&
                   const_int(value, &i)) {
            // int -> int
            return IntImm::make(op->type, i);
        } else if (op->type.is_uint() &&
                   const_int(value, &i)) {
            // int -> uint
            return UIntImm::make(op->type, safe_numeric_cast<uint64_t>(i));
        } else if (op->type.is_float() &&
                   const_int(value, &i)) {
            // int -> float
            return FloatImm::make(op->type, safe_numeric_cast<double>(i));
        } else if (op->type.is_int() &&
                   const_uint(value, &u)) {
            // uint -> int
            return IntImm::make(op->type, safe_numeric_cast<int64_t>(u));
        } else if (op->type.is_uint() &&
                   const_uint(value, &u)) {
            // uint -> uint
            return UIntImm::make(op->type, u);
        } else if (op->type.is_float() &&
                   const_uint(value, &u)) {
            // uint -> float
            return FloatImm::make(op->type, safe_numeric_cast<double>(u));
        } else if (cast &&
                   op->type.code() == cast->type.code() &&
                   op->type.bits() < cast->type.bits()) {
            // If this is a cast of a cast of the same type, where the
            // outer cast is narrower, the inner cast can be
            // eliminated.
            return mutate(Cast::make(op->type, cast->value), bounds);
        } else if (cast &&
                   (op->type.is_int() || op->type.is_uint()) &&
                   (cast->type.is_int() || cast->type.is_uint()) &&
                   op->type.bits() <= cast->type.bits() &&
                   op->type.bits() <= op->value.type().bits()) {
            // If this is a cast between integer types, where the
            // outer cast is narrower than the inner cast and the
            // inner cast's argument, the inner cast can be
            // eliminated. The inner cast is either a sign extend
            // or a zero extend, and the outer cast truncates the extended bits
            return mutate(Cast::make(op->type, cast->value), bounds);
        } else if (broadcast_value) {
            // cast(broadcast(x)) -> broadcast(cast(x))
            return mutate(Broadcast::make(Cast::make(op->type.element_of(), broadcast_value->value), broadcast_value->lanes), bounds);
        } else if (ramp_value &&
                   op->type.element_of() == Int(64) &&
                   op->value.type().element_of() == Int(32)) {
            // cast(ramp(a, b, w)) -> ramp(cast(a), cast(b), w)
            return mutate(Ramp::make(Cast::make(op->type.element_of(), ramp_value->base),
                                     Cast::make(op->type.element_of(), ramp_value->stride),
                                     ramp_value->lanes), bounds);
        }
    }

    if (value.same_as(op->value)) {
        return op;
    } else {
        return Cast::make(op->type, value);
    }
}