SRL Archive - Devs' Corner

Adding Items.simba, entire item database


Cstrike

2010-11-28 17:00:24

Pyroryan generated a great databse for us.

I edited all the stuff otu because the database is pretty big and would make some browsers crap out, but here's an example of the code

EDIT: Fixed, though will stretch the crap out of Simba.
{*******************************************************************************
function R_ReturnItem (NameOrID : Variant) : Variant;
By: pyroryan [database, aka: hard work], Cstrke [code, aka easy work]
Description: Input item name/ID to get back ID/item name.
*******************************************************************************}
function R_ReturnItem (NameOrID : Variant) : Variant;
var
ItemIDArray : TIntegerArray;
ItemNameArray : TStringArray;
i : Integer;
begin
ItemIDArray := [6, 8, ]; // shrunk
ItemNameArray := [ 'Cannon base', 'Cannon stand', ]; // shrunk
case VarType(NameOrID) of
varInteger: begin
Result := '';
for i:=0 to high(ItemIDArray) do
if ItemIDArray[i] = NameOrID then
begin
Result := ItemNameArray[i];
Exit;
end;
end;
varString: begin
Result := -1;
for i:=0 to high(ItemNameArray) do
if lowercase(ItemNameArray[i]) = lowercase(NameOrID) then
begin
Result := ItemIDArray[i];
Exit;
end;
end;
else
writeln ('[R_ReturnItem] Warning: Unsupported data type (you must enter an integer or string)');
end;
end;

Takes 15 milliseconds (!) to cycle through the entire array. Love computer power nowadays, and this is on my crap laptop too! In addition, method also got a *huge* library with even more stuff. I don't know how to convert it to this form though (for arrays).

Is this worth adding? Very useful IMO, great for when you don't know the ID of something, and in a function you can just call
DepositAllBut (R_ReturnItem('Harpoon'));

EDIT: Condensed function.

Sir R. M8gic1an

2010-11-28 17:10:35

Better be sure the code to update such a database is around…

Also, don't some objects have several IDs? (trees, rocks, etc)

And I think they'd be better off as types. It'd avoid mistakes in the biiig biiiig arrays:p

~RM

Cstrike

2010-11-28 17:14:49

From: Sir R. Magician
Better be sure the code to update such a database is around…

Also, don't some objects have several IDs? (trees, rocks, etc)

And I think they'd be better off as types. It'd avoid mistakes in the biiig biiiig arrays:p

~RM


So far with the main stuff done, people can update this (even I can easily update it now with a GE data gathering script). I can harvest 1000 items from GE in 5-10 minutes.
IIRC, Method had an even bigger one that had non-GE items.

BTW how would you go about the types?

Naike

2010-11-28 17:17:18

From: Sir R. Magician
Better be sure the code to update such a database is around…

Also, don't some objects have several IDs? (trees, rocks, etc)

And I think they'd be better off as types. It'd avoid mistakes in the biiig biiiig arrays:p

~RM


This is items only though :)
I'd like to have a function like this, great for many things.
Worth the effort!

Cstrike

2010-11-28 17:26:31

Uploaded

Sir R. M8gic1an

2010-11-28 17:33:24


TRefItem = record
Name: string;
ID: integer;

const
IRON_ORE = 0;

var AllItems: Array of TRefItem

Function RetrieveName(which:integer): string;
begin
Result := AllItems[which].Name;
end;

Function RetrieveID(which:integer): integer;
begin
Result := AllItems[which].ID;
end;

Procedure LoadItemArray;
begin
with AllItems[IRON_ORE] do
begin
Name := 'Iron Ore';
ID := 35235;
end;
end;

//shouldn't be too hard to make a script spit things out in this format ;)

~RM

pyroryan

2010-11-28 19:08:36

Go for it! Everything in our little private project should be placed into the reflection SVN anyways.

Coh3n

2010-11-28 20:05:18

From: Naike
This is items only though :)
I'd like to have a function like this, great for many things.
Worth the effort!

Method posted ID's in another thread and there were multiple IDs for a Bird's Nest. Not sure how many other items are like that though.

Post: http://villavu.com/forum/showpost.php?p=752526&postcount=36

Narcle

2010-11-29 00:37:19

Or you can just use a big TStringArray like so:

ItemList[ID] := 'name';

So when you put in the ID its basically instantly instead of searching the whole array, but with a name it would need to search the whole array then just Result.ID := i.

To set it up to declare the array you can just set the array length then

for i := 0 to High(items) do
if (Item.ID > -1) and (Item.Name <> '') then
ItemsList[Item.ID] := Item.Name;

If you get the idea.

Cstrike

2010-11-29 00:50:36

From: Narcle
Or you can just use a big TStringArray like so:

ItemList[ID] := 'name';

So when you put in the ID its basically instantly instead of searching the whole array, but with a name it would need to search the whole array then just Result.ID := i.

To set it up to declare the array you can just set the array length then

for i := 0 to High(items) do
if (Item.ID > -1) and (Item.Name <> '') then
ItemsList[Item.ID] := Item.Name;

If you get the idea.


If we use the entire item database with one big array, it causes simba to freak out and it returns nothing no matter what you put in :(

Narcle

2010-11-29 01:04:28

From: cstrike
If we use the entire item database with one big array, it causes simba to freak out and it returns nothing no matter what you put in :(


It would be only twice the size as the current array and only one array not 2… I didn't have trouble doing this in the past, as long as you code it right.

Cstrike

2010-11-29 01:22:35

From: Narcle
It would be only twice the size as the current array and only one array not 2… I didn't have trouble doing this in the past, as long as you code it right.


Sorry, my mistake:
I meant the full huge big database we're trying to implement.
For the current size, definitely :)

Sir R. M8gic1an

2010-11-29 08:20:40

From: cstrike
Sorry, my mistake:
I meant the full huge big database we're trying to implement.
For the current size, definitely :)


If it's too big just use functions, rather than arrays ;)

const
IRON_ORE = 0;

function GetID(which: integer): integer;
begin
case which of
IRON_ORE: result := 235325;
end;
end;

~RM

Narcle

2010-11-29 15:57:08

From: Sir R. Magician
If it's too big just use functions, rather than arrays ;)

const
IRON_ORE = 0;

function GetID(which: integer): integer;
begin
case which of
IRON_ORE: result := 235325;
end;
end;

~RM


^ The ids don't change so this could be used long term.

Naike

2010-11-29 16:14:07

If someone wants to write a function for all those items, go ahead.

For now, the current way is the smartest way to do it due lag and other weird stuff :\

Narcle

2010-11-29 17:08:55

Well so I made it real quick, wasn't to hard to do:

"The text that you have entered is too long (268489 characters). Please shorten it to 100000 characters long."

Link to pastebin: http://paste.villavu.com/show/128/

here's the odd thing:
Compiled succesfully in 7020 ms.
took: 0ms
6
took: 0ms
'Cannon base'
Successfully executed.
Takes 6-7 secs to compile but the return takes 0ms.

Cstrike

2010-11-29 17:14:13

:O

Would you be able to do what you did above with

1) A much bigger item list?

2) An object list of ~50,000 entries?

Just curious

Narcle

2010-11-29 17:16:33

From: cstrike
:O

Would you be able to do what you did above with

1) A much bigger item list?

2) An object list of ~50,000 entries?

Just curious


Idk, I'm concerned with the compile time. Do you have the ini list or w/e of all the items? I can load it from that and make a function using those and see if it'll work.