Warning to usecoders: Massive change in UCC

NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Forum rules
NOTICE: This forum is archived as read only.
Please use the Github Discussions at https://github.com/exult/exult/discussions
Locked
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Warning to usecoders: Massive change in UCC

Post by marzo »

This is a warning I am giving to usecoders so that they know why suddenly UCC will be throwing hundreds of warnings and errors. If you complain about it, I will just point to this thread and laugh at you. You have been warned.

Those of you who do not toy with usecode can safely disregard this post.

The reason is that I have noticed a few things in the behavior of the original games which I have implemented in Exult/UCC/ES. Specifically:

In the original games, it seems that there were two kinds of functions:

Code: Select all

(1) object functions: with ids = 0x800, they have the following characteristics:
    (a) Have varying number of parameters, all of which are used;
    (b) Always called with CALL opcode, and thus they inherit the itemref of their 'parent'  function;
    (c) Never used in scripts and intrinsics;
    (d) They are never 'entry-points' for usecode;
    (e) Never passed to intrinsics;
    (f) May or may not return something.
For these reasons, I made a similar split in Exult/UCC/ES. With the already existing split of 'shape#' functions, this means that there are four categories of functions in UCC/ES:
- Class functions: functions declared in UCC classes;
- Shape functions: declared with 'shape#(id)';
- Object functions: declared with 'object#()' or 'object#(id)';
- Utility functions: all others.

Class and utility functions can have parameters and return values, but can't be used for NPCs, eggs, etc.

Shape and object functions cannot have parameters or return values, and are the only ones allowed for NPCs, eggs, etc.

Functions whose IDs are < 0x400 in UCC, but are not declared with 'shape#', will issue a warning and be treated as having an implicit 'shape#' in their declaration.

Likewise, non-shape functions whose IDs are < 0x800 in UCC, but are not declared with 'object#', will issue a warning and be treated as having an implicit 'object#' in their declaration.

Uses of intrinsics or non-shape, non-object functions in scripts or calle will issue compilation errors in UCC. UCC does a thorough job of identifying when you pass a valid function in such cases, but if it can't be sure, it will issue a warning and continue compilation.

That is all I can think of for now.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by Donfrow »

As I'm toying with usecode and still rather... lacking in knowledge about it I'm hoping I don't come off too too dumb with this.

If I have an NPC with usecode 0x561, it will issue a warning on compiling now because it is < 0x800 and not declared with object# ?

Ie,

TestNPC 0x561()

Would come up with the warning message?
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by marzo »

Yes. UCC would still compile the usecode and assume (correctly, in this case) that it is an 'object#' function, but it would issue the following warning:

Code: Select all

test.uc:3: Warning: Treating function 'TestNPC' as being an 'object#()' function.
If you changed the declaration to
TestNPC object#(0x561) ()
the warning would go away. For this particular case (and similar cases), the warning is harmless.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by Donfrow »

Ah ok, I understand that now.

As per functions, I assume what I refer to as a function isn't technically a function so I should ask this as well.

I use 'functions' when I have something that I use multiple NPC's, such as a buying some food using the autonumbering '#autonumber 0xC00' (which I believe I took directly from TFL). One example I have is:

BuyMeat(muttoncost, beefcost, fowlcost, hamcost)
{
Coding in here
}

If I understand correctly this would fall under the fourth function class as 'Utility' in your original post and not need to be declared and wouldn't put out a warning message. Is this correct?

Thanks again.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by marzo »

Yes, it is correct on all accounts. Although in the interest of completeness, you can also have auto-numbered object functions, with either of the following syntaxes:

Code: Select all

FunctionName object#() ()
or

Code: Select all

FunctionName object#(-1) ()
(you can use any negative number other than -1 too)
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Donfrow
Posts: 308
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by Donfrow »

I'm surprised I got that right. Thanks for the info.
Wizardry Dragon
Posts: 1241
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by Wizardry Dragon »

Hey Marzo,

1: Yes, it's me, try not to be too shocked.

2: Any chance you could go through TFL as is in CVS and fix the UCC to use the new changes?

Thanks,
Peter/Wizardry Dragon
Cheers, Wizardry Dragon
Lead Designer, Ultima VII: The Feudal Lands
www.thefeudallands.ca
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by marzo »

Yes, it's me, try not to be too shocked.
/me dies of shock
Any chance you could go through TFL as is in CVS and fix the UCC to use the new changes?
It is done already; I committed the changes in TFL at the same time I committed the changes in UCC.
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by Malignant Manor »

I can't find the new descriptions of these at Seven Towers~

- 'fire_cannon' intrinsic renamed to 'fire_projectile'; unknown parameters have been decoded and implemented. Also, this intrinsic is confirmed to be present in SI as intrinsic 0x8C.
- 'explode' intrinsic renamed to 'attack_object'; unknown parameters have been decoded and implemented.



I need to go through quite a few things. I might not use the newer compiler for the next release since I only think one thing is broken(exploding blackrock) as opposed to this block of text that won't compile. I know a couple fixed themselves, but it is still quite a bit.


Image
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by marzo »

I can't find the new descriptions of these at Seven Towers
Oops... forgot to upload a file. They should be there now.

As for the compiler messages: note that any warnings can be safely ignored (for example, the first 6 lines). And know that I share your pain (having had to update Keyring, TFL and SI Fixes).
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by Malignant Manor »

At least you knew pretty much what you had to do since you made the changes in the first place and also have a million times greater understanding than I do of coding and UCC.

I'm sure I'll do it sooner or later or just stick with the old stuff and be out of being able to use the cannon and blackrock. A new release using the old data means that I have an up to date backup for when I screw something up trying to convert.
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by marzo »

