コード例 #1
0
ファイル: gere.c プロジェクト: FlorianDewulf/wolf3D
int	gere_mouse(int button, int x, int y, t_mlx **p)
{
  int	i;
  int	j;
  t_mlx	*tmp;

  i = (int) ((x - WINX_RAY) / (200 / my_strlen((*p)->tab[0])));
  j = (int) ((y - WINY_RAY) / (200 / my_strlen((*p)->tab[0])));
  if (button == 1 && i < (my_strlen((*p)->tab[0]) - 1) &&
      j < (my_strlen((*p)->tab[0]) - 2) && i > 0 && j > 0)
    {
      if ((*p)->tab[j][i] == '1')
	(*p)->tab[j][i] = '0';
      else if ((*p)->tab[j][i] == '0')
	(*p)->tab[j][i] = '1';
      tmp = (*p);
      tmp = put_sol_and_sky(tmp);
      calcul(&tmp);
      cadre(&tmp);
      map(&tmp);
      viseur(&tmp);
      weapon(&tmp);
      pos_map(&tmp);
      (*p) = tmp;
      mlx_put_image_to_window(tmp->mlx_ptr, tmp->win_ptr, tmp->img, 0, 0);
    }
  return (0);
}
コード例 #2
0
ファイル: player.cpp プロジェクト: bDignam/3320_Game_Project
player::player()
{
    health = 50;
    treasure = 0;
    monstersKilled = 0;
    currentRoom = NULL;

    srand (time(NULL));
    int randInt = rand()%2;

    //Random Player Weapon
    if(randInt == 0)
        myWeapon = weapon("Sword", 0.4, 5);
    else if(randInt == 1)
        myWeapon = weapon("Axe", 0.5, 4);
    else
        myWeapon = weapon("Spear", 0.6, 3);
}
コード例 #3
0
void Enemy::addWeapon(WeaponType weapon_type, sf::Vector2f rect_size, float attack_delay, float attack_time, int damage)
{
	std::unique_ptr<Weapon> weapon(new Weapon(weapon_type));
	current_weapon = weapon.get();
	current_weapon->setRect(rect_size);
	current_weapon->setAttackDelay(attack_delay);
	current_weapon->setAttackTime(attack_time);
	current_weapon->setDamage(damage);
	this->addChild(std::move(weapon));
}
コード例 #4
0
ファイル: greataxe.c プロジェクト: JensenDied/Sinbyen
void configure() {
        ::configure();
        add_description(Description_Type_Generic);
        weapon()->set_weapon_type(Weapon_Type_Greataxe);
        set_craft(Craft_Excellent);
        add_proportion(([
			Element_Type             : Material_Uru,
			Element_Proportion       : 0.50,
		]));
		add_proportion(([
			Element_Type             : Material_Steel,
			Element_Proportion       : 3.0,
		]));
		add_proportion(([
			Element_Type             : Material_Qlippotam,
			Element_Proportion       : 0.25,
		]));
        set_global_rarity(Rarity_Common);
}
コード例 #5
0
ファイル: gere.c プロジェクト: FlorianDewulf/wolf3D
int	gere_key(int keycode, t_mlx **s)
{
  int		i;
  t_mlx		*tmp;

  i = 0;
  tmp = (*s);
  reduckey(keycode, &tmp);
  reduckeytwo(keycode, &tmp);
  tmp = put_sol_and_sky(tmp);
  calcul(&tmp);
  cadre(&tmp);
  map(&tmp);
  viseur(&tmp);
  weapon(&tmp);
  pos_map(&tmp);
  (*s) = tmp;
  mlx_put_image_to_window(tmp->mlx_ptr, tmp->win_ptr, tmp->img, 0, 0);
  return (0);
}
コード例 #6
0
ファイル: hero.cpp プロジェクト: bcobos/Dungeon-Hero
/**
 * @function hero::paintEvent
 * @brief hero avatar
 * @param e, the QPaintevent.
 * I assume this is what gets passed in when the event handler notices it's time for a paint event.
*/
void Hero::paintEvent(QPaintEvent* e){	
	//create the painter and set its coordinates.
	//painter.begin(this);
	QPainter painter(this);
	painter.translate(x,y);
	painter.rotate(angle);

	//set color and style
	painter.setPen(Qt::NoPen);	//Gets rid of outlines
	painter.setRenderHint(QPainter::Antialiasing);	//Sets antialiasing to smooth out graphics
	painter.setBrush(QBrush(Qt::blue));	//NOTE can set brush to pixmap!! Use this for monsters

	//first layer of drawing: Body
	painter.drawEllipse(body);

	//second layer of drawing: Head
	painter.setBrush(QBrush(Qt::gray));
	painter.drawEllipse(head);

	//third layer of drawing: Weapon
	weapon(painter);
}
コード例 #7
0
monster::monster()
{
//    srand(time(NULL)); //moved to gameboard.cpp
    int rtype = rand() % 3;
    switch (rtype)
    {
        case 0:
            name = "Troll";
            hit_points = 13;
        break;
        case 1:
            name = "Gelfling";
            hit_points = 6;
        break;
        case 2:
            name = "Belf";
            hit_points = 7;
        break;
    }
    weapon_weilded = weapon(MONSTER);
    tresure_held = tresure(100);
    type = "monster";
}
コード例 #8
0
ファイル: concept.hpp プロジェクト: EricWF/entity
 /// This shows how to use concepts against single entities
 void check_entity_example()
 {
     entity e(entity_id::hero);
     e << position{0, 0}
       << hp_t(100)
       << weapon("Sword", 5);
       
     // test e against the concept
     // result == true
     bool result = IsHero().check(e); 
     
     // same as above.
     result = IsHero()(e);
     
     // test e against the concept. If it is not satisfied throw an error.
     IsHero().require(e);
     
     // same as above, but this uses concepts that are not default constructible
     auto HeroAtPos = Concept<IsHero, HasPos>( AtPosition(position{0, 0}) );
     HeroAtPos.check(e);
     HeroAtPos(e);
     HeroAtPos.require(e);
 }
