void LifeComponent::init()
{
	m_health = getMaxHealth();
	m_owner->addedToMap.on(this, &LifeComponent::addedToMap);
	m_spawning = false;
	m_despawning = false;
#ifdef FLAT_DEBUG
	m_dead = false;
#endif

	m_healthChangedSlotProxy.init(
		&healthChanged,
		[this](lua_State* L, int previousHealth)
		{
			lua_pushinteger(L, previousHealth);
			lua_pushinteger(L, m_health);
			lua_pushinteger(L, getMaxHealth());
		}
	);

	m_diedSlotProxy.init(
		&die,
		[](lua_State* L) {}
	);
}
示例#2
0
bool Hurtable::heal(int h)
{
    int curHealth = getHealth();
    int maxHealth = getMaxHealth();

    if (curHealth >= maxHealth)
        return false;

    setHealth(std::min(getMaxHealth(), getHealth() + h));
    return true;
}
示例#3
0
void Player::rest()
{
	health += 10;
	if (health > getMaxHealth())
	{
		health = getMaxHealth();
		std::cout << "Your health is full !" << std::endl;
	}
	else
		std::cout << "Your health is increased" << std::endl;

}
示例#4
0
文件: tile.cpp 项目: elgis/cpp-game
void Tile::draw()
{
	SDL_Rect rect;
	rect.x = x * TILE_SIZE;
	rect.y = y * TILE_SIZE;
	rect.w = TILE_SIZE;
	rect.h = TILE_SIZE;
	Sprite *sprite = m->sprites->getSprite(this->type);
	float mod = health / (float)getMaxHealth();
	if (mod != 1) {
		if (isBomb()) {
			sprite->draw(m->ren, &rect, 255, 255 * mod, 255 * mod);
		} else {
			sprite->draw(m->ren, &rect);
			drawDamage(rect, mod);
		}
	} else {
		sprite->draw(m->ren, &rect);
	}
	if (this->type != AIRID && !isBomb()) {
		drawCorners(m->sprites->CORNER, m->sprites->SIDE, AIRID);
		if (!isStone()) {
			drawCorners(m->sprites->CORNER_STONE, m->sprites->SIDE_STONE, STONEID);
			drawCorners(m->sprites->CORNER_STONE, m->sprites->SIDE_STONE, STONE_GOLDID);
		}
	}
}
示例#5
0
void SpacePlane::init(){

	static bool initialized = false;
	if(!initialized){
		sq_init(modPath() << _SC("models/SpacePlane.nut"),
			ModelScaleProcess(modelScale) <<=
			SingleDoubleProcess(hitRadius, _SC("hitRadius")) <<=
			MassProcess(defaultMass) <<=
			SingleDoubleProcess(maxHealthValue, _SC("maxhealth"), false) <<=
			Vec3dListProcess(engines, _SC("engines")) <<=
			DrawOverlayProcess(overlayDisp)
			);
		initialized = true;
	}

	undocktime = 0.f;
	health = getMaxHealth();
	mass = defaultMass;
	people = RandomSequence((unsigned long)this).next() % 100 + 100;
	engineHeat = 0.f;

	pf.resize(engines.size());
	for(int i = 0; i < pf.size(); i++)
		pf[i] = NULL;
}
示例#6
0
Danlu::Danlu(string name, char repChar, Stats stats){
    this->name = name;
    this->repChar = repChar;
    this->stats = stats;
    this->health = getMaxHealth();
    sorcu = new SorcuDacti(stats.strength*100);
}
示例#7
0
void Shipyard::draw(wardraw_t *wd){
	Shipyard *const p = this;
	static OpenGLState::weak_ptr<bool> init;
	static suftex_t *pst;
	static suf_t *sufbase = NULL;
	if(!Entity::w)
		return;

	/* cull object */
/*	if(beamer_cull(this, wd))
		return;*/
//	wd->lightdraws++;

	draw_healthbar(this, wd, health / getMaxHealth(), getHitRadius(), -1., capacitor / maxenergy());

	if(wd->vw->gc->cullFrustum(pos, getHitRadius()))
		return;
#if 1
	if(!init) do{
		motions[0] = LoadMotion("models/shipyard_door.mot");
		motions[1] = LoadMotion("models/shipyard_door2.mot");
		init.create(*openGLState);
	} while(0);

	Model *model = getModel();
	if(model){
		MotionPose mp[2];
		motions[0]->interpolate(mp[0], doorphase[0] * 10.);
		motions[1]->interpolate(mp[1], doorphase[1] * 10.);
		mp[0].next = &mp[1];

		const double scale = modelScale;
		Mat4d mat;

		glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT);
		glPushMatrix();
		transform(mat);
		glMultMatrixd(mat);
		gldScaled(scale);
		glScalef(-1, 1, -1);

#if 0
		for(int i = 0; i < nhitboxes; i++){
			Mat4d rot;
			glPushMatrix();
			gldTranslate3dv(hitboxes[i].org);
			rot = hitboxes[i].rot.tomat4();
			glMultMatrixd(rot);
			hitbox_draw(this, hitboxes[i].sc);
			glPopMatrix();
		}
#endif

		DrawMQOPose(model, mp);

		glPopMatrix();
		glPopAttrib();
	}
