]> git.localhorst.tv Git - l2e.git/commitdiff
rough implementation of capsule feeding
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 19 Dec 2012 21:07:30 +0000 (22:07 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 19 Dec 2012 21:07:30 +0000 (22:07 +0100)
src/common/Capsule.cpp
src/common/Capsule.h
src/main.cpp
src/menu/CapsuleFeedMenu.cpp
src/menu/CapsuleFeedMenu.h
src/menu/Resources.cpp
src/menu/Resources.h
test-data/capsule-feed.png [new file with mode: 0644]
test-data/capsules.l2s
test-data/test.l2s

index f886724515c3db11f9d5698f3d063f3eb306c45f..487958596fe767b94a75ad20d6e403a04a3f9b4c 100644 (file)
@@ -142,6 +142,35 @@ const Capsule::Class &Capsule::GetClass() const {
 }
 
 
+int Capsule::HungerEmpty() const {
+       return HungerTotal() - HungerFull();
+}
+
+int Capsule::HungerTotal() const {
+       return GetClass().hunger;
+}
+
+int Capsule::HungerFull() const {
+       return GetClass().hungerFull;
+}
+
+bool Capsule::IsHungry() const {
+       return HungerEmpty();
+}
+
+void Capsule::Feed(const common::Item *) {
+       // TODO: find out how to calculate an item's feed value
+       // TODO: an item the capsule favors (changes on every feed and after every
+       //       battle) doubles the value
+       int value = 1;
+       GetClass().hungerFull += value;
+       if (GetClass().hungerFull >= GetClass().hunger) {
+               GetClass().hungerFull = GetClass().hunger;
+               UpgradeClass();
+       }
+}
+
+
 Capsule::Class::Class()
 : name(0)
 , tribe(0)
@@ -150,6 +179,9 @@ Capsule::Class::Class()
 , attackAnimation(0)
 , spellAnimation(0)
 
+, hunger(32)
+, hungerFull(0)
+
 , healthBoost(0) {
        attacks[0] = 0;
        attacks[1] = 0;
@@ -210,6 +242,8 @@ void Capsule::Class::CreateTypeDescription() {
        td.AddField("attackAnimation", FieldDescription(((char *)&c.attackAnimation) - ((char *)&c), Animation::TYPE_ID).SetReferenced());
        td.AddField("spellAnimation", FieldDescription(((char *)&c.spellAnimation) - ((char *)&c), Animation::TYPE_ID).SetReferenced());
 
+       td.AddField("hunger", FieldDescription(((char *)&c.hunger) - ((char *)&c), Interpreter::NUMBER_ID));
+
        td.AddField("healthBoost", FieldDescription(((char *)&c.healthBoost) - ((char *)&c), Interpreter::NUMBER_ID));
        td.AddField("statBoost", FieldDescription(((char *)&c.statBoost) - ((char *)&c), Stats::TYPE_ID));
 }
index f68ba5301a52ef2b4b7b4503c185996ac13c2f46..ef4caf687a36af03385b4f4726444da2105a6b93 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef COMMON_CAPSULE_H_
 #define COMMON_CAPSULE_H_
 
+namespace common {
+       class Item;
+}
 namespace graphics {
        class Animation;
        class Sprite;
@@ -45,6 +48,12 @@ public:
        int ClassIndex() const { return curClass; }
        void SetClass(int index);
 
+       int HungerEmpty() const;
+       int HungerTotal() const;
+       int HungerFull() const;
+       bool IsHungry() const;
+       void Feed(const common::Item *);
+
        Uint16 MaxHealth() const;
 
        Stats GetStats() const;
@@ -79,6 +88,9 @@ private:
                graphics::Animation *attackAnimation;
                graphics::Animation *spellAnimation;
 
+               int hunger;
+               int hungerFull;
+
                int healthBoost;
                Stats statBoost;
        };
index 96bfad7c7da9966d4d2a843728b6ba2bf3d89119..dc4c669caadb90d8da52837680bf030b534c3d5d 100644 (file)
@@ -233,7 +233,7 @@ int main(int argc, char **argv) {
                gameState.heroes[0].AddSpell(valorSpell);
                gameState.heroes[1].AddSpell(valorSpell);
 
-               gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
+               gameState.inventory.Add(caster.GetItem("zirconPlateItem"), 32);
                gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
                gameState.inventory.Add(caster.GetItem("powerRingItem"));
                gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
index 184212d820537b47bbaac4cb2813357125608670..f2631b90aecad4b40fbf6fb305a3362f2a01355c 100644 (file)
@@ -100,9 +100,7 @@ void CapsuleFeedMenu::HandleEvents(const Input &input) {
                } else if (itemMenu.SelectedIndex() == itemMenu.SecondaryIndex()) {
                        switch (menu.Selected()) {
                                case CHOICE_SELECT:
-                                       if (true /* can feed */) {
-                                               // TODO: implement capsule feeding
-                                       }
+                                       FeedSelected();
                                        itemMenu.SetActive();
                                        break;
                                case CHOICE_SORT:
@@ -131,6 +129,18 @@ void CapsuleFeedMenu::HandleEvents(const Input &input) {
        }
 }
 
+void CapsuleFeedMenu::FeedSelected() {
+       if (itemMenu.Selected()) {
+               // TODO: feed and grow animations
+               GetCapsule().Feed(itemMenu.Selected());
+               parent->Game().state->inventory.Remove(itemMenu.Selected(), 1);
+               LoadInventory();
+       } else {
+               // beep
+       }
+}
+
+
 void CapsuleFeedMenu::UpdateWorld(float deltaT) {
 
 }
@@ -144,6 +154,9 @@ void CapsuleFeedMenu::Render(SDL_Surface *screen) {
        const Vector<int> spriteOffset(
                                3 * font.CharWidth() + font.CharWidth() * 3 / 4,
                                4 * font.CharHeight() + font.CharHeight() / 4);
+       const Vector<int> growthOffset(
+                       13 * font.CharWidth(),
+                       7 * font.CharHeight() + font.CharHeight() / 4);
        const Vector<int> hungerOffset(
                        13 * font.CharWidth(),
                        9 * font.CharHeight() + font.CharHeight() / 8);
@@ -157,6 +170,9 @@ void CapsuleFeedMenu::Render(SDL_Surface *screen) {
        parent->RenderBackground(screen);
        RenderName(screen, offset + nameOffset);
        RenderSprite(screen, offset + spriteOffset);
+       if (GetCapsule().IsHungry()) {
+               RenderGrowth(screen, offset + growthOffset);
+       }
        RenderHunger(screen, offset + hungerOffset);
        RenderMenu(screen, offset + menuOffset);
        RenderItems(screen, offset + itemsOffset);
@@ -177,6 +193,22 @@ void CapsuleFeedMenu::RenderSprite(SDL_Surface *screen, const Vector<int> &offse
        GetCapsule().BattleSprite()->Draw(screen, offset);
 }
 
+void CapsuleFeedMenu::RenderGrowth(SDL_Surface *screen, const Vector<int> &offset) const {
+       Vector<int> cursor(offset);
+       parent->Res().capsuleGrowthLabel->Draw(screen, offset);
+       cursor.X() += parent->Res().capsuleGrowthLabel->Width();
+
+       for (int i = 0; i < GetCapsule().HungerFull(); ++i) {
+               parent->Res().capsuleGrowthBarFilled->Draw(screen, cursor);
+               cursor.X() += parent->Res().capsuleGrowthBarFilled->Width();
+       }
+
+       for (int i = 0; i < GetCapsule().HungerEmpty(); ++i) {
+               parent->Res().capsuleGrowthBar->Draw(screen, cursor);
+               cursor.X() += parent->Res().capsuleGrowthBar->Width();
+       }
+}
+
 void CapsuleFeedMenu::RenderHunger(SDL_Surface *screen, const Vector<int> &offset) const {
        const Font &font(*parent->Res().normalFont);
        const Frame &frame(*parent->Res().statusFrame);
@@ -217,6 +249,10 @@ int CapsuleFeedMenu::Height() const {
        return parent->Height();
 }
 
+Capsule &CapsuleFeedMenu::GetCapsule() {
+       return parent->GetCapsule();
+}
+
 const Capsule &CapsuleFeedMenu::GetCapsule() const {
        return parent->GetCapsule();
 }
index 8c75edd11e1d22712190458bc1c316971af90839..1999674b6b453bbb1e8a2f4102865d4e517aa64e 100644 (file)
@@ -34,12 +34,15 @@ private:
 
        virtual void OnResize(int width, int height);
 
+       common::Capsule &GetCapsule();
        const common::Capsule &GetCapsule() const;
 
        void LoadInventory();
+       void FeedSelected();
 
        void RenderName(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
        void RenderSprite(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
+       void RenderGrowth(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
        void RenderHunger(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
        void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
        void RenderItems(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
index 548afc3572aae5496cd428c7b25ca9636454e44d..2c75291500f6668e2aaa004affc5754e6d552b37 100644 (file)
@@ -136,6 +136,10 @@ Resources::Resources()
 , capsuleAlignmentWheel(0)
 , capsuleAlignmentCursor(0)
 
+, capsuleGrowthLabel(0)
+, capsuleGrowthBar(0)
+, capsuleGrowthBarFilled(0)
+
 { }
 
 
@@ -259,6 +263,10 @@ void Resources::CreateTypeDescription() {
 
        td.AddField("capsuleAlignmentWheel", FieldDescription(((char *)&r.capsuleAlignmentWheel) - ((char *)&r), Sprite::TYPE_ID).SetReferenced());
        td.AddField("capsuleAlignmentCursor", FieldDescription(((char *)&r.capsuleAlignmentCursor) - ((char *)&r), Sprite::TYPE_ID).SetReferenced());
+
+       td.AddField("capsuleGrowthLabel", FieldDescription(((char *)&r.capsuleGrowthLabel) - ((char *)&r), Sprite::TYPE_ID).SetReferenced());
+       td.AddField("capsuleGrowthBar", FieldDescription(((char *)&r.capsuleGrowthBar) - ((char *)&r), Sprite::TYPE_ID).SetReferenced());
+       td.AddField("capsuleGrowthBarFilled", FieldDescription(((char *)&r.capsuleGrowthBarFilled) - ((char *)&r), Sprite::TYPE_ID).SetReferenced());
 }
 
 void Resources::Construct(void *data) {
index 1f6d2077912d41fd57ca4792b8602ed7375c2f60..1790a2777c8ee0f371327081c0be0e7ba0918a83 100644 (file)
@@ -124,6 +124,10 @@ struct Resources {
        graphics::Sprite *capsuleAlignmentWheel;
        graphics::Sprite *capsuleAlignmentCursor;
 
+       graphics::Sprite *capsuleGrowthLabel;
+       graphics::Sprite *capsuleGrowthBar;
+       graphics::Sprite *capsuleGrowthBarFilled;
+
        Resources();
 
        static void CreateTypeDescription();
diff --git a/test-data/capsule-feed.png b/test-data/capsule-feed.png
new file mode 100644 (file)
index 0000000..929483b
Binary files /dev/null and b/test-data/capsule-feed.png differ
index a62695855dc68c9668e1f919f19b2cf4def095a6..296e6bb3bc82e6123edbf88c717b52e5294f2341 100644 (file)
@@ -197,6 +197,7 @@ export Capsule flash {
                                        { column: 0, row: 0, disposition: < 0, -16> }
                                ]
                        },
+                       hunger: 0,
                        healthBoost: 208,
                        statBoost: Stats {
                                atp:  38,
index c691e17f55f14dc1223e3b7e7b6b9f0fb7328336..ed457cacfec0c3de823967d90093f8caf9351d51 100644 (file)
@@ -943,5 +943,19 @@ export MenuResources menuResources {
                image: :"capsule-sprites.png",
                size: <32, 32>,
                offset: <128, 128>
+       },
+       capsuleGrowthLabel: Sprite {
+               image: :"capsule-feed.png",
+               size: <32, 10>
+       },
+       capsuleGrowthBar: Sprite {
+               image: :"capsule-feed.png",
+               size: <8, 10>,
+               offset: <8, 10>
+       },
+       capsuleGrowthBarFilled: Sprite {
+               image: :"capsule-feed.png",
+               size: <8, 10>,
+               offset: <0, 10>
        }
 }