コード例 #9
0
CCobFile::CCobFile(CFileHandler &in, string name)
{
	char *cobdata = NULL;

	this->name = name;

	//Figure out size needed and allocate it
	int size = in.FileSize();

	// Handle errors (this is fairly fatal..)
	if (size < 0) {
		logOutput.Print("Could not find script for unit %s", name.c_str());
		exit(0);
	}

	cobdata = new char[size];

	//Read the entire thing, we will need it
	in.Read(cobdata, size);

	//Time to parse
	COBHeader ch;
	READ_COBHEADER(ch,cobdata);

	for (int i = 0; i < ch.NumberOfScripts; ++i) {
		int ofs;
		
		ofs = *(int *)&cobdata[ch.OffsetToScriptNameOffsetArray + i * 4];
		ofs = swabdword(ofs);
		string s = &cobdata[ofs];
		scriptNames.push_back(s);

		ofs = *(int *)&cobdata[ch.OffsetToScriptCodeIndexArray + i * 4];
		ofs = swabdword(ofs);
		scriptOffsets.push_back(ofs);
	}

	//Check for zero-length scripts
	for (int i = 0; i < ch.NumberOfScripts - 1; ++i) {
		scriptLengths.push_back(scriptOffsets[i + 1] - scriptOffsets[i]);
	}
	scriptLengths.push_back(ch.TotalScriptLen - scriptOffsets[ch.NumberOfScripts - 1]);

	for (int i = 0; i < ch.NumberOfPieces; ++i) {
		int ofs;

		ofs = *(int *)&cobdata[ch.OffsetToPieceNameOffsetArray + i * 4];
		ofs = swabdword(ofs);
		string s = StringToLower(&cobdata[ofs]);
		pieceNames.push_back(s);
	}

	int code_octets = size - ch.OffsetToScriptCode;
	int code_ints = (code_octets) / 4 + 4;
	code = new int[code_ints];
	memcpy(code, &cobdata[ch.OffsetToScriptCode], code_octets);
	for (int i = 0; i < code_ints; i++) {
		code[i] = swabdword(code[i]);
	}

	numStaticVars = ch.NumberOfStaticVars;

	// If this is a TA:K script, read the sound names
	if (ch.VersionSignature == 6) {
		for (int i = 0; i < ch.NumberOfSounds; ++i) {
			int ofs;
			ofs = *(int *)&cobdata[ch.OffsetToSoundNameArray + i * 4];
			/* TODO This probably isn't correct. */
			ofs = swabdword(ofs);
			string s = &cobdata[ofs];

			// Load the wave file and store the ID for future use
			s = "sounds/" + s + ".wav";
			sounds.push_back(sound->GetWaveId(s));
		}
	}

	delete[] cobdata;

	//Create a reverse mapping (name->int)
	for (unsigned int i = 0; i < scriptNames.size(); ++i) {
		scriptMap[scriptNames[i]] = i;
	}

	//Map common function names to indicies
	scriptIndex.resize(COBFN_Last + COB_MaxWeapons * 5);
	scriptIndex[COBFN_Create] = getFunctionId("Create");
	scriptIndex[COBFN_StartMoving] = getFunctionId("StartMoving");
	scriptIndex[COBFN_StopMoving] = getFunctionId("StopMoving");
	scriptIndex[COBFN_Activate] = getFunctionId("Activate");
	scriptIndex[COBFN_Killed] = getFunctionId("Killed");
	scriptIndex[COBFN_Deactivate] = getFunctionId("Deactivate");
	scriptIndex[COBFN_SetDirection] = getFunctionId("SetDirection");
	scriptIndex[COBFN_SetSpeed] = getFunctionId("SetSpeed");
	scriptIndex[COBFN_RockUnit] = getFunctionId("RockUnit");
	scriptIndex[COBFN_HitByWeapon] = getFunctionId("HitByWeapon");
	scriptIndex[COBFN_MoveRate0] = getFunctionId("MoveRate0");
	scriptIndex[COBFN_MoveRate1] = getFunctionId("MoveRate1");
	scriptIndex[COBFN_MoveRate2] = getFunctionId("MoveRate2");
	scriptIndex[COBFN_MoveRate3] = getFunctionId("MoveRate3");
	scriptIndex[COBFN_SetSFXOccupy] = getFunctionId("setSFXoccupy");

	// Also add the weapon aiming stuff
	for (int i = 0; i < COB_MaxWeapons; ++i) {
		char buf[15];
		sprintf(buf, "Weapon%d", i + 1);
		string weapon(buf);
		sprintf(buf, "%d", i + 1);
		string weap(buf);
		scriptIndex[COBFN_QueryPrimary + i] = getFunctionId("Query" + weapon);
		scriptIndex[COBFN_AimPrimary + i] = getFunctionId("Aim" + weapon);
		scriptIndex[COBFN_AimFromPrimary + i] = getFunctionId("AimFrom" + weapon);
		scriptIndex[COBFN_FirePrimary + i] = getFunctionId("Fire" + weapon);
		scriptIndex[COBFN_EndBurst + i] = getFunctionId("EndBurst" + weap);

		// If new-naming functions are not found, we need to support the old naming scheme
		if (i > 2)
			continue;
		switch (i) {
			case 0: weapon = "Primary"; break;
			case 1: weapon = "Secondary"; break;
			case 2: weapon = "Tertiary"; break;
		}

		if (scriptIndex[COBFN_QueryPrimary + i] == -1)
			scriptIndex[COBFN_QueryPrimary + i] = getFunctionId("Query" + weapon);
		if (scriptIndex[COBFN_AimPrimary + i] == -1)
			scriptIndex[COBFN_AimPrimary + i] = getFunctionId("Aim" + weapon);
		if (scriptIndex[COBFN_AimFromPrimary + i] == -1)
			scriptIndex[COBFN_AimFromPrimary + i] = getFunctionId("AimFrom" + weapon);
		if (scriptIndex[COBFN_FirePrimary + i] == -1)
			scriptIndex[COBFN_FirePrimary + i] = getFunctionId("Fire" + weapon);
	}
}
コード例 #10
0
void PlayerInst::use_item(GameState* gs, const GameAction& action) {
	if (!effective_stats().allowed_actions.can_use_items) {
		return;
	}
	itemslot_t slot = action.use_id;
	ItemSlot& itemslot = inventory().get(slot);
	Item& item = itemslot.item;
	ItemEntry& type = itemslot.item_entry();

	lua_State* L = gs->luastate();

	if (item.amount > 0) {
		if (item.is_equipment()) {
			if (itemslot.is_equipped()) {
				inventory().deequip(slot);
			} else {
				if (item.is_projectile()) {
					// Best-effort to equip, may not be possible:
					projectile_smart_equip(inventory(), slot);
				} else if (item.is_weapon()) {
					const Projectile& p = equipment().projectile();
					if (!p.empty()) {
						if (!p.projectile_entry().is_standalone()) {
							inventory().deequip_type(
									EquipmentEntry::AMMO);
						}
					}
					equipment().equip(slot);
					// Try and equip a projectile
					WeaponEntry& wentry = item.weapon_entry();
					if (wentry.uses_projectile) {
						const Projectile& p = equipment().projectile();
						if (p.empty()) {
							projectile_smart_equip(inventory(),
									wentry.weapon_class);
						}
					}
				} else {
					equipment().equip(slot);
				}

				if (item.is_weapon() || item.is_projectile()) {
					last_chosen_weaponclass =
							weapon().weapon_entry().weapon_class;
				}
			}
		} else if (equipment().valid_to_use(item)
				&& item_check_lua_prereq(L, type, this)) {
			item_do_lua_action(L, type, this,
					Pos(action.action_x, action.action_y), item.amount);
			if (is_local_player() && !type.inventory_use_message().empty()) {
				gs->game_chat().add_message(type.inventory_use_message(),
						Colour(100, 100, 255));
			}
			if (item.is_projectile())
				itemslot.clear();
			else
				item.remove_copies(1);
			reset_rest_cooldown();
		}
	}
}
コード例 #11
0
void PlayerInst::use_weapon(GameState* gs, const GameAction& action) {
    WeaponEntry& wentry = weapon().weapon_entry();
    MTwist& mt = gs->rng();
    const int MAX_MELEE_HITS = 10;
    EffectiveStats& estats = effective_stats();
    if (!cooldowns().can_doaction()) {
        return;
    }

    Pos start(x, y);
    Pos actpos(action.action_x, action.action_y);

    if (wentry.uses_projectile && !equipment().has_projectile()) {
        return;
    }

    int cooldown = 0;

    if (equipment().has_projectile()) {
        const Projectile& projectile = equipment().projectile;
        ProjectileEntry& pentry = projectile.projectile_entry();
        item_id item = get_item_by_name(pentry.name.c_str());
        int weaprange = std::max(wentry.range, pentry.range);

        AttackStats weaponattack(weapon());

        bool wallbounce = false;
        int nbounces = 0;
        float movespeed = pentry.speed;

        cooldown = std::max(wentry.cooldown, pentry.cooldown);

        //XXX: Horrible hack REMOVE THIS LATER
        if (class_stats().class_type().name == "Archer"
                && pentry.weapon_class == "bows") {
            int xplevel = class_stats().xplevel;
            float movebonus = class_stats().xplevel / 4.0f;
            if (movebonus > 2) {
                movebonus = 2;
            }
            float cooldown_mult = 1.0f - (class_stats().xplevel - 1) / 20.0f;
            if (cooldown_mult <= 0.85) {
                cooldown_mult = 0.85;
            }
            cooldown *= cooldown_mult;
            movespeed += movebonus;
            if (xplevel >= 3 && core_stats().mp >= 5) {
                nbounces = 2;
                core_stats().mp -= 5;
            }
        }

        GameInst* bullet = new ProjectileInst(projectile,
                                              effective_atk_stats(mt, weaponattack), id, start, actpos,
                                              movespeed, weaprange, NONE, wallbounce, nbounces);
        gs->add_instance(bullet);
        equipment().use_ammo();
    } else {
        int weaprange = wentry.range + this->radius + TILE_SIZE / 2;
        float mag = distance_between(actpos, Pos(x, y));
        if (mag > weaprange) {
            float dx = actpos.x - x, dy = actpos.y - y;
            actpos = Pos(x + dx / mag * weaprange, y + dy / mag * weaprange);
        }

        GameInst* enemies[MAX_MELEE_HITS];

        int max_targets = std::min(MAX_MELEE_HITS, wentry.max_targets);

        int numhit = get_targets(gs, this, actpos.x, actpos.y, wentry.dmgradius,
                                 enemies, max_targets);

        if (numhit == 0) {
            return;
        }

        for (int i = 0; i < numhit; i++) {
            EnemyInst* e = (EnemyInst*)enemies[i];
            lua_hit_callback(gs->get_luastate(), wentry.on_hit_func, this, e);
            if (attack(gs, e, AttackStats(equipment().weapon))) {
                PlayerData& pc = gs->player_data();
                signal_killed_enemy();

                char buffstr[32];
                int amnt = round(
                               double(e->xpworth()) / pc.all_players().size());
                players_gain_xp(gs, amnt);
                snprintf(buffstr, 32, "%d XP", amnt);
                gs->add_instance(
                    new AnimatedInst(Pos(e->x - 5, e->y - 5), -1, 25,
                                     Posf(), Posf(), AnimatedInst::DEPTH, buffstr,
                                     Colour(255, 215, 11)));
            }
        }
        cooldown = wentry.cooldown;
    }

    cooldowns().reset_action_cooldown(cooldown * estats.cooldown_mult);

    reset_rest_cooldown();
}
コード例 #12
0
// dx & dy indicates moving direction, useful for choosing melee attack targets
bool PlayerInst::enqueue_io_spell_and_attack_actions(GameState* gs, float dx,
        float dy) {
    GameView& view = gs->view();
    WeaponEntry& wentry = weapon().weapon_entry();

    bool mouse_within = gs->mouse_x() < gs->view().width;
    int rmx = view.x + gs->mouse_x(), rmy = view.y + gs->mouse_y();

    int level = gs->get_level()->id(), frame = gs->frame();

    bool is_moving = (dx != 0.0f || dy != 0.0f);
    IOController& io = gs->io_controller();
    bool attack_used = enqueue_io_spell_actions(gs);

    bool autotarget = io.query_event(IOEvent::AUTOTARGET_CURRENT_ACTION)
                      || io.query_event(IOEvent::ACTIVATE_SPELL_N);
    bool mousetarget = io.query_event(IOEvent::MOUSETARGET_CURRENT_ACTION);

    bool weaponuse = spell_selected() == -1;

    // choose & use weapon
    if (io.query_event(IOEvent::USE_WEAPON)) {
        queued_actions.push_back(
            game_action(gs, this, GameAction::CHOSE_SPELL, -1));
        autotarget = true;
        weaponuse = true;
    }

    if (spell_selected() >= 0
            && spells_known().get_entry(spell_selected()).mp_cost
            > core_stats().mp) {
        weaponuse = true;
    }

    // weapon use
    if (!attack_used && weaponuse && (autotarget || mousetarget)) {

        bool is_projectile = wentry.uses_projectile
                             || equipment().has_projectile();

        MonsterController& mc = gs->monster_controller();
        GameInst* curr_target = gs->get_instance(current_target);
        GameInst* target = NULL;
        Pos targ_pos;

        if (is_projectile) {
            if (mousetarget) {
                targ_pos = Pos(rmx, rmy);
            } else if (autotarget && curr_target) {
                targ_pos = curr_target->pos();
            }
        } else {
            if (mousetarget) {
                dx = rmx - x, dy = rmy - y;
            }
            target = get_weapon_autotarget(gs, this, curr_target, dx, dy);
            if (target) {
                targ_pos = Pos(target->x, target->y);

            }
            if (!is_moving && !target && !mousetarget && spell_selected() == -1
                    && curr_target && !is_projectile) {
                int vx, vy;
                GameInst* closest = get_closest_monster(gs, this);

                if (closest
                        && decide_attack_movement(pos(), closest->pos(),
                                                  TILE_SIZE / 4, vx, vy)) {
                    queued_actions.push_back(
                        game_action(gs, this, GameAction::MOVE, spellselect,
                                    round(vx), round(vy)));
                }
            }
        }
        if (target || (is_projectile && (mousetarget || curr_target))) {
            queued_actions.push_back(
                game_action(gs, this, GameAction::USE_WEAPON, spellselect,
                            targ_pos.x, targ_pos.y));
            attack_used = true;
        }
    }
    return attack_used;
}
コード例 #13
0
ファイル: pedactions.cpp プロジェクト: spippolatore/freesynd
bool PedInstance::createActQFiring(actionQueueGroupType &as, PathNode *tpn,
    ShootableMapObject *tsmo, bool forced_shot, uint32 make_shots, 
    pedWeaponToUse *pw_to_use, int32 value)
{
    as.state = 1;
    actionQueueType aq;
    aq.group_desc = PedInstance::gd_mFire;
    bool can_shoot = false;
    bool does_phys_dmg = false;
    Weapon *pWeapon = NULL;
    if (pw_to_use) {
        switch (pw_to_use->desc) {
            case 1:
                pw_to_use->wpn.wi = weapon(pw_to_use->wpn.indx);
                can_shoot = pw_to_use->wpn.wi->canShoot();
                does_phys_dmg = pw_to_use->wpn.wi->doesPhysicalDmg();
                pw_to_use->desc = 2;
                break;
            case 2:
                // pointer
                can_shoot = pw_to_use->wpn.wi->canShoot();
                does_phys_dmg = pw_to_use->wpn.wi->doesPhysicalDmg();
                break;
            case 3:
                // weapon type
                pWeapon = g_App.weapons().getWeapon(pw_to_use->wpn.wpn_type);
                can_shoot = pWeapon->canShoot();
                does_phys_dmg = pWeapon->doesPhysicalDmg();
                break;
            case 4:
                // strict damage type
                if(!g_App.weapons().checkDmgTypeCanShootStrict(
                    pw_to_use->wpn.dmg_type, can_shoot)) {
                    return false;
                }
                does_phys_dmg = (pw_to_use->wpn.dmg_type
                    & MapObject::dmg_Physical) != 0;
                break;
            case 5:
                // non-strict damage type
                if(!g_App.weapons().checkDmgTypeCanShootNonStrict(
                    pw_to_use->wpn.dmg_type, can_shoot)) {
                    return false;
                }
                does_phys_dmg = (pw_to_use->wpn.dmg_type
                    & MapObject::dmg_Physical) != 0;
                break;
        }
        aq.multi_var.enemy_var.pw_to_use = *pw_to_use;
    } else {
        WeaponInstance *wi = selectedWeapon();
        if (wi) {
            can_shoot = wi->canShoot();
            does_phys_dmg = wi->doesPhysicalDmg();
            Mod *pMod = slots_[Mod::MOD_BRAIN];
            if (pMod) {
                if (pMod->getVersion() == Mod::MOD_V3) {
                    aq.multi_var.enemy_var.pw_to_use.desc = 5;
                    aq.multi_var.enemy_var.pw_to_use.wpn.dmg_type = wi->dmgType();
                } else if (pMod->getVersion() == Mod::MOD_V2) {
                    aq.multi_var.enemy_var.pw_to_use.desc = 4;
                    aq.multi_var.enemy_var.pw_to_use.wpn.dmg_type = wi->dmgType();
                } else {
                    aq.multi_var.enemy_var.pw_to_use.desc = 3;
                    aq.multi_var.enemy_var.pw_to_use.wpn.wpn_type = wi->getWeaponType();
                }
            } else {
                aq.multi_var.enemy_var.pw_to_use.desc = 2;
                aq.multi_var.enemy_var.pw_to_use.wpn.wi = wi;
            }
        } else
            return false;
    }

    if (!can_shoot)
        return false;

    aq.multi_var.enemy_var.pw_to_use.use_ranks = slots_[Mod::MOD_BRAIN] ? true: false;
    aq.multi_var.enemy_var.value = value;
    aq.multi_var.enemy_var.forced_shot = forced_shot;
    if (does_phys_dmg) {
        aq.as = PedInstance::pa_smFiring;
        // TODO: use condition to set more information for action execution
        // continuos shooting until ammo ends(or all weapons ammo),
        // until target destroyed, type of damage that will complete action
        aq.multi_var.enemy_var.make_shots = make_shots;
        aq.multi_var.enemy_var.shots_done = 0;
        if (tpn) {
            aq.t_pn = *tpn;
            aq.ot_execute = PedInstance::ai_aAttackLocation;
            aq.t_smo = NULL;
        } else {
            aq.t_smo = tsmo;
            aq.ot_execute = PedInstance::ai_aDestroyObject;
        }
    } else {
        if (tsmo && tsmo->majorType() == MapObject::mjt_Ped) {
            aq.as = PedInstance::pa_smNone;
            aq.multi_var.enemy_var.make_shots = make_shots;
            aq.multi_var.enemy_var.shots_done = 0;
            aq.t_smo = tsmo;
            aq.ot_execute = PedInstance::ai_aAquireControl;
        } else
            return false;
    }
    aq.state = 1;
    aq.ot_execute |= PedInstance::ai_aWait;
    aq.multi_var.time_var.desc = 1;
    as.actions.push_back(aq);
    return true;
}
コード例 #14
0
ファイル: sc_item.cpp プロジェクト: coleb/Raid-Sim
bool item_t::decode_weapon()
{
  weapon_t* w = weapon();
  if ( ! w ) return true;

  std::vector<token_t> tokens;
  int num_tokens = parse_tokens( tokens, encoded_weapon_str );

  bool dps_set=false, dmg_set=false, min_set=false, max_set=false;

  for ( int i=0; i < num_tokens; i++ )
  {
    token_t& t = tokens[ i ];
    int type;
    school_type school;

    if ( ( type = util_t::parse_weapon_type( t.name ) ) != WEAPON_NONE )
    {
      w -> type = type;
    }
    else if ( ( school = util_t::parse_school_type( t.name ) ) != SCHOOL_NONE )
    {
      w -> school = school;
    }
    else if ( t.name == "dps" )
    {
      if ( ! dmg_set )
      {
        w -> dps = t.value;
        dps_set = true;
      }
    }
    else if ( t.name == "damage" || t.name == "dmg" )
    {
      w -> damage  = t.value;
      w -> min_dmg = t.value;
      w -> max_dmg = t.value;
      dmg_set = true;
    }
    else if ( t.name == "speed" || t.name == "spd" )
    {
      w -> swing_time = t.value;
    }
    else if ( t.name == "min" )
    {
      w -> min_dmg = t.value;
      min_set = true;

      if ( max_set )
      {
        dmg_set = true;
        dps_set = false;
        w -> damage = ( w -> min_dmg + w -> max_dmg ) / 2;
      }
      else
      {
        w -> max_dmg = w -> min_dmg;
      }
    }
    else if ( t.name == "max" )
    {
      w -> max_dmg = t.value;
      max_set = true;

      if ( min_set )
      {
        dmg_set = true;
        dps_set = false;
        w -> damage = ( w -> min_dmg + w -> max_dmg ) / 2;
      }
      else
      {
        w -> min_dmg = w -> max_dmg;
      }
    }
    else
    {
      sim -> errorf( "Player %s has unknown 'weapon=' token '%s' at slot %s\n", player -> name(), t.full.c_str(), slot_name() );
      return false;
    }
  }

  if ( dps_set ) w -> damage = w -> dps    * w -> swing_time;
  if ( dmg_set ) w -> dps    = w -> damage / w -> swing_time;

  if ( ! max_set || ! min_set )
  {
    w -> max_dmg = w -> damage;
    w -> min_dmg = w -> damage;
  }

  return true;
}
コード例 #15
0
ファイル: UnitDef.cpp プロジェクト: lunixbochs/spring
void UnitDef::ParseWeaponsTable(const LuaTable& weaponsTable)
{
	const WeaponDef* noWeaponDef = weaponDefHandler->GetWeapon("NOWEAPON");

	for (int w = 0; w < MAX_WEAPONS_PER_UNIT; w++) {
		LuaTable wTable;
		string name = weaponsTable.GetString(w + 1, "");
		if (name.empty()) {
			wTable = weaponsTable.SubTable(w + 1);
			name = wTable.GetString("name", "");
		}
		const WeaponDef* wd = NULL;
		if (!name.empty()) {
			wd = weaponDefHandler->GetWeapon(name);
		}
		if (wd == NULL) {
			if (w <= 3) {
				continue; // allow empty weapons among the first 3
			} else {
				break;
			}
		}

		while (weapons.size() < w) {
			if (!noWeaponDef) {
				logOutput.Print("Error: Spring requires a NOWEAPON weapon type "
				                "to be present as a placeholder for missing weapons");
				break;
			} else {
				weapons.push_back(UnitDefWeapon());
				weapons.back().def = noWeaponDef;
			}
		}

		const string badTarget = wTable.GetString("badTargetCategory", "");
		unsigned int btc = CCategoryHandler::Instance()->GetCategories(badTarget);

		const string onlyTarget = wTable.GetString("onlyTargetCategory", "");
		unsigned int otc;
		if (onlyTarget.empty()) {
			otc = 0xffffffff;
		} else {
			otc = CCategoryHandler::Instance()->GetCategories(onlyTarget);
		}

		const unsigned int slaveTo = wTable.GetInt("slaveTo", 0);

		float3 mainDir = wTable.GetFloat3("mainDir", float3(1.0f, 0.0f, 0.0f)).SafeNormalize();
		const float angleDif = cos(wTable.GetFloat("maxAngleDif", 360.0f) * (PI / 360.0f));

		const float fuelUse = wTable.GetFloat("fuelUsage", 0.0f);

		UnitDefWeapon weapon(name, wd, slaveTo, mainDir, angleDif, btc, otc, fuelUse);
		weapons.push_back(weapon);

		maxWeaponRange = std::max(maxWeaponRange, wd->range);

		if (wd->interceptor && wd->coverageRange > maxCoverage)
			maxCoverage = wd->coverageRange;

		if (wd->isShield) {
			if (!shieldWeaponDef || // use the biggest shield
			    (shieldWeaponDef->shieldRadius < wd->shieldRadius)) {
				shieldWeaponDef = wd;
			}
		}

		if (wd->stockpile) {
			// interceptors have priority
			if (wd->interceptor        ||
			    !stockpileWeaponDef ||
			    !stockpileWeaponDef->interceptor) {
				stockpileWeaponDef = wd;
			}
		}
	}
}
コード例 #16
0
ファイル: inventorystore.cpp プロジェクト: devnexen/openmw
void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor)
{
    const MWBase::World *world = MWBase::Environment::get().getWorld();
    const MWWorld::Store<ESM::GameSetting> &store = world->getStore().get<ESM::GameSetting>();
    MWMechanics::NpcStats& stats = actor.getClass().getNpcStats(actor);

    static float fUnarmoredBase1 = store.find("fUnarmoredBase1")->mValue.getFloat();
    static float fUnarmoredBase2 = store.find("fUnarmoredBase2")->mValue.getFloat();
    int unarmoredSkill = stats.getSkill(ESM::Skill::Unarmored).getModified();

    float unarmoredRating = (fUnarmoredBase1 * unarmoredSkill) * (fUnarmoredBase2 * unarmoredSkill);

    TSlots slots_;
    initSlots (slots_);

    // Disable model update during auto-equip
    mUpdatesEnabled = false;

    // Autoequip clothing, armor and weapons.
    // Equipping lights is handled in Actors::updateEquippedLight based on environment light.
    for (ContainerStoreIterator iter (begin(ContainerStore::Type_Clothing | ContainerStore::Type_Armor)); iter!=end(); ++iter)
    {
        Ptr test = *iter;

        if (!canActorAutoEquip(actor, test))
            continue;

        switch(test.getClass().canBeEquipped (test, actor).first)
        {
            case 0:
                continue;
            default:
                break;
        }

        if (iter.getType() == ContainerStore::Type_Armor &&
                test.getClass().getEffectiveArmorRating(test, actor) <= std::max(unarmoredRating, 0.f))
        {
            continue;
        }

        std::pair<std::vector<int>, bool> itemsSlots =
            iter->getClass().getEquipmentSlots (*iter);

        // checking if current item poited by iter can be equipped
        for (std::vector<int>::const_iterator iter2 (itemsSlots.first.begin());
            iter2!=itemsSlots.first.end(); ++iter2)
        {
            // if true then it means slot is equipped already
            // check if slot may require swapping if current item is more valueable
            if (slots_.at (*iter2)!=end())
            {
                Ptr old = *slots_.at (*iter2);

                if (iter.getType() == ContainerStore::Type_Armor)
                {
                    if (old.getTypeName() == typeid(ESM::Armor).name())
                    {
                        if (old.get<ESM::Armor>()->mBase->mData.mType < test.get<ESM::Armor>()->mBase->mData.mType)
                            continue;

                        if (old.get<ESM::Armor>()->mBase->mData.mType == test.get<ESM::Armor>()->mBase->mData.mType)
                        {
                            if (old.getClass().getEffectiveArmorRating(old, actor) >= test.getClass().getEffectiveArmorRating(test, actor))
                                // old armor had better armor rating
                                continue;
                        }
                    }
                    // suitable armor should replace already equipped clothing
                }
                else if (iter.getType() == ContainerStore::Type_Clothing)
                {
                    // if left ring is equipped
                    if (*iter2 == Slot_LeftRing)
                    {
                        // if there is a place for right ring dont swap it
                        if (slots_.at(Slot_RightRing) == end())
                        {
                            continue;
                        }
                        else // if right ring is equipped too
                        {
                            Ptr rightRing = *slots_.at(Slot_RightRing);

                            // we want to swap cheaper ring only if both are equipped
                            if (old.getClass().getValue (old) >= rightRing.getClass().getValue (rightRing))
                                continue;
                        }
                    }

                    if (old.getTypeName() == typeid(ESM::Clothing).name())
                    {
                        // check value
                        if (old.getClass().getValue (old) >= test.getClass().getValue (test))
                            // old clothing was more valuable
                            continue;
                    }
                    else
                        // suitable clothing should NOT replace already equipped armor
                        continue;
                }
            }

            if (!itemsSlots.second) // if itemsSlots.second is true, item can stay stacked when equipped
            {
                // unstack item pointed to by iterator if required
                if (iter->getRefData().getCount() > 1)
                {
                    unstack(*iter, actor);
                }
            }

            // if we are here it means item can be equipped or swapped
            slots_[*iter2] = iter;
            break;
        }
    }

    static const ESM::Skill::SkillEnum weaponSkills[] =
    {
        ESM::Skill::LongBlade,
        ESM::Skill::Axe,
        ESM::Skill::Spear,
        ESM::Skill::ShortBlade,
        ESM::Skill::Marksman,
        ESM::Skill::BluntWeapon
    };
    const size_t weaponSkillsLength = sizeof(weaponSkills) / sizeof(weaponSkills[0]);

    bool weaponSkillVisited[weaponSkillsLength] = { false };

    for (int i = 0; i < static_cast<int>(weaponSkillsLength); ++i)
    {
        int max = 0;
        int maxWeaponSkill = -1;

        for (int j = 0; j < static_cast<int>(weaponSkillsLength); ++j)
        {
            int skillValue = stats.getSkill(static_cast<int>(weaponSkills[j])).getModified();

            if (skillValue > max && !weaponSkillVisited[j])
            {
                max = skillValue;
                maxWeaponSkill = j;
            }
        }

        if (maxWeaponSkill == -1)
            break;

        max = 0;
        ContainerStoreIterator weapon(end());

        for (ContainerStoreIterator iter(begin(ContainerStore::Type_Weapon)); iter!=end(); ++iter)
        {
            if (!canActorAutoEquip(actor, *iter))
                continue;

            const ESM::Weapon* esmWeapon = iter->get<ESM::Weapon>()->mBase;

            if (esmWeapon->mData.mType == ESM::Weapon::Arrow || esmWeapon->mData.mType == ESM::Weapon::Bolt)
                continue;

            if (iter->getClass().getEquipmentSkill(*iter) == weaponSkills[maxWeaponSkill])
            {
                if (esmWeapon->mData.mChop[1] >= max)
                {
                    max = esmWeapon->mData.mChop[1];
                    weapon = iter;
                }

                if (esmWeapon->mData.mSlash[1] >= max)
                {
                    max = esmWeapon->mData.mSlash[1];
                    weapon = iter;
                }

                if (esmWeapon->mData.mThrust[1] >= max)
                {
                    max = esmWeapon->mData.mThrust[1];
                    weapon = iter;
                }
            }
        }

        if (weapon != end() && weapon->getClass().canBeEquipped(*weapon, actor).first)
        {
            std::pair<std::vector<int>, bool> itemsSlots =
                weapon->getClass().getEquipmentSlots (*weapon);

            if (!itemsSlots.first.empty())
            {
                if (!itemsSlots.second)
                {
                    if (weapon->getRefData().getCount() > 1)
                    {
                        unstack(*weapon, actor);
                    }
                }

                int slot = itemsSlots.first.front();
                slots_[slot] = weapon;
            }

            break;
        }

        weaponSkillVisited[maxWeaponSkill] = true;
    }

    bool changed = false;

    for (std::size_t i=0; i<slots_.size(); ++i)
    {
        if (slots_[i] != mSlots[i])
        {
            changed = true;
            break;
        }
    }
    mUpdatesEnabled = true;

    if (changed)
    {
        mSlots.swap (slots_);
        fireEquipmentChangedEvent(actor);
        updateMagicEffects(actor);
        flagAsModified();
    }
}
コード例 #17
0
ファイル: inventorystore.cpp プロジェクト: garvek/openmw
void MWWorld::InventoryStore::autoEquipWeapon (const MWWorld::Ptr& actor, TSlots& slots_)
{
    if (!actor.getClass().isNpc())
    {
        // In original game creatures do not autoequip weapon, but we need it for weapon sheathing.
        // The only case when the difference is noticable - when this creature sells weapon.
        // So just disable weapon autoequipping for creatures which sells weapon.
        int services = actor.getClass().getServices(actor);
        bool sellsWeapon = services & (ESM::NPC::Weapon|ESM::NPC::MagicItems);
        if (sellsWeapon)
            return;
    }

    static const ESM::Skill::SkillEnum weaponSkills[] =
    {
        ESM::Skill::LongBlade,
        ESM::Skill::Axe,
        ESM::Skill::Spear,
        ESM::Skill::ShortBlade,
        ESM::Skill::Marksman,
        ESM::Skill::BluntWeapon
    };
    const size_t weaponSkillsLength = sizeof(weaponSkills) / sizeof(weaponSkills[0]);

    bool weaponSkillVisited[weaponSkillsLength] = { false };

    // give arrows/bolt with max damage by default
    int arrowMax = 0;
    int boltMax = 0;
    ContainerStoreIterator arrow(end());
    ContainerStoreIterator bolt(end());

    // rate ammo
    for (ContainerStoreIterator iter(begin(ContainerStore::Type_Weapon)); iter!=end(); ++iter)
    {
        const ESM::Weapon* esmWeapon = iter->get<ESM::Weapon>()->mBase;

        if (esmWeapon->mData.mType == ESM::Weapon::Arrow)
        {
            if (esmWeapon->mData.mChop[1] >= arrowMax)
            {
                arrowMax = esmWeapon->mData.mChop[1];
                arrow = iter;
            }
        }
        else if (esmWeapon->mData.mType == ESM::Weapon::Bolt)
        {
            if (esmWeapon->mData.mChop[1] >= boltMax)
            {
                boltMax = esmWeapon->mData.mChop[1];
                bolt = iter;
            }
        }
    }

    // rate weapon
    for (int i = 0; i < static_cast<int>(weaponSkillsLength); ++i)
    {
        int max = 0;
        int maxWeaponSkill = -1;

        for (int j = 0; j < static_cast<int>(weaponSkillsLength); ++j)
        {
            int skillValue = actor.getClass().getSkill(actor, static_cast<int>(weaponSkills[j]));
            if (skillValue > max && !weaponSkillVisited[j])
            {
                max = skillValue;
                maxWeaponSkill = j;
            }
        }

        if (maxWeaponSkill == -1)
            break;

        max = 0;
        ContainerStoreIterator weapon(end());

        for (ContainerStoreIterator iter(begin(ContainerStore::Type_Weapon)); iter!=end(); ++iter)
        {
            if (!canActorAutoEquip(actor, *iter))
                continue;

            const ESM::Weapon* esmWeapon = iter->get<ESM::Weapon>()->mBase;

            if (esmWeapon->mData.mType == ESM::Weapon::Arrow || esmWeapon->mData.mType == ESM::Weapon::Bolt)
                continue;

            if (iter->getClass().getEquipmentSkill(*iter) == weaponSkills[maxWeaponSkill])
            {
                if (esmWeapon->mData.mChop[1] >= max)
                {
                    max = esmWeapon->mData.mChop[1];
                    weapon = iter;
                }

                if (esmWeapon->mData.mSlash[1] >= max)
                {
                    max = esmWeapon->mData.mSlash[1];
                    weapon = iter;
                }

                if (esmWeapon->mData.mThrust[1] >= max)
                {
                    max = esmWeapon->mData.mThrust[1];
                    weapon = iter;
                }
            }
        }

        bool isBow = false;
        bool isCrossbow = false;
        if (weapon != end())
        {
            const MWWorld::LiveCellRef<ESM::Weapon> *ref = weapon->get<ESM::Weapon>();
            ESM::Weapon::Type type = (ESM::Weapon::Type)ref->mBase->mData.mType;

            if (type == ESM::Weapon::MarksmanBow)
                isBow = true;
            else if (type == ESM::Weapon::MarksmanCrossbow)
                isCrossbow = true;
        }

        if (weapon != end() && weapon->getClass().canBeEquipped(*weapon, actor).first)
        {
            // Do not equip ranged weapons, if there is no suitable ammo
            bool hasAmmo = true;
            if (isBow == true)
            {
                if (arrow == end())
                    hasAmmo = false;
                else
                    slots_[Slot_Ammunition] = arrow;
            }
            if (isCrossbow == true)
            {
                if (bolt == end())
                    hasAmmo = false;
                else
                    slots_[Slot_Ammunition] = bolt;
            }

            if (hasAmmo)
            {
                std::pair<std::vector<int>, bool> itemsSlots = weapon->getClass().getEquipmentSlots (*weapon);

                if (!itemsSlots.first.empty())
                {
                    if (!itemsSlots.second)
                    {
                        if (weapon->getRefData().getCount() > 1)
                        {
                            unstack(*weapon, actor);
                        }
                    }

                    int slot = itemsSlots.first.front();
                    slots_[slot] = weapon;

                    if (!isBow && !isCrossbow)
                        slots_[Slot_Ammunition] = end();
                }

                break;
            }
        }

        weaponSkillVisited[maxWeaponSkill] = true;
    }
}
コード例 #18
0
bool Player::doInput(std::string s) {
	// Create 2 new arrays, each to hold a word.
	std::string args[2];
	
	// Put words into arrays
	int divisionpoint = s.find(" ");
	args[0] = s.substr(0,divisionpoint);
	args[1] = s.substr(divisionpoint+1);
	
	// Make the strings lowercase so they can be checked without being case sensitive.
	for (int i = 0; i < 16; i++) {if (args[0][i] <='Z' && args[0][i]>='A') args[0][i] -= ('Z'-'z');} // Convert string to lowercase.
	for (int i = 0; i < 16; i++) {if (args[1][i] <='Z' && args[1][i]>='A') args[1][i] -= ('Z'-'z');} // Convert string to lowercase.
	
	// Base input checker, takes the first word and uses the switch to call the needed function
	if (args[0] == "eat") goto eat;
	else if (args[0] == "get") goto get;
	else if (args[0] == "drop") goto drop;
	else if (args[0] == "go") goto go;
	else if (args[0] == "attack") goto attack;
	else if (args[0] == "search") {location->searchRoom(); return false;}
	else if (args[0] == "inventory") {checkInventory(); return false;}
	else if (args[0] == "health") {showHealth(); return false;}
	else if (args[0] == "weapon") goto weapon;
	else if (args[0] == "armor") goto armor;
	else if (args[0] == "suicide") {suicide(); return false;}
	else if (args[0] == "help") goto help;
	else {std::cout << "Unknown command, use 'help' to view commands.\n"; return false;}
	
eat:
	if (args[1] == "0") {eat(0); return true;}
	else if (args[1] == "1") {eat(1); return true;}
	else if (args[1] == "2") {eat(2); return true;}
	else if (args[1] == "3") {eat(3); return true;}
	else if (args[1] == "4") {eat(4); return true;}
	else if (args[1] == "5") {eat(5); return true;}
	else if (args[1] == "6") {eat(6); return true;}
	else if (args[1] == "7") {eat(7); return true;}
	else if (args[1] == "8") {eat(8); return true;}
	else if (args[1] == "9") {eat(9); return true;}
	else {std::cout << "Invalid argument for 'eat'.\nValid arguments for 'eat' are numbers 0-9.\n"; return false;}
	
get:
	if (args[1] == "0") {get(0); return true;}
	else if (args[1] == "1") {get(1); return true;}
	else if (args[1] == "2") {get(2); return true;}
	else if (args[1] == "3") {get(3); return true;}
	else if (args[1] == "4") {get(4); return true;}
	else if (args[1] == "5") {get(5); return true;}
	else if (args[1] == "6") {get(6); return true;}
	else if (args[1] == "7") {get(7); return true;}
	else if (args[1] == "8") {get(8); return true;}
	else if (args[1] == "9") {get(9); return true;}
	else {std::cout << "Invalid argument for 'get'.\nValid arguments for 'get' are numbers 0-9.\n"; return false;}
	
drop:
	if (args[1] == "0") {drop(0); return true;}
	else if (args[1] == "1") {drop(1); return true;}
	else if (args[1] == "2") {drop(2); return true;}
	else if (args[1] == "3") {drop(3); return true;}
	else if (args[1] == "4") {drop(4); return true;}
	else if (args[1] == "5") {drop(5); return true;}
	else if (args[1] == "6") {drop(6); return true;}
	else if (args[1] == "7") {drop(7); return true;}
	else if (args[1] == "8") {drop(8); return true;}
	else if (args[1] == "9") {drop(9); return true;}
	else {std::cout << "Invalid argument for 'drop'.\nValid arguments for 'drop' are numbers 0-9.\n"; return false;}
	
go:
	if (args[1] == "n") {go(0); return true;}
	else if (args[1] == "s") {go(1); return true;}
	else if (args[1] == "e") {go(2); return true;}
	else if (args[1] == "w") {go(3); return true;}
	else {std::cout << "Invalid argument for 'go'.\nValid arguments for 'go' are 'n', 's', 'e', and 'w'.\n"; return false;}
	
attack:
	if (args[1] == "0") {attack(0); return true;}
	else if (args[1] == "1") {attack(1); return true;}
	else if (args[1] == "2") {attack(2); return true;}
	else if (args[1] == "3") {attack(3); return true;}
	else if (args[1] == "4") {attack(4); return true;}
	else {std::cout << "Invalid argument for 'attack'.\nValid arguments for 'attack' are numbers 0-4.\n"; return false;}

weapon:
	if (args[1] == "0") {weapon(0); return true;}
	else if (args[1] == "1") {weapon(1); return true;}
	else if (args[1] == "2") {weapon(2); return true;}
	else if (args[1] == "3") {weapon(3); return true;}
	else if (args[1] == "4") {weapon(4); return true;}
	else if (args[1] == "5") {weapon(5); return true;}
	else if (args[1] == "6") {weapon(6); return true;}
	else if (args[1] == "7") {weapon(7); return true;}
	else if (args[1] == "8") {weapon(8); return true;}
	else if (args[1] == "9") {weapon(9); return true;}
	else {std::cout << "Invalid argument for 'weapon'.\nValid arguments for 'weapon' are numbers 0-9.\n"; return false;}
	
armor:
	if (args[1] == "0") {armor(0); return true;}
	else if (args[1] == "1") {armor(1); return true;}
	else if (args[1] == "2") {armor(2); return true;}
	else if (args[1] == "3") {armor(3); return true;}
	else if (args[1] == "4") {armor(4); return true;}
	else if (args[1] == "5") {armor(5); return true;}
	else if (args[1] == "6") {armor(6); return true;}
	else if (args[1] == "7") {armor(7); return true;}
	else if (args[1] == "8") {armor(8); return true;}
	else if (args[1] == "9") {armor(9); return true;}
	else {std::cout << "Invalid argument for 'armor'.\nValid arguments for 'armor' are numbers 0-9.\n"; return false;}
	
help:
	std::cout << "Valid commands are 'eat', 'get', 'drop', 'go', 'attack', 'search', 'inventory', 'health', 'weapon', 'armor', 'suicide', and 'help'.\n";
	return false;
}