enigma-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Enigma-devel] Third addition - makeing rubber band objects work


From: FilE/TaRôM
Subject: Re: [Enigma-devel] Third addition - makeing rubber band objects work
Date: Tue, 4 Oct 2005 10:42:57 +0200
User-agent: KMail/1.6.1

ok, a little changed some files for peroxyd levels.
-------------- items.cc ------------------------
namespace
{
    class Rubberband : public Item {
        CLONEOBJ(Rubberband);
        DECL_TRAITS;

        ItemAction activate(Actor *actor,GridPos p) {
            double strength = 10.0;
            double length = 1.0;
            double_attrib ("length", &length);
            double_attrib ("strength", &strength);
            string o1 = "ac0";
            string_attrib("object1",&o1); 
            string o2 = "ac1";
            string_attrib("object2",&o2); 
            Actor  *obj1       = dynamic_cast<Actor*>(GetNamedObject(o1));
            //Actor *ac1 = (Actor*
            //Actor *ac2 = (Actor*)GetNamedObject(o2);
            Actor  *obj2       = dynamic_cast<Actor*>(GetNamedObject(o2));
            Stone  *st       = dynamic_cast<Stone*>(GetNamedObject(o2));
            if(!obj1) return ITEM_DROP;
            if((!obj2)&&(!st)) return ITEM_DROP;
            if (!world::HasRubberBand (obj1, obj2)) {
                sound_event ("rubberband");
                //world::KillRubberBand (sc.actor, (Stone*)0);
                if(obj2)
                 world::AddRubberBand (obj1, obj2, strength, length);
                else world::AddRubberBand (obj1, st, strength, length);
            }
            return ITEM_KILL;
         }
    public:
        Rubberband() {
            set_attrib("object1", Value());
            set_attrib("object2", Value());
            set_attrib("length", Value());
            set_attrib("strength", Value());
        }
    };
    DEF_TRAITS(Rubberband, "it-rubberband", it_rubberband);
}
--------------- CODE END ------------------