In general, the changes that must be made are along the following lines:
(a) all functions below 1024 (0x400) should be declared with "shape#";
(b) all functions below 2048 (0x800) should be declared with "object#";
(c) all functions intended for 'high' shapes must be declared with "shape#" (anyone that paid attention to me for quite a while would have been doing this already);
(d) functions used as parameters for intrinsics or the call opcode must be declared as "shape#" or "object#";
(e) functions declared as "shape#" or "object#" cannot have parameters or have a return value;
(f) functions declared as "shape#" or "object#" must be called in 'calle' form; i.e., "obj->Fun()";
(g) conversely, functions NOT declared as "shape#" or "object#" must NOT be called in 'calle' form (intrinsics, though, always can be);
(h) autonumbered functions which are meant to be used for scripts or intrinsics should use "object#()" or "object#(-1)".

In general, I tried to make the compiler as smart as possible when detecting if you are doing things "right", and I tried to make the warnings as descriptive as possible. Sometimes, multiple warnings/errors can be corrected with a single change -- for example, all the errors listed in your "items/BG_books_1.uc" file would go away with a single change (the bad thing is that another might come up...).
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by marzo »

Oh I forgot one: all functions intended to be used by eggs and NPCs should also be "object#" or "shape#" (preferably the former).
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by Malignant Manor »

How do you declare something as "utility"?
How do I use a function as a variable now?


This is breaking my spellbook.
example:

spellbook_1 shape#(1224) ()
{
var function;
function = &Weather;
call function, DOUBLECLICK;
}



My books functions are separated and won't work. They won't let me declare as shape or object.

example:

extern BG_BOOK_QUALITY_101_OR_MORE ();
extern BG_BOOK_QUALITY_100_OR_LESS ();

BG_BOOK_1 shape#(1301) ()
{
book_mode();
UI_play_sound_effect2(0x005E, item);
var quality = get_item_quality();

if (get_item_quality() > 100)
item->BG_BOOK_QUALITY_101_OR_MORE ();

else if (get_item_quality() BG_BOOK_QUALITY_100_OR_LESS ();
}



extern BG_BOOK_QUALITY_101_OR_MORE ();
extern BG_BOOK_QUALITY_100_OR_LESS ();

BG_BOOK_2 shape#(1302) ()
{
book_mode();
UI_play_sound_effect2(0x005E, item);
var quality = get_item_quality();

if (get_item_quality() > 100)
item->BG_BOOK_QUALITY_101_OR_MORE ();

else if (get_item_quality() BG_BOOK_QUALITY_100_OR_LESS ();
}


BG_BOOK_QUALITY_101_OR_MORE ()
{
var quality = get_item_quality();

if (quality == 101) say("101");
else if (quality == 148) say("148");
}


BG_BOOK_QUALITY_100_OR_LESS ()
{
var quality = get_item_quality();

if (quality == 0) say("0");
else say ("End of books");
return;
}
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by marzo »

How do you declare something as "utility"?
If by "utility" you mean anything not an "object#" or "shape#" function, it is declared without anything special. To clarify using your book example:
extern BG_BOOK_QUALITY_101_OR_MORE ();
This declares a "utility" function, while this:
item->BG_BOOK_QUALITY_101_OR_MORE ();
expects a "shape#" or "object#" function. Thus, a correct way to do your book example would be

Code: Select all

extern BG_BOOK_QUALITY_101_OR_MORE object#() ();
extern BG_BOOK_QUALITY_100_OR_LESS object#() ();

BG_BOOK_2 shape#(1302) ()
{
    book_mode();
    UI_play_sound_effect2(0x005E, item);
    var quality = get_item_quality();

    if (get_item_quality() > 100)
        item->BG_BOOK_QUALITY_101_OR_MORE ();

    else if (get_item_quality() BG_BOOK_QUALITY_100_OR_LESS ();
}


BG_BOOK_QUALITY_101_OR_MORE object#() ()
{
    var quality = get_item_quality();

    if (quality == 101) say("101");
    else if (quality == 148) say("148");
}


BG_BOOK_QUALITY_100_OR_LESS object#() ()
{
    var quality = get_item_quality();

    if (quality == 0) say("0");
    else say ("End of books");
    return;
}
Similarly, your "Weather" function needs the "object#" bit in its declaration (since it is not expected to be used as a function of any shape).
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Malignant Manor
Site Admin
Posts: 985
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by Malignant Manor »

Thanks, the book problem was me forgetting to change the externs as well. I think I have everything updated I just need to do more testing and finish a few things I want to release.

Why can setting a variable affect the result of a code? I hope these examples can explain what I'm saying. This example causes the object to get a target cursor even the part that doesn't use the variable. Although if it uses the variable, it won't get a second target cursor.

example ()
{
var click= UI_click_on_item();
var get_shape_click= UI_get_item_shape(click);

if (using var)
blah();
else if (not using var)
blah();
}


I have to put something like this so it doesn't mess up.

example ()
{
if (using var)
{
var click= UI_click_on_item();
var get_shape_click= UI_get_item_shape(click);

blah();
}
else if (not using var)
blah();
}
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: Warning to usecoders: Massive change in UCC

Post by marzo »

I am not sure what you mean; could you clarify? What I *think* you mean is that you were under the impression that the following code:

Code: Select all

var click= UI_click_on_item();
var get_shape_click= UI_get_item_shape(click);
would only get executed if you used the variables for something; if that is the case, this would be your problem: the iontrinsics get called (and the targeting cursor shown) at the moment the intrinsic appears (and thus, before the pseudo-code "if (using var)").
------
Marzo Sette Torres Junior
aka Geometrodynamic Dragon
[url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url]
Locked