Exemplo n.º 1
0
/** Initialize the three color components. */
Clear::Clear(const Tag &tag) : Node(tag) {
	
	float arr[4];
	
	// Color
	if (tag.get("color", arr, false)) {
		hasColor = true;
		color = Vec4(arr[0], arr[1], arr[2], arr[3]);
	} else {
		hasColor = false;
		color = Vec4(0.0, 0.0, 0.0, 0.0);
	}
	
	// Depth
	hasDepth = true;
	if (!tag.get("depth", depth, false)) {
		hasDepth = false;
		depth = 1.0;
	}
	
	// Mask
	if (hasColor && !hasDepth) {
		mask = GL_COLOR_BUFFER_BIT;
	} else if (hasDepth && !hasColor) {
		mask = GL_DEPTH_BUFFER_BIT;
	} else {
		mask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
	}
}
Exemplo n.º 2
0
/** Initialize attributes.
 *
 * @throw NodeException if name not specified.
 */
Uniform::Uniform(const Tag &tag) : Node(tag), Nameable(tag) {

    // From tag
    tag.get("type", type);
    tag.get("link", link, false, false);

    // Other
    program = NULL;
    location = 0;
}
Exemplo n.º 3
0
/** @throw NodeException if matrix type not supported. */
UniformMatrix::UniformMatrix(const Tag &tag) : Uniform(tag) {
	
	// Find matrix type
	if (tag.get("as", as, false)) {
		setTypeFromAs();
	} else {
		setTypeFromName();
	}
	
	// Light
	light = NULL;
	tag.get("of", of, false, false);
}
Exemplo n.º 4
0
/** Creates a new %Scale from an XML tag.
 * 
 * @param tag XML tag with "x", "y", and "z" values.
 */
Scale::Scale(const Tag &tag) : Transform(tag) {
	
	// Values
	if (tag.get("value", value, false)) {
		x = value;
		y = value;
		z = value;
	} else {
		if (!tag.get("x", x, false))
			x = 1.0f;
		if (!tag.get("y", y, false))
			y = 1.0f;
		if (!tag.get("z", z, false))
			z = 1.0f;
	}
}
Exemplo n.º 5
0
/** Initializes the type and value (or link).
 * 
 * @throw NodeException if @e type is not supported.
 * @throw NodeException if @e value or @e link not specified.
 */