------------------ oxyd.cc --------------------
void OxydLoader::load_actors () 
{
    using world::MakeActor;
    //using World::name_object;

    int  nmeditationmarbles = 0;
    int  nmarbles           = level.getNumMarbles();
    bool have_black_marble  = false;

    for (int i=0; i<nmarbles; ++i)
        if (level.getMarble(i).getMarbleType() == MarbleType_Black)
            have_black_marble                   = true;


    for (int i=0; i<nmarbles; ++i) {
        const Marble &marble = level.getMarble(i);
        double        x      = marble.getX()/32.0;
        double        y      = marble.getY()/32.0;
        Actor        *ac     = 0;

        MarbleInfo minfo(marble);

        switch (marble.getMarbleType()) {
        case MarbleType_Black:
            ac = MakeActor (world::ac_blackball);
            world::NameObject(ac, "ac0");
            ac->set_attrib ("player", Value(0.0));
            break;
        case MarbleType_White:
            ac = MakeActor (world::ac_whiteball);
            world::NameObject(ac, "ac1");
            ac->set_attrib ("player", Value(1.0));
            break;
        case MarbleType_Meditation:
            if (have_black_marble) {
                // # example: Oxyd Extra #28
                ac = MakeActor (world::ac_killerball);
                world::NameObject(ac, "ac0");
                ac->set_attrib ("player", Value(0.0));
            }
            else {
                ac = MakeActor (world::ac_meditation);
                nmeditationmarbles += 1;
                if (config.twoplayers && (nmeditationmarbles % 2) == 0)
                    ac->set_attrib("player", Value(1.0));
                else
                    ac->set_attrib ("player", Value(0.0));
            }

            if (minfo.is_default(MI_FORCE)) {
                ac->set_attrib("mouseforce", Value(1.0));
            }
            else {
                ac->set_attrib("mouseforce", Value(minfo.get_value(MI_FORCE) / 
32.0)); // just a guess
            }
            break;
        case MarbleType_Jack:
            ac = MakeActor (world::ac_top);
            if (!minfo.is_default(MI_FORCE)) {
                double force = minfo.get_value(MI_FORCE) / 10.0 * 2.0; // just 
a guess
                ac->set_attrib("force", Value(force) );
                enigma::Log << "Set jack force to " << force << endl;
            }
            if (!minfo.is_default(MI_RANGE)) {
                double range = minfo.get_value(MI_RANGE) / 32.0; // value 
seems to contain distance in pixels
                ac->set_attrib("range", Value(range) );
                enigma::Log << "Set jack range to " << range << endl;
            }
            break;
        case MarbleType_Rotor: {
            ac = MakeActor (world::ac_rotor);

            if (!minfo.is_default(MI_FORCE)) {
                double force = minfo.get_value(MI_FORCE) / 10.0 * 2.0; // just 
a guess
                ac->set_attrib("force", Value(force) );
                enigma::Log << "Set rotor force to " << force << endl;
            }

            double range = 100./32;
            if (!minfo.is_default(MI_RANGE)) 
                range = minfo.get_value(MI_RANGE) / 32.0;
            ac->set_attrib("range", Value(range) );
            break;
        }

        case MarbleType_Horse: {
            ac = MakeActor (world::ac_horse);
            int levelw = level.getWidth();
            if (!minfo.is_default(MI_HORSETARGET1)) {
                int targetpos = minfo.get_value(MI_HORSETARGET1);
                ac->set_attrib("target1", px::strf("%d %d", 
                                                   targetpos % levelw, 
                                                   int(targetpos / levelw)));
            }
            if (!minfo.is_default(MI_HORSETARGET2)) {
                int targetpos = minfo.get_value(MI_HORSETARGET2);
                ac->set_attrib("target2", px::strf("%d %d", 
                                                   targetpos % levelw, 
                                                   int(targetpos / levelw)));
            }
            if (!minfo.is_default(MI_HORSETARGET3)) {
                int targetpos = minfo.get_value(MI_HORSETARGET3);
                ac->set_attrib("target3", px::strf("%d %d", 
                                                   targetpos % levelw, 
                                                   int(targetpos / levelw)));
            }
            if (!minfo.is_default(MI_HORSETARGET4)) {
                int targetpos = minfo.get_value(MI_HORSETARGET4);
                ac->set_attrib("target4", px::strf("%d %d", 
                                                   targetpos % levelw, 
                                                   int(targetpos / levelw)));
            }
            break;
        }
        case MarbleType_Bug:
            ac = MakeActor (world::ac_bug);
            break;
        default:
            enigma::Log << "Unhandled actor type " << 
int(marble.getMarbleType()) << endl;
            break;
//         case MarbleType_LifeSpitter:
//         case MarbleType_DynamiteHolder:
//             break;
        }

        if (ac) 
            world::AddActor (x, y, ac);

        m_actors.push_back (ac);
    }
}
---------------------- CODE END -------------------------

------------------------ ox_peroxyd.cc ----------------------
{{const char *oxyd::peroxyd_stone_map[256]}}
-    0,                          // PerOxyd stone 0x1e
+    "st-rock3",                          // PerOxyd stone 0x1e

{{ItemID oxyd::peroxyd_item_map[256]}}
-    it_MISSING,                            // 0x3e rubber band
+        it_rubberband,                 // 0x3e rubber band

---------------------- CODE END -------------------------

this will also change the 0x1e stone from dummy to st-rock3, which should be 
(at least after jeremy sawicki's grid byte values) correct. Note this only 
works if black marble get's connetion with the white one and vice versa. 
(does someone know a level which has a different behavior???)

greets
t.p.f.k.a.f

        

        
                
___________________________________________________________ 
Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: 
http://mail.yahoo.de





reply via email to

[Prev in Thread] Current Thread [Next in Thread]