Author Topic: Ai vehicle factory contest  (Read 5068 times)

Offline HaXtOr

  • Sr. Member
  • ****
  • Posts: 423
    • http://www.wtfmoogle.com
Ai vehicle factory contest
« on: October 13, 2004, 10:29:31 PM »
Here is the scoop. I am going nuts trying to figure out how to program the dlls so that the ai bulds vehicles useing the vehicle fatcory.
As a result of me looseing almost a week of sleep over this problem I think im going a little crazy. several of you probably altready seen my op2 movie dll. anyways I am offering a prize of 1,000,000 IB credits to the first person who can show the code nessisary to make a ai produce vehicles at a vehicle factory. makeing it look like the vehicles are being built at a vehicle factory does not count.
the full code must be given to me and a working dll to prove the code works, codse myust me compileable.
good luck

Offline PlayingOutpost0-24

  • Hero Member
  • *****
  • Posts: 537
    • http://op3np.xfir.net
Ai vehicle factory contest
« Reply #1 on: October 14, 2004, 09:16:51 AM »
hehe i dont wanna go over LONG with my bank account, i am offerink 20,000,000 IB credits to whom solves this problem... (i find it an interesting problem :) )
Great news for OP2 fans... OP3 in progress.
Official Site
Outpost 3: A New Power progress
OP3:NP Discussion

Progress in OP3:NP[/size][/font]
PLANNING[|||||||||-]
GRAPHICS [||||------]
SOUNDS [|---------]
MAP DESIGNING [|||||-----]
CODING [----------]
Going slowly... Very slow.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Ai vehicle factory contest
« Reply #2 on: October 15, 2004, 01:20:22 AM »
I have a feeling this is not supported by the exported functions. DoDevelop comes close. It'll start building vehicles but the game will crash once they are finished. Even if it didn't, you still wouldn't be able to specify the weapon type.

Anyways, I have a solution that works. I can't post it yet. The code isn't quite ready. There are a few potential problems with using it. It seems unlikely that the code will fail but if it does, it would be a nightmare to support the people trying to use it. I may release code for a future template to handle it, but I'll likely distribute it as an already compiled .obj file that you just link with your DLL and a header file with the function declarations.

Anyways, I tested the code by building a ConVec and a Microwave Lynx. There is not trouble specifying a weapon. (But it looks like you can't specify a cargo for the ConVec, which shouldn't be surprising). Also, it appears you need the technology and the money for the build to proceed.

For the future, I may release code for doing certain things that the exported functions don't seem to let you do. I have a few candidate functions for future release. Let me know if there are any others you need which you don't think can be done with the exported functions. Here's something along the lines of what I mean:

Code: [Select]

_Player.GetColorNumber();
Unit.DoBuildUnit(enum map_id unitType, enum map_id weaponType); /* for VF */
Unit.DoResearch(int techID); /* For labs */
Unit.DoTrainScientists(int numScientists); /* For universities */
Unit.Load/Unload(int bay); /* for use with Garages and factories */
Unit.Bulldoze(int x1, int y1, int x2, int y2); /* For RoboDozers */

/* Perhaps Scatter for groups of units */
Unit.Repair
Unit.Reprogram
Unit.ExitMap
_Player.Ally()


Note: I quite likely will not add the functions as members of the _Player and Unit class, but it should give you an idea as to how they apply.


EDIT (leeor_net): added code formatting for readability
 
« Last Edit: August 08, 2017, 01:26:36 AM by leeor_net »

Offline zeritou

  • Full Member
  • ***
  • Posts: 149
Ai vehicle factory contest
« Reply #3 on: October 15, 2004, 09:56:39 AM »
i dont know squat about dll programming but i have an idea that may help

assign a number to each chassis/weapon
for instance
lynx=1
panther=2
tiger=3

laser=1
starflare=2
rail=3
thor=4

wright a line of code that says something to the effect of:

pick random number: 1 through 3
assign said number to variable X
pick random number: 1 through 4
assign said number to variable Y
produce unit X/Y

so say it picks X=2 and Y=1
unit X/Y would be a panther-laser
begin production of panther-laser

and then you would plug this into the script for a human player instead of where the the script that determines what the human player wants by where he or she clicked
how to insult a klingon:

