Esempio n. 1
0
void spoil_powers_aux(FILE *fff, power_info *table)
{
	int i;
	variant vn, vd;
	var_init(&vn);
	var_init(&vd);

	fprintf(fff, "\n== Powers ==\n");
	fprintf(fff, "||  || *Stat* || *Lvl* || *Cost* || *Fail* || *Description* ||\n");
	for (i = 0; ; i++)
	{
		power_info *base = &table[i];		
		if (!base->spell.fn) break;

		base->spell.fn(SPELL_SPOIL_NAME, &vn);
		if (var_is_null(&vn)) base->spell.fn(SPELL_NAME, &vn);
		
		base->spell.fn(SPELL_SPOIL_DESC, &vd);
		if (var_is_null(&vd)) base->spell.fn(SPELL_DESC, &vd);

		fprintf(fff, "||%s||%s||%d||%d||%d||`%s`||\n", 
			var_get_string(&vn), 
			stat_abbrev_true[base->stat],
			base->spell.level, base->spell.cost, base->spell.fail, 
			var_get_string(&vd)
		);
	}

	var_clear(&vn);
	var_clear(&vd);
}
Esempio n. 2
0
void spoil_spells_aux(FILE *fff, spell_info *table)
{
	int i;
	variant vn, vd;
	var_init(&vn);
	var_init(&vd);

	fprintf(fff, "\n== Spells ==\n");
	fprintf(fff, "||  || *Lvl* || *Cost* || *Fail* || *Description* ||\n");
	for (i = 0; ; i++)
	{
		spell_info *base = &table[i];
		if (!base->fn) break;

		base->fn(SPELL_SPOIL_NAME, &vn);
		if (var_is_null(&vn)) base->fn(SPELL_NAME, &vn);
		
		base->fn(SPELL_SPOIL_DESC, &vd);
		if (var_is_null(&vd)) base->fn(SPELL_DESC, &vd);

		fprintf(fff, "||%s||%d||%d||%d||`%s`||\n", 
			var_get_string(&vn), base->level, base->cost, base->fail, var_get_string(&vd));
	}

	var_clear(&vn);
	var_clear(&vd);
}
Esempio n. 3
0
void default_spell(int cmd, variant *res) /* Base class */
{
    switch (cmd)
    {
    case SPELL_NAME:
        var_set_string(res, "Unknown Spell");
        break;

    case SPELL_DESC:
    case SPELL_INFO:
    case SPELL_MUT_DESC:
        var_set_string(res, "");
        break;    

    case SPELL_GAIN_MUT:
    case SPELL_LOSE_MUT:
        var_clear(res);
        break;

    case SPELL_FAIL:
    case SPELL_STOP:
    case SPELL_CONT:
        var_set_bool(res, TRUE);
        break;

    case SPELL_CAST:
        msg_print("Zap?");
        var_set_bool(res, TRUE);
        break;

    case SPELL_COST_EXTRA:
    case SPELL_FAIL_MIN:
        var_set_int(res, 0);
        break;

    case SPELL_ENERGY:
        var_set_int(res, 100);
        break;

    case SPELL_CALC_BONUS:
        var_set_bool(res, TRUE);
        break;

    case SPELL_COLOR:
        var_set_int(res, TERM_WHITE);
        break;

    case SPELL_ON_BROWSE:
        var_set_bool(res, FALSE);
        break;

    default:
        var_clear(res);
        break;
    }
}
Esempio n. 4
0
static void _list(menu_ptr menu, char *keys)
{
    char temp[255];
    int  i;
    int  y = 1;
    int  x = 13;

    Term_erase(x, y, 255);

    if (menu->heading)
        put_str(format("     %s", menu->heading), y++, x);

    for (i = 0; i < menu->count; i++)
    {
        byte attr = TERM_WHITE;
        variant key, text, color;

        var_init(&key);
        var_init(&text);
        var_init(&color);

        menu->fn(MENU_KEY, i, menu->cookie, &key);
        if (var_is_null(&key))
            keys[i] = I2A(i);
        else
            keys[i] = (char)var_get_int(&key);

        if (menu->count <= 26)
            keys[i] = tolower(keys[i]);

        menu->fn(MENU_TEXT, i, menu->cookie, &text);
        if (var_is_null(&text))
            var_set_string(&text, "");

        menu->fn(MENU_COLOR, i, menu->cookie, &color);
        if (!var_is_null(&color))
            attr = var_get_int(&color);

        if (attr == TERM_DARK)
            keys[i] = '\0';

        sprintf(temp, "  %c) %s", keys[i], var_get_string(&text));
        c_prt(attr, temp, y + i, x);

        var_clear(&key);
        var_clear(&text);
        var_clear(&color);
    }
    Term_erase(x, y + menu->count, 255);
}
Esempio n. 5
0
void _gain_power(int level)
{
int group_idx = -1;

    if (level % 2 == 1)
        group_idx = level/2;

    if (group_idx >= 0 && group_idx < _MAX_TALENTS && _group_size(group_idx) > 0)
    {
        variant name;
        int idx = randint0(_group_size(group_idx));
        talent_t *talent = &_talents[group_idx][idx];

        if (!talent->spell.fn)
        {
            msg_print("BUG: Where is your talent?!");
            return;
        }

        var_init(&name);
        (talent->spell.fn)(SPELL_NAME, &name);

        msg_format("You gain the power of '%s' %s.", var_get_string(&name), talent->gain_desc);
        p_ptr->magic_num1[group_idx] = idx + 1;

        var_clear(&name);
    }
}
Esempio n. 6
0
void
id_item_default_release(id_item_t *item)
{
    assert(item != NULL);

    switch (item->type) {
    case ID_VAR:
        if (item->var != NULL) {
            var_clear(item->var);
            ufree(item->var);
            item->var = NULL;
        }
        break;
    case ID_ARR:
        if (item->arr != NULL) {
            arr_free(item->arr);
            item->arr = NULL;
        }
        break;
    case ID_UNKNOWN:
    default:
        error(1, "unknown id type\n");
        break;
    }
}
Esempio n. 7
0
void fail_spell(ang_spell spell)
{
    variant res;
    var_init(&res);
    spell(SPELL_FAIL, &res);
    var_clear(&res);
}
Esempio n. 8
0
static void _character_dump(doc_ptr doc)
{
    int i;
    spell_info spells[MAX_SPELLS];
    int ct = _get_spells_imp(spells, MAX_SPELLS, 0, _MAX_TALENTS - 1);

    for (i = 0; i < ct; i++)
    {
        spell_info* current = &spells[i];
        current->cost += get_spell_cost_extra(current->fn);
        current->fail = MAX(current->fail, get_spell_fail_min(current->fn));
    }

    if (ct > 0)
    {
        int i;
        variant name, info;

        var_init(&name);
        var_init(&info);

        doc_printf(doc, "<topic:WildTalent>================================= <color:keypress>W</color>ild Talents ================================\n\n");
        doc_printf(doc, "<color:G>%-23.23s Lv Stat Cost Fail Info</color>\n", "");
        for (i = 0; i < ct; ++i)
        {
            spell_info *spell = &spells[i];

            (spell->fn)(SPELL_NAME, &name);
            (spell->fn)(SPELL_INFO, &info);

            doc_printf(doc, "%-23.23s %2d %4.4s %4d %3d%% %s\n",
                            var_get_string(&name),
                            spell->level,
                            stat_abbrev_true[_which_stat(i)],
                            spell->cost,
                            spell->fail,
                            var_get_string(&info));
        }

        var_clear(&name);
        var_clear(&info);

        doc_newline(doc);
    }
}
Esempio n. 9
0
void dump_spells_aux(FILE *fff, spell_info *table, int ct)
{        
    int i;
    variant vn, vd, vc, vfm;

    if (!ct) return;

    var_init(&vn);
    var_init(&vd);
    var_init(&vc);
    var_init(&vfm);

    if (character_dump_hack)
    {
        fprintf(fff, "=================================== Spells ====================================\n\n");
        fprintf(fff, "%-20.20s Lvl Cost Fail %-15.15s Cast Fail\n", "", "Desc");
    }
    else
    {
        fprintf(fff, "\n[[[[r|%-20.20s Lvl Cost Fail %-15.15s Cast Fail\n", "Spells", "Desc");
    }
    for (i = 0; i < ct; i++)
    {
        spell_info     *spell = &table[i];      
        spell_stats_ptr stats = spell_stats(spell);

        spell->fn(SPELL_NAME, &vn);
        spell->fn(SPELL_INFO, &vd);
        spell->fn(SPELL_COST_EXTRA, &vc);
        spell->fn(SPELL_FAIL_MIN, &vfm);

        fprintf(fff, "%-20.20s %3d %4d %3d%% %-15.15s %4d %4d %3d%%\n", 
            var_get_string(&vn), 
            spell->level, calculate_cost(spell->cost + var_get_int(&vc)), MAX(spell->fail, var_get_int(&vfm)), 
            var_get_string(&vd),
            stats->ct_cast, stats->ct_fail,
            spell_stats_fail(stats)
        );
    }

    var_clear(&vn);
    var_clear(&vd);
    var_clear(&vc);
    var_clear(&vfm);
}
Esempio n. 10
0
static int _choose_spell(spell_info* spells, int ct, cptr desc, int max_cost)
{
    int choice = -1;
    char prompt1[140];
    char prompt2[140];
    variant name;
    bool describe = FALSE;

    var_init(&name);

    for (;;)
    {
        char ch = '\0';

        strnfmt(prompt1, 78, "Use which %s? (Type '?' to Browse) ", desc);
        strnfmt(prompt2, 78, "Browse which %s? (Type '?' to Use)", desc);
        _list_spells(spells, ct, max_cost);

        /* Prompt User */
        choice = -1;

        if (!get_com(describe ? prompt2 : prompt1, &ch, FALSE)) break;

        if (ch == '?')
        {
            describe = !describe;
            if (!get_com(describe ? prompt2 : prompt1, &ch, FALSE)) break;
        }

        if (isupper(ch))
            choice = ch - 'A' + 26;
        else if (islower(ch))
            choice = ch - 'a';
        else if (ch >= '0' && ch <= '9')
            choice = ch - '0' + 52;

        /* Valid Choice? */
        if (choice < 0 || choice >= ct)
        {
            bell();
            continue;
        }

        if (describe)
        {
            _describe_spell(&spells[choice], _col_height(ct));
            continue;
        }

        /* Good to go! */
        break;
    }
    
    var_clear(&name);
    return choice;
}
Esempio n. 11
0
int get_spell_energy(ang_spell spell)
{
    int n;
    variant res;
    var_init(&res);
    spell(SPELL_ENERGY, &res);
    n = var_get_int(&res);
    var_clear(&res);
    return n;
}
Esempio n. 12
0
int get_spell_cost_extra(ang_spell spell)
{
    int n;
    variant res;
    var_init(&res);
    spell(SPELL_COST_EXTRA, &res);
    n = var_get_int(&res);
    var_clear(&res);
    return n;
}
Esempio n. 13
0
int get_spell_fail_min(ang_spell spell)
{
    int n;
    variant res;
    var_init(&res);
    spell(SPELL_FAIL_MIN, &res);
    n = var_get_int(&res);
    var_clear(&res);
    return n;
}
Esempio n. 14
0
cptr get_spell_name(ang_spell spell)
{
    static char buf[255];
    variant v;
    var_init(&v);
    spell(SPELL_NAME, &v);
    sprintf(buf, "%s", var_get_string(&v));
    var_clear(&v);
    return buf;
}
Esempio n. 15
0
cptr get_spell_desc(ang_spell spell)
{
    static char buf[1024];
    variant v;
    var_init(&v);
    spell(SPELL_DESC, &v);
    sprintf(buf, "%s", var_get_string(&v));
    var_clear(&v);
    return buf;
}
Esempio n. 16
0
bool cast_spell(ang_spell spell)
{
    bool b;
    variant res;
    var_init(&res);
    spell(SPELL_CAST, &res);
    b = var_get_bool(&res);
    var_clear(&res);
    return b;
}
Esempio n. 17
0
void mut_name(int i, char* buf)
{
	variant v;
	var_init(&v);

	if (i >= 0 && i < MAX_MUTATIONS)
		(_mutations[i].spell.fn)(SPELL_NAME, &v);
	else
		var_set_string(&v, "None");

	sprintf(buf, "%s", var_get_string(&v));
	var_clear(&v);
}
Esempio n. 18
0
bool mut_gain(int mut_idx)
{
	variant v;

	if (mut_idx < 0 || mut_idx >= MAX_MUTATIONS) return FALSE;
	if (mut_present(mut_idx)) return FALSE;
	
	var_init(&v);
	add_flag(p_ptr->muta, mut_idx);
	(_mutations[mut_idx].spell.fn)(SPELL_GAIN_MUT, &v);
	var_clear(&v);

	_mut_refresh();
	return TRUE;
}
Esempio n. 19
0
bool mut_lose(int mut_idx)
{
	variant v;
	if (mut_idx < 0 || mut_idx >= MAX_MUTATIONS) return FALSE;
	if (!mut_present(mut_idx)) return FALSE;
	if (mut_locked(mut_idx)) return FALSE;
	
	var_init(&v);
	remove_flag(p_ptr->muta, mut_idx);
	(_mutations[mut_idx].spell.fn)(SPELL_LOSE_MUT, &v);
	var_clear(&v);

	_mut_refresh();
	return TRUE;
}
Esempio n. 20
0
void mut_dump_file(FILE* file)
{
	int i;
	variant desc;
	var_init(&desc);
	for (i = 0; i < MAX_MUTATIONS; ++i)
	{
		if (mut_present(i))
		{
			(_mutations[i].spell.fn)(SPELL_MUT_DESC, &desc);
			fprintf(file, "%s\n", var_get_string(&desc));
		}
	}
	var_clear(&desc);
}
Esempio n. 21
0
void
var_clearv(struct variable *var, ...)
{
	struct variable *p;

	va_list ap;

	va_start(ap, var);
	p = var;

	while (p != NULL) {
		var_clear(p);
		p = va_arg(ap, struct variable *);
	}
	va_end(ap);
}
Esempio n. 22
0
void mut_calc_bonuses(void)
{
	int i;
	variant v;
	var_init(&v);

	for (i = 0; i < MAX_MUTATIONS; i++)
	{
		if ( mut_present(i)
		  && (_mutations[i].type & MUT_TYPE_BONUS) )
		{
			(_mutations[i].spell.fn)(SPELL_CALC_BONUS, &v);
		}
	}

	var_clear(&v);
}
Esempio n. 23
0
File: MTV.cpp Progetto: aissat/trick
/**
@details
Send mtv event data through the variable server.

-# For each event in the mtv_list
 -# call var_add() for all the event information
-# Send the size of list of variables we've added
-# Send the data
-# Clear the var_add list.
*/
int Trick::MTV::send_event_data() {

    char varname[80];
    const char *mtv_name = "trick_ip.mtv.mtv_list";
    unsigned int ii ;
    int jj;

    for (ii=0; ii < mtv_count; ii++) {
        sprintf(varname, "%s[%d][0].name", mtv_name,ii);
        var_add(varname);
        sprintf(varname, "%s[%d][0].active", mtv_name,ii);
        var_add(varname);
        sprintf(varname, "%s[%d][0].added", mtv_name,ii);
        var_add(varname);
        sprintf(varname, "%s[%d][0].condition_count", mtv_name,ii);
        var_add(varname);
        sprintf(varname, "%s[%d][0].action_count", mtv_name,ii);
        var_add(varname);
        sprintf(varname, "%s[%d][0].before_after", mtv_name,ii);
        var_add(varname);
        for (jj=0; jj< mtv_list[ii]->condition_count; jj++) {
            sprintf(varname, "%s[%d][0].cond[%d].comment", mtv_name,ii,jj);
            var_add(varname);
        }
        for (jj=0; jj< mtv_list[ii]->action_count; jj++) {
            sprintf(varname, "%s[%d][0].act[%d].comment", mtv_name,ii,jj);
            var_add(varname);
        }
        if (mtv_list[ii]->get_before_after() > 0) {
            sprintf(varname, "%s[%d][0].target_name", mtv_name,ii);
            var_add(varname);
        }
    }
    var_send_list_size() ;
    var_send() ;
    var_clear() ;

    return 0 ;
}
Esempio n. 24
0
static void _spell_menu_fn(int cmd, int which, vptr cookie, variant *res)
{
    _spell_menu_t *ss = (_spell_menu_t*)cookie;
    _spell_menu_t *s = ss + which;

    switch (cmd)
    {
    case MENU_TEXT:
        if (s->total_charges)
        {
            char    buf[1024];
            _kind_t k = s->spell->kind;
            cptr    info = _do_device(s->spell->kind.tval, s->spell->kind.sval, SPELL_INFO);

            sprintf(buf, "%-22.22s %3d %3d %3d%% ", _kind_name(&k), s->charges, s->total_charges, s->fail);
            if (info)
                strcat(buf, info);
            var_set_string(res, buf);
        }
        else
            var_clear(res);
        break;            
    case MENU_HELP:
        var_set_string(res, _kind_desc(&s->spell->kind));
        break;
    case MENU_COLOR:
        if (!s->total_charges)
            var_set_int(res, TERM_DARK);
        else if (!s->charges)
            var_set_int(res, TERM_RED);
        else
            var_set_int(res, TERM_WHITE);
        break;
    default:
        default_menu(cmd, which, cookie, res);
    }
}
Esempio n. 25
0
static void _describe(menu_ptr menu, int which)
{
    variant v;

    var_init(&v);
    menu->fn(MENU_HELP, which, menu->cookie, &v);
    if (!var_is_null(&v))
    {
        char tmp[255*10];
        int i, line;

        for (i = 0; i < 2+10; i++)
            Term_erase(13, menu->count + i + 1 + (menu->heading ? 1 : 0), 255);

        roff_to_buf(var_get_string(&v), 80-15, tmp, sizeof(tmp));

        for(i = 0, line = menu->count + 2 + (menu->heading ? 1 : 0); tmp[i]; i += 1+strlen(&tmp[i]))
        {
            prt(&tmp[i], line, 15);
            line++;
        }
    }
    var_clear(&v);
}
Esempio n. 26
0
void mut_process(void)
{
	int i;
	variant v;

	/* No effect on monster arena */
	if (p_ptr->inside_battle) return;

	/* No effect on the global map */
	if (p_ptr->wild_mode) return;

	var_init(&v);

	for (i = 0; i < MAX_MUTATIONS; i++)
	{
		if ( mut_present(i)
		  && (_mutations[i].type & MUT_TYPE_EFFECT) )
		{
			(_mutations[i].spell.fn)(SPELL_PROCESS, &v);
		}
	}

	var_clear(&v);
}
Esempio n. 27
0
static bool _describe_spell(spell_info *spell, int col_height)
{
    bool result = TRUE;
    variant info;

    var_init(&info);

    (spell->fn)(SPELL_ON_BROWSE, &info);
    if (!var_get_bool(&info))
    {
        char tmp[62*5];
        int i, line;
        rect_t display = ui_menu_rect();

        /* 2 lines below list of spells, 5 lines for description */
        for (i = 0; i < 7; i++)
            Term_erase(display.x, display.y + col_height + i + 2, display.cx);

        /* Get the description, and line break it (max 5 lines) */
        (spell->fn)(SPELL_DESC, &info);
        roff_to_buf(var_get_string(&info), 62, tmp, sizeof(tmp));

        line = display.y + col_height + 3;
        for(i = 0; tmp[i]; i += 1+strlen(&tmp[i]))
        {
            put_str(&tmp[i], line, display.x + 2);
            line++;
        }

        (spell->fn)(SPELL_INFO, &info);
        put_str(format("%^s", var_get_string(&info)), line, display.x + 2);
        result = FALSE;
    }
    var_clear(&info);
    return result;
}
Esempio n. 28
0
int
libcall_sum(id_item_t **args, int *rettypes, void **retvals)
{
	id_item_t *arg;
	struct variable *res;

	assert(args != NULL);

	rettypes[0] = ID_UNKNOWN;
	retvals[0] = NULL;

	res = xmalloc(sizeof(*res));
	var_init(res);
	var_set_zero(res);

	while (*args != NULL) {
		arg = *args;
		if (arg->type != ID_VAR) {
			print_warn("error: %s ID_VAR\n",
			id_type_2_str(ID_VAR));
			goto err;
		}

		if (varop_add(res, res, arg->var) != 0)
			goto err;
		args++;
	}

	rettypes[0] = ID_VAR;
	retvals[0] = res;

	return 0;
err:
	var_clear(res);
	return 1;
}
Esempio n. 29
0
void default_menu(int cmd, int which, vptr cookie, variant *res)
{
    var_clear(res);
}
Esempio n. 30
0
static void _list_spells(spell_info* spells, int ct, int max_cost)
{
    char temp[140];
    int  i;
    rect_t display = ui_menu_rect();
    int  col_height = _col_height(ct);
    int  col_width;
    variant name, info, color;

    var_init(&name);
    var_init(&info);
    var_init(&color);

    Term_erase(display.x, display.y, display.cx);
    if (col_height == ct)
    {
        put_str("Lvl Cost Fail Desc", display.y, display.x + 29);
    }
    else
    {
        col_width = 42;
        put_str("Lvl Cost Fail", display.y, display.x + 29);
        put_str("Lvl Cost Fail", display.y, display.x + col_width + 29);
    }

    for (i = 0; i < ct; i++)
    {
        char letter = '\0';
        byte attr = TERM_WHITE;
        spell_info* spell = &spells[i];

        var_set_int(&color, TERM_WHITE);

        (spell->fn)(SPELL_NAME, &name);
        (spell->fn)(SPELL_INFO, &info);
        (spell->fn)(SPELL_COLOR, &color);

        attr = var_get_int(&color);

        if (i < 26)
            letter = I2A(i);
        else if (i < 52)
            letter = 'A' + i - 26;
        else
            letter = '0' + i - 52;

        sprintf(temp, "  %c) ", letter);

        strcat(temp, format("%-23.23s %3d %4d %3d%%", 
                            var_get_string(&name),
                            spell->level,
                            spell->cost,
                            spell->fail));

        if (col_height == ct)
            strcat(temp, format(" %s", var_get_string(&info)));

        if (spell->fail == 100)
            attr = TERM_L_DARK;

        if (spell->cost > max_cost)
            attr = TERM_L_DARK;

        if (spell->level > p_ptr->lev)
            attr = TERM_L_DARK;

        if (i < col_height)
        {
            Term_erase(display.x, display.y + i + 1, display.cx);
            c_put_str(attr, temp, display.y + i + 1, display.x);
        }
        else
        {
            c_put_str(attr, temp, display.y + (i - col_height) + 1, display.x + col_width);
        }
    }
    Term_erase(display.x, display.y + col_height + 1, display.cx);
    var_clear(&name);
    var_clear(&info);
    var_clear(&color);
}