TGC Codebase Backup



The Godfather: AI Negotiations by Libervurto

24th Jun 2007 22:09
Summary

A demo of the negotiation system that I may used in my strategy game "The Godfather". The mouse controls your hand, move closer to increase your opponent's percentage and



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `** NEGOTIATIONS **
set display mode 1024,768,16
hide mouse
sync on

`load media
cd "cursor"
load image "negL.bmp",1
load image "negR.bmp",2
load image "shake.bmp",3
cd "../"
load image "vito.bmp",4
load image "opponent.bmp",5
load image "small.bmp",6

DO
`formatting
ink rgb(255,255,255),0
set text font "Gloucester MT extra condensed"
t = 24
set text size t
`* WELCOME SCREEN
cls
paste image 6,380,20
tm = 280
center text 512,tm+t*0, "THE GODFATHER: NEGOTIATION DEMO"
center text 512,tm+t*1, "In the full version of the game you will need to negotiate with business owners, racket bosses, contraband suppliers, police chiefs and politicians."
center text 512,tm+t*2, "Evidently, being a good negotiator is vital if you are to secure the protection money, supplies, investments, legal protection and political influence required to increase the Corleones' power."
center text 512,tm+t*3, "The art of negotiation is all about compromise; by making a compromise, and moving your hand forward, you entice your opponent to make a compromise himself."
center text 512,tm+t*4, "When making a compromise your opponent is acting in the heat of the moment, while in this state retracting your hand will draw him in, and he will make a considerable compromise."
center text 512,tm+t*5, "Depending on the skill of your opponent, you will only have a small window of opportunity to seal a favorable deal before he realises his weak position."
center text 512,tm+t*6, "Use the mouse to move your hand towards or away from you opponent. You must shake your opponent's hand to agree a deal before the time expires."
center text 512,tm+t*7, "As time runs out, your opponent will be willing to make a bigger compromise, in order to seal the deal."
center text 512,tm+t*12, "(Pressing ESCAPE at any time will exit this demo)"
ink rgb(230,0,0),0
center text 512,tm+t*9, "Use the keyboard to set the negotiation skill of your opponent."
`# negotiation skill parameter
set cursor 415,tm+t*10
input "(1 = best, 20 = worst)> "; TOLMAX
center text 512,tm+t*11, "CLICK THE MOUSE TO BEGIN NEGOTIATIONS"
suspend for mouse
sync
`show sprites
if sprite exist(1) then show sprite 1 : show sprite 2

`Adjust tolmax
if TOLMAX < 1 then TOLMAX = 1
if TOLMAX > 20 then TOLMAX = 20
sync
`# variables
PPOS = 0
OPOS = 0
DEST = 0
TIME# = 20
Pimg = 1

`@ Loop
Repeat

`Is player at least meeting what the opponent desires?
If PPOS >= (100 - DEST)
   `is player too eager? (exceeding the opponent's tolerance)
   If PPOS >= (100 - DEST) + TOL
      move = (100-PPOS)/28 : if move < 1 then move = 1
      dec OPOS, move
      dec DEST, 1
      inc TOL, 1
   Else
      `check OPOS is less than his desired deal before incrementing
      If OPOS < DEST
         `the better deal the player offers the quicker the opponent moves
         move = PPOS/28 : if move < 1 then move = 1
         inc OPOS, move : if OPOS + PPOS > 100 then OPOS = 100-PPOS
         inc TOL, 1
      endif
   Endif
Else
   `does player force compromise? (within Tolerance boundary)
   If PPOS >= (100 - DEST) - TTOL
      move = PPOS/28 : if move < 1 then move = 1
      inc OPOS, move : if OPOS + PPOS > 100 then OPOS = 100-PPOS
      inc DEST, 1
      dec TOL, 1
   ELSE
      `the worse deal the player offers the quicker the opponent retreats
      move = (100-PPOS)/28 : if move < 1 then move = 1
      dec OPOS, move
      DEST = (PPOS/1.6) + (OPOS/2)
   Endif
Endif

`TIME TOLERANCE
dec TIME#, 0.019
TIMETOL = (TOLMAX/5) * ( (20-TIME#) / 5)

`Total Tolerance
TTMAX = TOLMAX + TIMETOL
`!!! NOT WORKING !!!
`TTOL = TOL + TIMETOL
TTOL = TOL

`variable boundaries
if PPOS < 1 then PPOS = 1
if PPOS > 99 then PPOS = 99
if OPOS < 1 then OPOS = 1
if OPOS > 99 then OPOS = 99
if DEST < 1 then DEST = 1
if DEST > 99 then DEST = 99
IF TOL < 1 then TOL = 1
IF TOL > TTMAX then TOL = TTMAX

`+ Controls
mmove = mousemovex()/2
if mmove + OPOS + PPOS < 100 and mmove + PPOS > 1 then inc PPOS,mmove

`+ Display
cls
`MAKE DEAL
if PPOS + OPOS = 100
   Pimg = 3
   if sprite exist(2) then hide sprite 2
else
   if sprite exist(2) then show sprite 2
   Pimg = 1
endif

`bar
ink rgb(255,255,255),0
box 200,251,400,252
line 300,246,300,257
`Portraits
paste image 4,130,200
paste image 5,420,200
`hands (opp under player)
sprite 2, 400-(OPOS*2), 250, 2
sprite 1, 200+(PPOS*2), 250, Pimg
offset sprite 1, sprite width(1)/2, sprite height(1)/2
offset sprite 2, sprite width(2)/2, sprite height(2)/2

set text size 22
`Portrait Captions
center text 155, 310, "Vito Corleone"
center text 445, 310, "Opponent (Skill: " + str$(TOLMAX) + ")"
`format time
time$ = str$(int(time#))
time$ = time$ + "." + mid$(str$(time#),len(time$)+2)
`time
set text size 40
if time# < 10 then ink rgb(230,0,0),0 : set text size 50
`bulging text
if time# < 5
   bulge = wrapvalue(bulge + 7)
   set text size 60+(sin(bulge)*5)
   ink rgb(230+(sin(bulge)*25),0,0),0
endif
center text 300, 160, time$

`progammer info
if shiftkey() = 1
   set text size t
   text 0,t*0, "TIME REMAINING: " + time$
   text 0,t*1, "Corleone offer: " + STR$(PPOS) + "%"
   text 0,t*2, "Opponent offer: " + STR$(OPOS) + "%"
   text 0,t*3, "Opponent Wants: " + STR$(100-DEST-TTOL) + "%"
   text 0,t*4, "Opponent Skill: " + STR$(TOLMAX)
endif

sync

Until PPOS + OPOS = 100 or Time# <= 0

`print result and restart
set text size t
if PPOS + OPOS = 100 then text 0,0,"A deal has been agreed. You have secured an interest of " + str$(OPOS) + "% for the Corleone family."
if Time# <= 0 then text 0,0,"You failed to reach an agreement."
sync
suspend for mouse
hide sprite 1 : hide sprite 2

LOOP