UniformVector::UniformVector(const Tag &tag) : Uniform(tag) {
	
	// Type
	if (getType() == "vec3") {
		size = 3;
	} else if (getType() == "vec4") {
		size = 4;
	} else {
		NodeException e(tag);
		e << "[UniformVector] '" << getType() << "' not supported.";
		throw e;
	}
	
	// Value or link
	if (!tag.get("value", value, false)) {
		if (!hasLink()) {
			NodeException e(tag);
			e << "[UniformVector] Need 'value' or 'link' attribute.";
			throw e;
		}
	}
	
	// Other
	transformable = NULL;
}
Exemplo n.º 6
0
/** Initialize attributes. */
Instance::Instance(const Tag &tag) : Node(tag) {
	
	Tag linkTag;
	
	// Name of group
	tag.get("of", of, true, true);
	if (!tag.get("selectable", selectable, false)) {
		selectable = false;
	}
	
	// Exclusions
	tag.get("only", only, false);
	
	// Create link
	linkTag.setName("link");
	linkTag.setFilename(tag.getFilename());
	linkTag.setLine(tag.getLine());
	linkTag["to"] = of;
	link = new Link(linkTag);
	addChild(link);
}
Exemplo n.º 7
0
/** Initializes the @e link and @e name attributes. */
Target::Target(const Tag &tag) : Attachment(tag) {
	
	tag.get("link", link, true, false);
	
	// Check name
	if (!hasName())
		setName(link);
	
	// Check type
	if (getType() != "color") {
		NodeException e(getTag());
		e << "[Target] Type must be color.";
		throw e;
	}
}
CardWidget::CardWidget(Card *card) : GuiContext(0, 0)
{
    face = new GuiColorRect(0, 0, 150, 76);
    add(face);
    face->set_rgba(0, 0, 0, 0.75f);
    set_width(face->get_width());
    set_height(face->get_height());

    GuiColorRect *edge = new GuiColorRect(0, 38, 152, 1);
    add(edge);
    edge->set_rgba(1, 1, 1, 1.0);
    // edge = new GuiColorRect(0, -38, 152, 1);
    // add(edge);
    // edge->set_rgba(1, 1, 1, 1.0);

    // icon
    GuiSprite *icon = new GuiSprite(card->iconAtlas, card->iconAtlasKey, 0, 0);
    icon->set_rgba(1.0, 1.0, 1.0, 1.0);
    add(icon);
    icon->align(GUI_LEFT, GUI_TOP);
    icon->offset(4,-4);

    // Label
    GuiLabel *title = new GuiLabel(FontManager::font("small"), card->title, 0, 0, true);
    title->set_rgba(1.0, 1.0, 1.0, 1.0);
    add(title);
    title->alignOnDimension(GUI_VERTICAL, GUI_TOP);
    title->offset_y(-4);
    title->set_x(icon->get_x()+icon->get_width()/2+title->get_width()/2+5);

    // Costs
    std::list<Tag *> *costs = card->matchAll("cost");
    GLfloat runningY = icon->get_y()-icon->get_height()/2-5;
    for(std::list<Tag *>::iterator tagIter = costs->begin(); tagIter != costs->end(); tagIter++) {
        Tag *costTag = *tagIter;

        char costStr[20];
        sprintf(costStr,"%s %s",costTag->get("amount").c_str(),costTag->get("resource").c_str());
        GuiLabel *costLabel = new GuiLabel(FontManager::font("small"), costStr, 0, 0, 0.5);
        add(costLabel);
        costLabel->set_y(runningY-costLabel->get_height()/2);
        costLabel->alignOnDimension(GUI_HORIZONTAL, GUI_LEFT);
        costLabel->offset_x(5);
        costLabel->set_rgba(0.5, 0, 0, 1.0);
        runningY -= costLabel->get_height() + 4;
    }
    delete costs;

    // Provides
    std::list<Tag *> *provides = card->matchAll("provide");
    runningY = icon->get_y()-icon->get_height()/2-5;
    for(std::list<Tag *>::iterator tagIter = provides->begin(); tagIter != provides->end(); tagIter++) {
        Tag *provideTag = *tagIter;

        char provideStr[20];
        sprintf(provideStr,"%s %s",provideTag->get("rate").c_str(),provideTag->get("resource").c_str());
        GuiLabel *provideLabel = new GuiLabel(FontManager::font("small"), provideStr, 0, 0, 0.5);
        add(provideLabel);
        provideLabel->set_y(runningY-provideLabel->get_height()/2);
        provideLabel->alignOnDimension(GUI_HORIZONTAL, GUI_RIGHT);
        provideLabel->offset_x(-5);
        provideLabel->set_rgba(0, 0.5, 0, 1.0);
        runningY -= provideLabel->get_height() + 4;
    }
    delete provides;

    // Poor man's reflection.
    this->className = "CardWidget";

    // Mouse events
    onMouseEnter = boost::bind(&CardWidget::mouseIn, this);
    onMouseExit = boost::bind(&CardWidget::mouseOut, this);
}
void CombatScreen::rollInitiative()
{
	int dMod = 0,aMod = 0;

	// Compute modifiers
		// Smallest fleet
	if (attackerShips.size() < defenderShips.size()) {
		aMod += 1;
	} else if (attackerShips.size() > defenderShips.size()) {
		dMod += 1;
	}
		// Fastest fleet
	Card *slowestAttacker = NULL;
	Card *slowestDefender = NULL;
	int slowestSpeed = -1;
	int shipSpeed;
	for(std::list<Card *>::iterator iter = attackerShips.begin(); iter != attackerShips.end(); iter++) {
		Tag *movementTag = (*iter)->match("movement");
		shipSpeed = atoi(movementTag->get("speed").c_str());
		if (slowestSpeed < 0 || shipSpeed < slowestSpeed) {
			slowestSpeed = shipSpeed;
			slowestAttacker = *iter;
		}
	}
	slowestSpeed = -1;
	for(std::list<Card *>::iterator iter = defenderShips.begin(); iter != defenderShips.end(); iter++) {
		Tag *movementTag = (*iter)->match("movement");
		shipSpeed = atoi(movementTag->get("speed").c_str());
		if (slowestSpeed < 0 || shipSpeed < slowestSpeed) {
			slowestSpeed = shipSpeed;
			slowestDefender = *iter;
		}
	}
	int attackerMinSpeed = atoi(slowestAttacker->match("movement")->get("speed").c_str());
	int defenderMinSpeed = atoi(slowestDefender->match("movement")->get("speed").c_str());
	if (attackerMinSpeed < defenderMinSpeed) {
		dMod += 1;
	} else if (attackerMinSpeed > defenderMinSpeed) {
		aMod += 1;
	}

	char modifierString[40];
	sprintf(modifierString,"Initiative: Attacker +%d, Defender +%d",aMod,dMod);
	eventLog->push(modifierString);

	int attackerDie = DiceManager::d6() + aMod;
	int defenderDie = DiceManager::d6() + dMod;

	sprintf(modifierString,"Initiative: Attacker %d vs Defender %d",attackerDie,defenderDie);
	eventLog->push(modifierString);

	Color4f *playerColor = NULL;
	char playerString[20];
	if (attackerDie == defenderDie) {
		// Initiative does not change
		if (defenderHasInitiative) {
			playerColor = defender->getColor();
			sprintf(playerString, "Defender");
		} else {
			playerColor = attacker->getColor();
			sprintf(playerString, "Attacker");
		}
		eventLog->push("keeps initiative",playerString,playerColor);
	} else {
		if (attackerDie > defenderDie) {
			defenderHasInitiative = false;
			sprintf(playerString, "Attacker");
			playerColor = attacker->getColor();
			Analytics::event("Attacker wins initiative");
		} else {
			defenderHasInitiative = true;
			sprintf(playerString, "Defender");
			playerColor = defender->getColor();
			Analytics::event("Defender wins initiative");
		}
		eventLog->push("wins initiative",playerString,playerColor);
	}
}