qatlh Quch Hab ghaj no'ra'
vaj HabHa''a' je 'uSDu'lIj joj

wich translates roughly to:

how come you guys never had those for head bumps in the first staktrek series and do you guys have bumps like that on your genitals too?

Offline PlayingOutpost0-24

  • Hero Member
  • *****
  • Posts: 537
    • http://op3np.xfir.net
Ai vehicle factory contest
« Reply #4 on: October 15, 2004, 01:42:18 PM »
i have an idea... Repeated CreateUnit at the vehicle factory.
 
Great news for OP2 fans... OP3 in progress.
Official Site
Outpost 3: A New Power progress
OP3:NP Discussion

Progress in OP3:NP[/size][/font]
PLANNING[|||||||||-]
GRAPHICS [||||------]
SOUNDS [|---------]
MAP DESIGNING [|||||-----]
CODING [----------]
Going slowly... Very slow.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Ai vehicle factory contest
« Reply #5 on: October 15, 2004, 07:14:21 PM »
Yeah, I've suggested using CreateUnit like that before. That's faking it though. Besides, that adds problems with making the computer player play by the same rules as a human player. What if the Vehicle factory gets EMPed or damaged while something is "building". It won't really take that into account, and adding checks won't work so well either if you're using time triggers. It might kinda work with AIProc but that's kinda sick.

Zeritou: That's pretty much how it'd likely be done. I have a feeling that's how some DLLs work since not all the attack forces seem to be quite the same. Although, there's probably a better strategy than that. It'd be nice to have the computer make an intelligent choice on what units to build.

 

Offline PlayingOutpost0-24

  • Hero Member
  • *****
  • Posts: 537
    • http://op3np.xfir.net
Ai vehicle factory contest
« Reply #6 on: October 16, 2004, 07:33:47 AM »
y is checking a problem?

its like with plain text:

