selecting terrain tiles in code

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
agentorangeguy
Posts: 565
Joined: Thu May 14, 2020 1:34 pm

selecting terrain tiles in code

Post by agentorangeguy »

Is it possible to designate certain terrain tiles to be targeted in code with the UI_click_on_item(); intrinsic? I'm working on code for the shovel, but I can't seem to target terrain tiles successfully, but the same code I make will target actual items. Is there anything specifically i could do to target terrain tiles, like cavefloors and so on?
-------------------------------------------------------------------------------------
Ultima 6 Mod for Exult site: http://www.ultima6.realmofultima.com/
Colourless
Site Admin
Posts: 731
Joined: Thu May 14, 2020 1:34 pm

Re: selecting terrain tiles in code

Post by Colourless »

8x8 terrain tiles aren't items and I don't think there is anything in the code that would allow you to do what you'd want. An 'idea' could be to place specially crafted invisible items where you'd want to be able to dig, but that doesn't sound like what you'd want (a general solution). I think modifications to exult would be needed
agentorangeguy
Posts: 565
Joined: Thu May 14, 2020 1:34 pm

Re: selecting terrain tiles in code

Post by agentorangeguy »

Yeah I was kind of afraid of that. I'd have to blanket entire areas in the invisible items. I suppose maybe making an "invisible carpet" and naming it as "soft dirt" might work in the mean time..
-------------------------------------------------------------------------------------
Ultima 6 Mod for Exult site: http://www.ultima6.realmofultima.com/
marzo
Site Admin
Posts: 1925
Joined: Thu May 14, 2020 1:34 pm

Re: selecting terrain tiles in code

Post by marzo »

Just to expand on colourless' answer: UI_click_on_item targets either objects or tiles -- it always returns an array of the form {object, x, y, z} -- but you cannot do anything with a tile except use it to either place objects there or find stuff near it.

This might be enough for your purposes: if you want a specific tile to contain something, you hard-code the position in the shovel's usecode, and when the shovel is used at that location, you create the item and move it there.

Example:

Code: Select all

void Shovel shape#(xxx) () {
	var objpos = UI_click_on_item();
	if (objpos[0]) {
		AVATAR.say("There is something on the way, maybe I should try moving it fist.");
	} else {
		var x = objpos[1], y = objpos[2], z = objpos[3];
		var found = 0;
		if (x == 200 && y == 300 && z == 0) {
			AVATAR.say("@A-ha!@");
			found = UI_create_new_object(800);
			var gold = found->add_cont_items(10, 646, -359, 0, false);
		}
		if (found) {
			found->set_last_created();
			UI_update_last_created([x, y, z]);
		}
	}
}
------
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]
Colourless
Site Admin
Posts: 731
Joined: Thu May 14, 2020 1:34 pm

Re: selecting terrain tiles in code

Post by Colourless »

I think what agentorangeguy really would want is to be able tell what index+frame the tile is.

Thinking about it, it would be like implementing the 'is_water' water intrinsic as usecode itself.
Colourless
Site Admin
Posts: 731
Joined: Thu May 14, 2020 1:34 pm

Re: selecting terrain tiles in code

Post by Colourless »

Thinking about it, and looking at the code, would be simple enough to say extend UI_click_on_item to have an extra two elements returned (shape+frame) and then add a function to return the entire Shape_info structure for a shape.
agentorangeguy
Posts: 565
Joined: Thu May 14, 2020 1:34 pm

Re: selecting terrain tiles in code

Post by agentorangeguy »

I was hoping to use only certain tiles such as dirt dungeon floors, but only the "dirt" frames and not the "stone" frames, which would be too 'hard' to dig with a shovel. then, I set a random chance that you'll pull up a gold nugget, or a gem. Right now i have it like 1 in 25 chances. For regular grass tiles and regular dirt tiles, a less of a chance of pulling something up. This way, dungeons are more profitable to dig. Another snag I have is randomizing gems when dug up. i don't know if UI_create_object uses frames or not...
-------------------------------------------------------------------------------------
Ultima 6 Mod for Exult site: http://www.ultima6.realmofultima.com/
Scythifuge
Posts: 384
Joined: Thu May 14, 2020 1:34 pm

Re: selecting terrain tiles in code

Post by Scythifuge »

While z-value issues remain, as far as Exult not remembering anything above the original z-height value (as far as stackable objects & losing any z-height due to this method), the idea that I have for map building Savage Empire is to use tiles to lay out the landscape, & then place object-tiles drawn to resemble the environment on top of the tiles. This is to allow digging & destructible environments (such as craters when using player made grenades.)

You are probably too far along with your map for such a radical idea. However, maybe areas that need to be dug could be elevated one tile up, such as low hillocks. I remember some tiles in the original U6 that were shaded to give the illusion of elevated land.
agentorangeguy
Posts: 565
Joined: Thu May 14, 2020 1:34 pm

Re: selecting terrain tiles in code

Post by agentorangeguy »

Yes that would be an idea for certain spots that need to be dug up such as Hawkins' treasure area.
-------------------------------------------------------------------------------------
Ultima 6 Mod for Exult site: http://www.ultima6.realmofultima.com/
Locked