#endif
}
EnemyUnitBoundaryItem::EnemyUnitBoundaryItem(BWAPI::Unit* u, BWAPI::UnitType ut, BlackboardInformations* i)
    : AbstractSpaceUnitBoundaryItem(u, i, ut),
      info(i),
      lastSeen(-100),
      position(BWAPI::Positions::Unknown),
      health(getMaxHealth()),
      currentAction(BWAction::Unknown)
{ }
DevastatorClass::DevastatorClass(House* newOwner) : TrackedUnit(newOwner)
{
    DevastatorClass::init();

    setHealth(getMaxHealth());

    devastateTimer = 0;
}
示例#10
0
void Creature::changeHealth(int32_t healthChange)
{
	if(healthChange > 0)
		health += std::min(healthChange, getMaxHealth() - health);
	else
		health = std::max((int32_t)0, health + healthChange);

	g_game.addCreatureHealth(this);
}
示例#11
0
Palace::Palace(House* newOwner) : StructureBase(newOwner) {
    Palace::init();

    setHealth(getMaxHealth());
    specialWeaponTimer = getMaxSpecialWeaponTimer();

    // TODO: Special weapon is available immediately but AI uses it only after first visual contact
	//specialTimer = 1; // we want the special weapon to be immediately ready
}
OwnUnitBoundaryItem::OwnUnitBoundaryItem(BWAPI::Unit* u, BWAPI::UnitType ut, BlackboardInformations* i)
    : AbstractSpaceUnitBoundaryItem(u, i, ut),
      provideUnit(this),
      supply(this, ut),
      health(getMaxHealth())
{
    provideUnit.estimatedTime = ACTIVE_TIME;
    supply.estimatedTime = ACTIVE_TIME;
}
示例#13
0
void BuddyPlayer::deathReset(){
    setY(200);
    spawn_time = SPAWN_TIME;
    setMoving(true);
    setStatus(Status_Falling);
    setHealth(getMaxHealth());
    setDeath(0);
    animation_current = getMovement("idle");
}
示例#14
0
/*
*	Constructor - 
*
*/
Ogre::Ogre(){
	state=standby;
	hp=getMaxHealth();
	setVisible(true);
	setAlpha(255);
	targetUnit=targetTower=NULL;
	hook=new ActorHook();
	targetInRange=0;
	callback.myUnit=this;
}
void player::rest()
{
    //Heals by one point and takes up one turn
    if (getHealth() < getMaxHealth())
    {
        int newHealth = getHealth() + 1;
        setHealth(newHealth);
    }
    return;
}
示例#16
0
文件: player.cpp 项目: Faultless/Dawn
std::string Player::getSaveText() const
{
	std::ostringstream oss;
	std::string objectName = "thePlayer";
	oss << "-- General status attributes" << std::endl;
	oss << "local " << objectName << " = DawnInterface.getPlayer();" << std::endl;
	oss << objectName << ":setStrength( " << getStrength() << " );" << std::endl;
	oss << objectName << ":setDexterity( " << getDexterity() << " );" << std::endl;
	oss << objectName << ":setVitality( " << getVitality() << " );" << std::endl;
	oss << objectName << ":setIntellect( " << getIntellect() << " );" << std::endl;
	oss << objectName << ":setWisdom( " << getWisdom() << " );" << std::endl;
	oss << objectName << ":setMaxHealth( " << getMaxHealth() << " );" << std::endl;
	oss << objectName << ":setMaxMana( " << getMaxMana() << " );" << std::endl;
	oss << objectName << ":setMaxFatigue( " << getMaxFatigue() << " );" << std::endl;
	oss << objectName << ":setMinDamage( " << getMinDamage() << " );" << std::endl;
	oss << objectName << ":setMaxDamage( " << getMaxDamage() << " );" << std::endl;

	// don't set activity textures here. That is determined by class of Player / NPC

	oss << objectName << ":setDamageModifierPoints( " << getDamageModifierPoints() << " );" << std::endl;
	oss << objectName << ":setHitModifierPoints( " << getHitModifierPoints() << " );" << std::endl;
	oss << objectName << ":setEvadeModifierPoints( " << getEvadeModifierPoints() << " );" << std::endl;
	oss << objectName << ":setParryModifierPoints( " << getParryModifierPoints() << " );" << std::endl;
	oss << objectName << ":setBlockModifierPoints( " << getBlockModifierPoints() << " );" << std::endl;
	oss << objectName << ":setMeleeCriticalModifierPoints( " << getMeleeCriticalModifierPoints() << " );" << std::endl;
	oss << objectName << ":setResistAllModifierPoints( " << getResistAllModifierPoints() << " );" << std::endl;
	oss << objectName << ":setSpellEffectAllModifierPoints( " << getSpellEffectAllModifierPoints() << " );" << std::endl;
	for( size_t curElement=0; curElement<static_cast<size_t>(ElementType::Count); ++curElement )
	{
		ElementType::ElementType curElementType = static_cast<ElementType::ElementType>(curElement);
		oss << objectName << ":setResistElementModifierPoints( "
		            << curElementType << ", "
		            << getResistElementModifierPoints( curElementType ) << " );" << std::endl;
		oss << objectName << ":setSpellEffectElementModifierPoints( "
		            << curElementType << ", "
		            << getSpellEffectElementModifierPoints( curElementType ) << " );" << std::endl;
	}
	oss << objectName << ":setSpellCriticalModifierPoints( " << getSpellCriticalModifierPoints() << " );" << std::endl;
	oss << objectName << ":setName( \"" << getName() << "\" );" << std::endl;
	// string stream doesn't seem to have a proper overload for uint8_t and makes it the 0-character, so cast to size_t
	oss << objectName << ":setLevel( " << static_cast<size_t>(getLevel()) << " );" << std::endl;
	oss << objectName << ":setExperience( " << getExperience() << " );" << std::endl;
	oss << objectName << ":setClass( CharacterClass." << getClassName() << " );" << std::endl;

	oss << "-- coins" << std::endl;
	oss << objectName << ":setCoins( " << getCoins() << " );" << std::endl;

	oss << "-- position" << std::endl;
	oss << objectName << ":setPosition( " << getXPos() << ", " << getYPos() << " );" << std::endl;

	// no current attributes are set here because after reloading the player is completely refreshed again

	return oss.str();
}
示例#17
0
void Creature::changeHealth(int32_t healthChange, bool sendHealthChange/* = true*/)
{
	int32_t oldHealth = health;

	if (healthChange > 0) {
		health += std::min<int32_t>(healthChange, getMaxHealth() - health);
	} else {
		health = std::max<int32_t>(0, health + healthChange);
	}

	if (sendHealthChange && oldHealth != health) {
		g_game.addCreatureHealth(this);
	}
}
示例#18
0
void LifeComponent::debugDraw(debug::DebugDisplay& debugDisplay) const
{
	std::stringstream debugString;
	debugString << m_health << "/" << getMaxHealth() << "hp";
	if (m_spawning)
	{
		debugString << "\n(spawning)";
	}
	else if (m_despawning)
	{
		debugString << "\n(despawning)";
	}
	debugDisplay.add3dText(m_owner->getPosition(), debugString.str());
}
示例#19
0
文件: slime.cpp 项目: olofn/db_public
Slime::Slime(int x, int y, int slimeType, int level) : 
	Actor(ENEMY, x, y, 14, 10, true),
	mAnimation("graphics/slime" + toString(slimeType + 1) + ".bmp", 4),
	stateChangeTimer(0),
	mSlimeType(slimeType)
{
	mLevel = level;
	addState("idleleft", &mAnimation, 0, 0, 6, Actor::LEFT, false, false);
	addState("idleright", &mAnimation, 0, 0, 6, Actor::RIGHT, true, false);
	addState("walkleft", &mAnimation, -1, 0, 3, Actor::LEFT, false, false);
	addState("walkright", &mAnimation, 1, 0, 3, Actor::RIGHT, true, false);
	addState("walkup", &mAnimation, 0, -1, 3, Actor::UP, true, false);
	addState("walkdown", &mAnimation, 0, 1, 3, Actor::DOWN, false, false);

	setState(Random::get().getInt(2) == 0 ? "idleleft" : "idleright");
	stateChangeTimer = Random::get().getInt(10, 30);

	setMaxHealth(10 * (slimeType + 1));
	setHealth(getMaxHealth());
}
void player::levelUp()
{
    //Assigns to a random value at this point
    int currentAttribute;
    int randomAttribute = rand() % 3;
    switch(randomAttribute)
    {
        //Increases Damage
        case 0:
            currentAttribute = getBaseDamage() + 1;
            setBaseDamage(currentAttribute);
            break;
        //Increases Armor
        case 1:
            currentAttribute = getArmor() + 1;
            setArmor(currentAttribute);
            break;
        //Increase Health
        case 2:
            currentAttribute = getMaxHealth() + 1;
            setHealth(currentAttribute);
            setMaxHealth(currentAttribute);
            break;
    }


    experience=xpToLevel%experience;
    if((xpToLevel%2)>0)
    {
        xpToLevel=xpToLevel*1.5;
        xpToLevel++;
    }
    else
    {
        xpToLevel=xpToLevel*1.5;
    }
    int levelHolder=getLevel();
    levelHolder++;
    setLevel(levelHolder);
    return;
}
示例#21
0
void UnitBase::drawSelectionBox() {

    SDL_Surface* selectionBox = NULL;

    switch(currentZoomlevel) {
        case 0:     selectionBox = pGFXManager->getUIGraphic(UI_SelectionBox_Zoomlevel0);   break;
        case 1:     selectionBox = pGFXManager->getUIGraphic(UI_SelectionBox_Zoomlevel1);   break;
        case 2:
        default:    selectionBox = pGFXManager->getUIGraphic(UI_SelectionBox_Zoomlevel2);   break;
    }

    SDL_Rect dest = {   screenborder->world2screenX(realX) - selectionBox->w/2,
                        screenborder->world2screenY(realY) - selectionBox->h/2,
                        selectionBox->w,
                        selectionBox->h };
	SDL_BlitSurface(selectionBox, NULL, screen, &dest);

	int x = screenborder->world2screenX(realX) - selectionBox->w/2;
	int y = screenborder->world2screenY(realY) - selectionBox->h/2;
	for(int i=1;i<=currentZoomlevel+1;i++) {
        drawHLine(screen, x+1, y-i, x+1 + ((int)((getHealth()/(float)getMaxHealth())*(selectionBox->w-3))), getHealthColor());
	}
}
示例#22
0
Radar::Radar(House* newOwner) : StructureBase(newOwner) {
    Radar::init();

    setHealth(getMaxHealth());
}
示例#23
0
void Scarry::draw(wardraw_t *wd){
	Scarry *const p = this;
	static int init = 0;
	static suftex_t *pst;
	static suf_t *sufbase = NULL;
	if(!w)
		return;

	/* cull object */
/*	if(beamer_cull(this, wd))
		return;*/
//	wd->lightdraws++;

	draw_healthbar(this, wd, health / getMaxHealth(), getHitRadius(), -1., capacitor / maxenergy());

	if(wd->vw->gc->cullFrustum(pos, getHitRadius()))
		return;
#if 0
	if(init == 0) do{
		init = 1;
		sufbase = CallLoadSUF("models/spacecarrier.bin");
		if(!sufbase) break;
		CallCacheBitmap("bridge.bmp", "bridge.bmp", NULL, NULL);
		CallCacheBitmap("beamer_panel.bmp", "beamer_panel.bmp", NULL, NULL);
		CallCacheBitmap("bricks.bmp", "bricks.bmp", NULL, NULL);
		CallCacheBitmap("runway.bmp", "runway.bmp", NULL, NULL);
		suftexparam_t stp;
		stp.flags = STP_MAGFIL | STP_MINFIL | STP_ENV;
		stp.magfil = GL_LINEAR;
		stp.minfil = GL_LINEAR;
		stp.env = GL_ADD;
		stp.mipmap = 0;
		CallCacheBitmap5("engine2.bmp", "engine2br.bmp", &stp, "engine2.bmp", NULL);
		pst = AllocSUFTex(sufbase);
		extern GLuint screentex;
		glNewList(pst->a[0].list, GL_COMPILE);
		glBindTexture(GL_TEXTURE_2D, screentex);
		glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		glDisable(GL_LIGHTING);
		glEndList();
	} while(0);
	if(sufbase){
		static const double normal[3] = {0., 1., 0.};
		double scale = SCARRY_SCALE;
		static const GLdouble rotaxis[16] = {
			-1,0,0,0,
			0,1,0,0,
			0,0,-1,0,
			0,0,0,1,
		};
		Mat4d mat;

		glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT);
		glPushMatrix();
		transform(mat);
		glMultMatrixd(mat);

#if 1
		for(int i = 0; i < nhitboxes; i++){
			Mat4d rot;
			glPushMatrix();
			gldTranslate3dv(hitboxes[i].org);
			rot = hitboxes[i].rot.tomat4();
			glMultMatrixd(rot);
			hitbox_draw(this, hitboxes[i].sc);
			glPopMatrix();
		}
#endif

		Mat4d modelview, proj;
		glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
		glGetDoublev(GL_PROJECTION_MATRIX, proj);
		Mat4d trans = proj * modelview;
		texture((glPushMatrix(),
			glScaled(1./2., 1./2., 1.),
			glTranslated(1, 1, 0),
			glMultMatrixd(trans)
		));
		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGendv(GL_S, GL_EYE_PLANE, Vec4d(1,0,0,0));
		glEnable(GL_TEXTURE_GEN_S);
		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGendv(GL_T, GL_EYE_PLANE, Vec4d(0,1,0,0));
		glEnable(GL_TEXTURE_GEN_T);
		glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGeniv(GL_R, GL_EYE_PLANE, Vec4<int>(0,0,1,0));
		glEnable(GL_TEXTURE_GEN_R);
		glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
		glTexGeniv(GL_Q, GL_EYE_PLANE, Vec4<int>(0,0,0,1));
		glEnable(GL_TEXTURE_GEN_Q);

		glPushMatrix();
		glScaled(scale, scale, scale);
		glMultMatrixd(rotaxis);
		DecalDrawSUF(sufbase, SUF_ATR, NULL, pst, NULL, NULL);
		glPopMatrix();

		texture((glPopMatrix()));
		glPopMatrix();
		glPopAttrib();
	}