Code: [Select]
if timetrigger expires then
check if exists (vehiclefactory)
check if emped (vehiclefactory)
if all is FALSE then createunit(zeritou's template); reset timetrigger. else reset timetrigger. end if
end if
Great news for OP2 fans... OP3 in progress.
Official Site
Outpost 3: A New Power progress
OP3:NP Discussion

Progress in OP3:NP[/size][/font]
PLANNING[|||||||||-]
GRAPHICS [||||------]
SOUNDS [|---------]
MAP DESIGNING [|||||-----]
CODING [----------]
Going slowly... Very slow.

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Ai vehicle factory contest
« Reply #7 on: October 16, 2004, 07:48:33 AM »
Quote
y is checking a problem?

its like with plain text:

Code: [Select]
if timetrigger expires then
check if exists (vehiclefactory)
check if emped (vehiclefactory)
if all is FALSE then createunit(zeritou's template); reset timetrigger. else reset timetrigger. end if
end if
lol, That will create a vec without a vehicle factory.

Offline PlayingOutpost0-24

  • Hero Member
  • *****
  • Posts: 537
    • http://op3np.xfir.net
Ai vehicle factory contest
« Reply #8 on: October 16, 2004, 08:31:05 AM »
Quote
Quote
y is checking a problem?

its like with plain text:

Code: [Select]
if timetrigger expires then
check if exists (vehiclefactory)
check if emped (vehiclefactory)
if all is FALSE then createunit(zeritou's template); reset timetrigger. else reset timetrigger. end if
end if
lol, That will create a vec without a vehicle factory.
"check if exists". this is a part.
« Last Edit: October 16, 2004, 08:31:32 AM by PlayingOutpost0-24 »
Great news for OP2 fans... OP3 in progress.
Official Site
Outpost 3: A New Power progress
OP3:NP Discussion

Progress in OP3:NP[/size][/font]
PLANNING[|||||||||-]
GRAPHICS [||||------]
SOUNDS [|---------]
MAP DESIGNING [|||||-----]
CODING [----------]
Going slowly... Very slow.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Ai vehicle factory contest
« Reply #9 on: October 16, 2004, 02:04:18 PM »
lol, "if all is FALSE"

Anyways, you're overlooking exactly the problem I thought you might. EMP wears off, so if the VF is EMP but then recovers by the time the trigger fires, the unit will still build, with no delay in building time. Same thing if the vehicle factory is disabled due to damage but then repaired before the trigger fires. If you want it accurate, you can't just use a trigger because things can happen to the VF between the time for the trigger firing.

Plus, that ifExists then could be a problem if the building is destroyed and is being replaced with a new one. It might exists, even though it's not finished building. Besides, there are just way too many checks, or things to consider for it to really seem worthwhile.
 

Offline HaXtOr

  • Sr. Member
  • ****
  • Posts: 423
    • http://www.wtfmoogle.com
Ai vehicle factory contest
« Reply #10 on: October 18, 2004, 06:12:39 PM »
The prize goes to hooman for helping me figure it out

Code: [Select]

UnitRecord unitRecord1[] =
{
    { map_Vehicle_Factory,    0x30, 0x10, 0, 0, map_None, 0x10, 0, 0 },
    { map_Structure_Factory,  0x30, 0x14, 0, 0, map_None, 0x10, 0, 0 },
    { map_Command_Center,     0x30, 0x17, 0, 0, map_None, 0x10, 0, 0 },
    { map_Common_Ore_Smelter, 0x30, 0x1A, 0, 0, map_None, 0x10, 0, 0 },
    { map_Rare_Ore_Smelter,   0x30, 0x1E, 0, 0, map_None, 0x10, 0, 0 },
    { map_Tokamak,            0x23, 0x03, 0, 0, map_None, 0x10, 0, 0 },
    { map_ConVec,             0x32, 0x14, 0, 0, map_None, 0x10, 0, 0 },
    { map_Cargo_Truck,        0x34, 0x10, 0, 0, map_None, 0x10, trck_Rare_Metal, 1000 },
    { map_Tiger,              0x34, 0x17, 0, 0, map_Thors_Hammer, 0x10, 0, 0 },
    { map_None,                  0,    0, 0, 0, map_None, 0,  0, 0 }
};

UnitBlock unitBlock1(unitRecord1);

Unit u1, u2, u3, u4, u5, u6, retUnit;

TethysGame::CreateUnit(u2, map_Vehicle_Factory, LOCATION(48, 15), 0, map_None, 0);

BuildingGroup &bld= CreateBuildingGroup(Player[0]);

bld.TakeUnit(u2);
bld.RecordVehReinforceGroup(bld,5);
bld.SetTargCount(map_Tiger,map_Thors_Hammer,15);
bld.RecordUnitBlock(unitBlock1);

bld.SetRect(MAP_RECT(48,15,90,90));



EDIT (leeor_net): added code tags for readability
« Last Edit: August 08, 2017, 01:31:20 AM by leeor_net »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Ai vehicle factory contest
« Reply #11 on: October 18, 2004, 07:56:22 PM »
Woohoo!  (thumbsup)

Actually, that's quite helpful to know that works. I'm glad you worked on it. Be sure to post any more results or clairifications on how things work if you come across any more info on it.
 

Offline zeritou

  • Full Member
  • ***
  • Posts: 149
Ai vehicle factory contest
« Reply #12 on: October 19, 2004, 09:17:15 AM »
again since i know nothing abot dll programming im confused by that string of code so im going to request a regression back to laymans terms with the dll, in the mean time im going to ammend my first idea and ask for only 28% of the prize if my idea gets used


Quote
assign a number to each chassis/weapon
for instance
lynx=1
panther=2
tiger=3

laser=1
starflare=2
rail=3
thor=4

wright a line of code that says something to the effect of:

pick random number: 1 through 3
assign said number to variable X
pick random number: 1 through 4
assign said number to variable Y
produce unit X/Y

so say it picks X=2 and Y=1
unit X/Y would be a panther-laser
begin production of panther-laser

and then you would plug this into the script for a human player instead of where the the script that determines what the human player wants by where he or she clicked

the end of this says to substitute this rough draft of a formula in place of where a human player would click to choose which unit said human player wanted

if this were used as a replacement instead of a click, it would tell the AI building to start producing the unit the same way and under the same rules that a players building would

this is my graphical representation, i dont want this grapic representation used ever again to discribe the same thing.
disclamer: i do not in any way shape or form use these smileys to show my likes or dislikes of anything

this would be the script for a human building to start making a laser lynx
 <_<
the moving hand would be my rough formula/script making the AI build script look like this
 (thumbsdown)

edit: finished this my next class

 
« Last Edit: October 19, 2004, 09:32:41 AM by zeritou »
how to insult a klingon:

qatlh Quch Hab ghaj no'ra'
vaj HabHa''a' je 'uSDu'lIj joj

wich translates roughly to:

how come you guys never had those for head bumps in the first staktrek series and do you guys have bumps like that on your genitals too?

Offline PlayingOutpost0-24

  • Hero Member
  • *****
  • Posts: 537
    • http://op3np.xfir.net
Ai vehicle factory contest
« Reply #13 on: October 19, 2004, 10:41:27 AM »
Quote
Anyways, you're overlooking exactly the problem I thought you might. EMP wears off, so if the VF is EMP but then recovers by the time the trigger fires, the unit will still build, with no delay in building time. Same thing if the vehicle factory is disabled due to damage but then repaired before the trigger fires. If you want it accurate, you can't just use a trigger because things can happen to the VF between the time for the trigger firing.

if timetrigger expires then
check if built (vehiclefactory)
check if emped (vehiclefactory)
if all is FALSE then createunit(zeritou's template); reset timetrigger. else reset timetrigger. end if
end if

and BTW, look at this part: reset timetrigger. else reset timetrigger.

that would mean...

U= create R= reset.

|-----------------------------------_|
|-----------_|EMPED|NOT EMPED |
| BUILT ----| U R --| R ----------_|
|NOT BUILT| R ---_| R ----------_|
|-----------_|________________-|
« Last Edit: October 19, 2004, 10:45:12 AM by PlayingOutpost0-24 »
Great news for OP2 fans... OP3 in progress.
Official Site
Outpost 3: A New Power progress
OP3:NP Discussion

Progress in OP3:NP[/size][/font]
PLANNING[|||||||||-]
GRAPHICS [||||------]
SOUNDS [|---------]
MAP DESIGNING [|||||-----]
CODING [----------]
Going slowly... Very slow.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Ai vehicle factory contest
« Reply #14 on: October 19, 2004, 04:01:13 PM »
Hmm, DLL programming isn't exactly like replacing user input with scripted input. It's more like an alternative form of input. There's nothing stopping the game from using both, and you can't exactly get rid of the user input (without hacking the exe). (But anyways, just a minor point here.  :P )

Anyways, PlayingOutpost: stop trying to patch up your idea, it'll never work right!  :P (lol, j/k) It might kinda work, and kinda work better, but you'd be best to leave it and try another idea. Besides, it looks like Haxtor figured it out. It can be done and with the regular exported functions. I guess I was wrong when I suggested it couldn't be done with the exported functions. Anyways, it can be done, just not as a direct order to the building to build exactly one unit (but maybe as a roundabout way if that's what you really wanted). At least that's the restriction if you're using the exported functions. But the way it's done is exactly the way that's needed.

Btw, PlayingOutpost: It appears you'd have to patch your solution again if you stayed on this train of thought.  :heh:

Quote
check if built (vehiclefactory)
Quote
if all is FALSE then createunit
That'll create a unit only if the building isn't built.  :lol:

But yeah, I see where you're going with this. Although, the reset should really be more of a pause if the building is EMPed. Especially if resources have already been spent on the unit. The real problem with this method is determining how long to pause in the case of EMP. You'd have to monitor the structure every game cycle to get an accurate time. So, yeah I guess you could possibly get it to work but the code would be huge and complicated. Essentially you'd have to do it without triggers to get it to be accurate.

But yeah, if there was no other way, your idea would probably be the best way of faking it.
 

Offline PlayingOutpost0-24

  • Hero Member
  • *****
  • Posts: 537
    • http://op3np.xfir.net
Ai vehicle factory contest
« Reply #15 on: October 22, 2004, 05:46:58 PM »
EVERY CODE is huge and complicated :)

but nevermind

if (1=true) and (2=false) then createunit

BTW i meant like timetrigger 20 secs

if expired then it does the check and creates an unit if conditions are met, and ALWAYS sets back timetrigger to 20. that means it checks BOTH every 20 secs.
but if we want something reality...

<INSERT>
if (2=true) then check EMPtime remaining; pause timetrigger.
if EMP_wornofff then reset timetrigger
« Last Edit: October 22, 2004, 05:51:59 PM by PlayingOutpost0-24 »
Great news for OP2 fans... OP3 in progress.
Official Site
Outpost 3: A New Power progress
OP3:NP Discussion

Progress in OP3:NP[/size][/font]
PLANNING[|||||||||-]
GRAPHICS [||||------]
SOUNDS [|---------]
MAP DESIGNING [|||||-----]
CODING [----------]
Going slowly... Very slow.

Offline zeritou

  • Full Member
  • ***
  • Posts: 149
Ai vehicle factory contest
« Reply #16 on: October 27, 2004, 03:08:33 PM »
Quote
Hmm, DLL programming isn't exactly like replacing user input with scripted input. It's more like an alternative form of input. There's nothing stopping the game from using both, and you can't exactly get rid of the user input

its the same thing!

and im not suggesting getting rid of user input im suggesting copying and patching the code to make it into an ai player to play against
« Last Edit: October 27, 2004, 03:09:24 PM by zeritou »
how to insult a klingon:

qatlh Quch Hab ghaj no'ra'
vaj HabHa''a' je 'uSDu'lIj joj

wich translates roughly to:

how come you guys never had those for head bumps in the first staktrek series and do you guys have bumps like that on your genitals too?

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Ai vehicle factory contest
« Reply #17 on: October 27, 2004, 08:27:51 PM »
Hmm, the point I guess I'm trying to get across is that there isn't exactly an equivalent exported function for everything the player can do. For instance, there is no way to make a lab research using the exported functions. I also don't know of any way to tell a RoboDozer to bulldoze an area with the exported functions.

In other words, an AI that's built in this manner is going to be lacking in some way. The method of input the user has just doesn't exists for an AI.

Anyways, I'm doing some work on this with some success. I've found a way of bypassing having to use the exported functions. This has allowed me to do a few extra things for which the exported functions have no equivalent. The test project still needs work though. It'll be a while before I'd be comfortable releasing any of it. Even if I do, it'd probably be in some controlled form like .obj and .h file only.

Also, programming an AI isn't as easy as you might think. There are a lot of things a player can do that are very difficult to describe to a computer. Plus you often have the problem of predictability which can be a big weakness in an AI. And don't think a few random numbers will solve the problem of predictability. It really won't in most cases. Especially since an AI isn't really capable of learning (in most cases) or if it is, it's usually fairly limited in what it can learn or the way in which it learns it.

As an example of what I mean, consider using terrain to defend your base. You only have to defend the gaps in the ridges. How would you program an AI to find these gaps? If you can't reduce this problem down to examining a 2D array of boolean values for whether or not that tile is passable, then your solution is useless.
 

Offline zeritou

  • Full Member
  • ***
  • Posts: 149
Ai vehicle factory contest
« Reply #18 on: October 28, 2004, 09:44:50 AM »
i just suggested replacing user input for this one thing not for everything a player could possibly do, the rest of the ai has been figured (or so im led to belive)

edit: a note to haxtor, im sorry this is getting of the topic of making a dll for an ai vech fac and on to the topic of wether or notyou can replace all the aspects of a human
« Last Edit: October 28, 2004, 09:48:09 AM by zeritou »
how to insult a klingon:

qatlh Quch Hab ghaj no'ra'
vaj HabHa''a' je 'uSDu'lIj joj

wich translates roughly to:

how come you guys never had those for head bumps in the first staktrek series and do you guys have bumps like that on your genitals too?

Offline BlackBox

  • Administrator
  • Hero Member
  • *****
  • Posts: 3093
Ai vehicle factory contest
« Reply #19 on: October 28, 2004, 03:07:32 PM »
I'll clear up a common misconception about OP2. There is NOT any 'default' AI in the game. ALL of the computer player's AI is up to the DLL programmer to implement.

And like Hooman said, the game doesn't export a lot of things. The only way to make it do anything is to actually send a command directly to the game engine.

Hooman and I are the only ones that have the code, etc needed to do this, and we don't plan to release all of it for certain reasons (e.g. it could be used to cheat, because you can emulate ANY action in the game engine; e.g you could fake a player exit message, or anything else for that matter).

If we choose to release any 'special functionality' things out for the public, it will probably be wrapped up in .obj or .lib and .h files that you include to do specific things (eg. do research at a lab, bulldoze terrain, etc)