Page 1 of 1

Abstract items

Posted: Sun May 06, 2007 8:56 am
by itec
Like in object oriented languages, items should be possible to derive from another abstract item. Let's say we have item class MaceWeapon, which looks like this:

Code: Select all

Abstract MaceWeapon
{
    Attribute       macefighting
    HitSound        0x13C
    MissSound       0x234
    equipscript     equip
    unequipscript   unequip
    destroyscript   destroy
    HitScript	   :combat:mainHitScript
    CProp	        OnHit a1:S15::combat:maceHit
}
And a weapon club:

Code: Select all

Weapon 0x13B3 : MaceWeapon
{
    Name            Club
    desc            club
    Speed           40
    Damage          1d3+20
    Anim            0x000b
    MaxHP           35
    VendorSellsFor  27
    VendorBuysFor   13
    strrequired     10
    MinDam          11
    MaxDam          13
}
Or the definition could be handled as an element:

Code: Select all

    DeriveFrom       MaceWeapon
So the abstract items (and why not NPC templates also) would be a collection of properties. This would save a lot of repeating in config files, and it would make maintenance easier.

Posted: Tue May 15, 2007 1:14 am
by zandor
Not evil this think.

I also like to have a sort of C #DEFINE and #IFDEFINEDCOMPILE #ENDCOMPIELSECION to compile single senction of code in some circustances....

Posted: Tue May 15, 2007 5:32 am
by CWO
Zandor I think what you're trying to say can be accomplished using constants.

Code: Select all

use uo;

const TESTCONST := 0;

program testconst(who)
  if (TESTCONST)
    SendSysMessage(who, "Test area compiled");
  endif
  SendSysMessage(who, "Ending script");
endprogram
If TESTCONST is 0, the script will be compiled as if only SendSysMessage(who, "Ending script"); exists. Check the .lst file to see.

Posted: Tue May 15, 2007 5:55 am
by OldnGrey
Well, that's a new one for me!
Thanks for the education :)

Posted: Tue May 15, 2007 9:27 am
by zandor70
No... I can use const like vars into programs but program compiled is always the same.

Posted: Tue May 15, 2007 10:17 am
by tekproxy
For the record, what CWO says works. Here's his example in action:


conditional_compile.src - TESTCONST == 0

Code: Select all

use uo;

const TESTCONST := 0;

program testconst(who)
  if (TESTCONST)
    SendSysMessage(who, "Test area compiled");
  endif
  SendSysMessage(who, "Ending script");
endprogram
conditional_compile.lst - TESTCONST == 0

Code: Select all

conditional_compile.src, Line 5
program testconst(who)
const TESTCONST := 0;
0: get arg 'who'
SendSysMessage(who, "Ending script");
1: local #0
2: "Ending script"
3: 3L
4: 1000L
5: Func(2,0): SendSysMessage
6: #
7: leave block(1)
8: progend


conditional_compile.src - TESTCONST == 1

Code: Select all

use uo;

const TESTCONST := 1;

program testconst(who)
  if ( TESTCONST )
    SendSysMessage(who, "Test area compiled");
  endif
  SendSysMessage(who, "Ending script");
endprogram
conditional_compile.lst - TESTCONST == 1

Code: Select all

conditional_compile.src, Line 5
program testconst(who)
const TESTCONST := 1;
0: get arg 'who'
SendSysMessage(who, "Test area compiled");
1: local #0
2: "Test area compiled"
3: 3L
4: 1000L
5: Func(2,0): SendSysMessage
6: #
SendSysMessage(who, "Ending script");
7: local #0
8: "Ending script"
9: 3L
10: 1000L
11: Func(2,0): SendSysMessage
12: #
13: leave block(1)
14: progend

zandor70: Could you post your code that is not working?

Posted: Wed May 16, 2007 12:18 pm
by zandor70
I thinked const was used like vars.... I have never watched the code, sorry. I think you are right is code in .ecl is this, and for me is a very good news.

Posted: Wed May 16, 2007 5:41 pm
by CWO
I did this all over my AI because its a bit more efficient than variables and conditionals in the script (notice, ecompile doesn't even compile the conditional if/else/endif so POL doesn't have to read it). Now spellcaster code, ranged combat code, firebreath, and tactical stuff is all configurable.