#endif
}
示例#24
0
文件: tile.cpp 项目: elgis/cpp-game
void Tile::resetHealth()
{
	this->health = getMaxHealth();
}
示例#25
0
文件: player.cpp 项目: Faultless/Dawn
uint16_t Player::getModifiedMaxHealth() const
{
	return getModifiedAttribute( inventory, this, getMaxHealth(), &getItemHealthHelper, &getSpellHealthHelper, NON_NULLABLE_ATTRIBUTE_MIN );
}
ConstructionYardClass::ConstructionYardClass(House* newOwner) : BuilderClass(newOwner)
{
    ConstructionYardClass::init();

    setHealth(getMaxHealth());
}
RadarClass::RadarClass(House* newOwner) : StructureClass(newOwner)
{
    RadarClass::init();

    setHealth(getMaxHealth());
}
示例#28
0
Quad::Quad(House* newOwner) : GroundUnit(newOwner) {
    Quad::init();

    setHealth(getMaxHealth());
}
Dynamite::Dynamite(int xPos, int yPos) : Entity(xPos,yPos)
{
    //Entity::Entity(xPos,yPos);
    setHealth(getMaxHealth());
    speed = 2*(rand()%7+1);
}
SiegeTankClass::SiegeTankClass(House* newOwner) : TankBaseClass(newOwner)
{
    SiegeTankClass::init();

    setHealth(getMaxHealth());
}