I am not using EnableExplicit since I have a lot of variables that start at either "0" or are blank strings. Many are just temporary storage for all the Random() results in my procedures.
Many thanks again, after your tweak the enemies are no longer receiving two handed weapons when they shouldn't. I could have easily wrote it like that but I must have fried my brain overthinking it...
I broke it again... I combined all the basics into one file for error checking the logic line by line. I noticed the cause of my lock up was the ELSE statement in my section for handling what weapon is selected after a category is picked. But now my code is failing to pass the "selected weapon" into the variables to contain the data. Which is odd because the only thing I changed other than adding more strict "And" statements to the weapon selection I changed the weapons ID's to constants. That way everytime I add a new item in the middle of the list I don't have to incriment all the weapons from 1 to 60. I instead just say hey there are 6 smallguns and they are 1 to 6 or how many rifles are there? There are 10 so pick from these 10 instead.
Part#2 please combine it with the above code.
When you run it you will see that it randomly picks a category and weapon based upon the enemy selected. Which in this case is the "Lone Bandit". I took out all the other types for testing. Please hit "Z" and enter to restart the sequence.
; What weapon was selected and show description.
Procedure Display_Selected_Weapon()
PrintN(" Weapon name: "+WPN_name+"")
PrintN(" Description: "+WPN_desc+"")
PrintN(" Attack variety: "+Atk_Variety+"")
PrintN(" Damage type 1: "+Damage_type1+"")
If Damage_type2 <> #Empty$
PrintN(" Damage type 2: "+Damage_type2+"")
EndIf
PrintN(" Max damage: "+Damage_Mx+"")
PrintN(" Min damage: "+Damage_Mn+"")
PrintN(" AP cost:"+APcost+"")
PrintN(" Weapon Range: "+WPNRange+" ft")
If ThrwWPNRange <> 0
PrintN(" Thrown Range:"+ThrwWPNRange+"ft")
EndIf
PrintN(" Min STR needed: "+Min_ST+"")
If Ammunition <> ""
PrintN(" Ammunition: "+Ammunition+"")
EndIf
If Hands_req <> 0
PrintN(" Hands required: "+Hands_req+"")
EndIf
If Magazine_Size <> 0
PrintN(" Magazine size: "+Magazine_Size+"")
EndIf
If Value <> 0
PrintN(" Item value: "+Value+"")
EndIf
If Item_lb <> 0
PrintN(" Item weight: "+Item_lb+" lbs")
EndIf
EndProcedure
; Randomize selected Category.
Procedure Randomize_Enemy_Weapon_WPN_Category()
PrintN(" *Randomizing Category Selection*")
RandomEMweapon:
;Result = 0
;WPN_Selected = #False
;-----------------------------------------------
;Pick a catagory
;-----------------------------------------------
Result = Random(12,1) ; change 12 to 13 later - have no explosive users yet!
If Result = #creaturebite And Enemy_CanUse_bite = #True
WPN_Category = "Creature Bite"
Selected_Category = #creaturebite
ElseIf Result = #creatureclaws And Enemy_CanUse_claws = #True
WPN_Category = "Creature Claws"
Selected_Category = #creatureclaws
ElseIf Result = #unarmed And Enemy_CanUse_unarmed = #True
WPN_Category = "Unarmed"
Selected_Category = #unarmed
ElseIf Result = #armed And Enemy_CanUse_armed = #True
WPN_Category = "Armed"
Selected_Category = #armed
ElseIf Result = #thrown And Enemy_CanUse_thrown = #True
WPN_Category = "Thrown"
Selected_Category = #thrown
ElseIf Result = #smallguns And Enemy_CanUse_smallguns = #True
WPN_Category = "Smallguns"
Selected_Category = #smallguns
ElseIf Result = #shotguns And Enemy_CanUse_shotguns = #True
WPN_Category = "Shotguns"
Selected_Category = #shotguns
ElseIf Result = #rifles And Enemy_CanUse_rifles = #True
WPN_Category = "Rifles"
Selected_Category = #rifles
ElseIf Result = #assault_rifles And Enemy_CanUse_assault_rifles = #True ;<--- Watch for spelling errors! This is what was causing the error of it failing to reset and giving the wrong items out!!!! Did not match Global name.
WPN_Category = "Assault Rifles"
Selected_Category = #assault_rifles
ElseIf Result = #assault_rifles And Enemy_CanUse_machineguns = #True
WPN_Category = "Machineguns"
Selected_Category = #machineguns
ElseIf Result = #heavyweapons And Enemy_CanUse_heavyweapons = #True
WPN_Category = "Heavyweapons"
Selected_Category = #heavyweapons
ElseIf Result = #energyweapons And Enemy_CanUse_energyweapons = #True
WPN_Category = "Energyweapons"
Selected_Category = #energyweapons
ElseIf Result = #explosiveweapons And Enemy_CanUse_explosiveweapons = #True
WPN_Category = "Explosive weapons"
Selected_Category = #explosiveweapons
Else
; TURN THIS ON IF YOU WANT TO SEE THE REROLLING ON CONDITION. Sometimes the game appears STUCK here...
;PrintN(" Failed result: " +Result+"")
;Delay(10)
;PrintN(" No valid condition...")
;Delay(10)
;PrintN(" Re-rolling...")
LoopCounter + 1 ; For the error checking routine at bottom.
If LoopCounter => 500 ; I put this error check in because sometimes the simulation seems to get stuck.
PrintN(" ERROR COUNTER HAS RAN: " +GotoLoopCounter+" TIMES FOR CATEGORY SELECTION...")
Delay(500)
PrintN(" The enemy selected: "+EnemyTitle+"")
PrintN(" Current Weapon Catagory: "+WPN_Category+"")
PrintN(" Bite= "+Enemy_CanUse_bite+"")
PrintN(" Claws= "+Enemy_CanUse_claws+"")
PrintN(" Unarmed= "+Enemy_CanUse_unarmed+"")
PrintN(" Armed= "+Enemy_CanUse_armed+"")
PrintN(" Thrown= "+Enemy_CanUse_thrown+"")
PrintN(" Smallguns= "+Enemy_CanUse_smallguns+"")
PrintN(" Shotguns= "+Enemy_CanUse_shotguns+"")
PrintN(" Rifles= "+Enemy_CanUse_rifles+"")
PrintN(" AssaultRifles= "+Enemy_CanUse_assault_rifles+"")
PrintN(" Machineguns= "+Enemy_CanUse_machineguns+"")
PrintN(" Heavyweapons= "+Enemy_CanUse_heavyweapons+"")
PrintN(" Energyweapons= "+Enemy_CanUse_energyweapons+"")
PrintN(" Explosives= "+Enemy_CanUse_explosiveweapons+"")
PrintN(" Check this routine for logic errors, spelling errors, or missing data!!!")
Input()
End
EndIf
Goto RandomEMweapon
EndIf
Delay(100)
PrintN(" DONE... Result is: "+Result+" Category: "+Selected_Category+" Selected type:"+WPN_Category+"") ; <--- This shows If the catagory integer is actually changing.
EndProcedure
; Randomize weapon based on category.
Procedure Set_Randomized_Weapon()
PrintN(" *Randomizing Weapon Selection*")
PrintN(" Selected Category: "+WPN_Category+"") ; <--- This shows If the catagory integer is actually changing.
PickEMweapon:
If Selected_Category = #creaturebite ; does not work with CONSTANTS in place! #creaturebite
Result = Random(1,1)
If Result = #Bite
WPN_Selected = #Bite
EndIf
ElseIf Selected_Category = #creatureclaws
Result = Random(1,1)
If Result = #Claw
WPN_Selected = #Claw
EndIf
ElseIf Selected_Category = #unarmed
Result = Random(1,1)
If Result =1
WPN_Selected = #Fists
EndIf
ElseIf Selected_Category = #armed
Category_Armed:
Result = Random(14,1) ;Pick between these weapons
If Result = #SmallKnife ; <-- This way is easier to read instead of using integers.
WPN_Selected = #SmallKnife ; <-- The WEAPON ID in Globals MUST MATCH or this wont work.
ElseIf Result = #CombatKnife
WPN_Selected = #CombatKnife
ElseIf Result = #Wakizashi ;And EnemyForce <> #TribalWomen
WPN_Selected = #Wakizashi
ElseIf Result = #Katana ;And EnemyForce <> #TribalWomen
WPN_Selected = #Katana
ElseIf Result = #Axe
WPN_Selected = #Axe
ElseIf Result = #Wrench ;EnemyForce <> #TribalWomen ; Dont allow this enemy to use this and if Wrench is selected then re-roll the ARMED category.
WPN_Selected = #Wrench
ElseIf Result = #Crowbar
WPN_Selected = #Crowbar
ElseIf Result = #BaseballBat ;And EnemyForce <> #TribalWomen
WPN_Selected = #BaseballBat
ElseIf Result = #Club
WPN_Selected = #Club
ElseIf Result = #SledgeHammer
WPN_Selected = #SledgeHammer
ElseIf Result = #WoodStaff
WPN_Selected = #WoodStaff
ElseIf Result = #Brassknuckles ;And EnemyForce <> #TribalWomen
WPN_Selected = #Brassknuckles
ElseIf Result = #SpikedBrassKnuckles
WPN_Selected = #SpikedBrassKnuckles
ElseIf Result = #CattleProd ;And EnemyForce <> #TribalWomen
WPN_Selected = #CattleProd
EndIf
ElseIf Selected_Category = #thrown
Result = Random(5,1);Pick between these weapons 17 and 21
If Result = #Tomahawk
WPN_Selected = #Tomahawk
ElseIf Result = #CombatTomahawk
WPN_Selected = #CombatTomahawk
ElseIf Result = #SharpenedPole
WPN_Selected = #SharpenedPole
ElseIf Result =#CrudeSpear
WPN_Selected=#FineSpear
EndIf
ElseIf Selected_Category = #smallguns
Result = Random(4,1);Pick between these weapons
If Result = #CrudePipePistol
WPN_Selected = #CrudePipePistol
ElseIf Result = #Revolver
WPN_Selected = #Revolver
ElseIf Result = #RareRevolver
WPN_Selected = #RareRevolver
ElseIf Result = #BerretaM9Pistol
WPN_Selected = #BerretaM9Pistol
EndIf
ElseIf Selected_Category = #shotguns
Result = Random(7,1);Pick between these weapons
If Result = #CrudePipeShotgun
WPN_Selected = #CrudePipeShotgun
ElseIf Result = #Blunderbuss
WPN_Selected = #Blunderbuss
ElseIf Result = #WornSawedoffShotgun
WPN_Selected = #WornSawedoffShotgun
ElseIf Result = #SawedoffShotgun
WPN_Selected = #SawedoffShotgun
ElseIf Result = #Shotgun
WPN_Selected = #Shotgun
ElseIf Result = #CombatShotgun
WPN_Selected = #CombatShotgun
ElseIf Result = #PancorJackhammer
WPN_Selected = #PancorJackhammer
EndIf
ElseIf Selected_Category = #rifles
Result = Random(2,1);Pick between these weapons
If Result = #HomeMadeRifle
WPN_Selected = #HomeMadeRifle
ElseIf Result = #BoltActionRifle
WPN_Selected = #BoltActionRifle
EndIf
ElseIf Selected_Category = #assault_rifles
Result = Random(1,1)
If Result = #M16
WPN_Selected = #M16
EndIf
ElseIf Selected_Category = 10
Result = Random(1,1)
If Result = #M60
WPN_Selected = #M60
EndIf
ElseIf Selected_Category = #machineguns
Result = Random(2,1);Pick between these weapons
If Result = #ImprovisedFlameThrower
WPN_Selected = #ImprovisedFlameThrower
ElseIf Result = #M9A17FlameThrower
WPN_Selected = #M9A17FlameThrower
EndIf
ElseIf Selected_Category = #heavyweapons
Result = Random(8,1);Pick between these weapons
If Result = #LaserPistol
WPN_Selected = #LaserPistol
ElseIf Result = #LaserRifle
WPN_Selected = #LaserRifle
ElseIf Result = #EnhancedLaserPistol
WPN_Selected = #EnhancedLaserPistol
ElseIf Result = #EnhancedLaserRifle
WPN_Selected = #EnhancedLaserRifle
ElseIf Result = #PhasedPlasmaPulseGun40Watt
WPN_Selected = #PhasedPlasmaPulseGun40Watt
ElseIf Result = #PhasedPlasmaPulseGun80Watt
WPN_Selected = #PhasedPlasmaPulseGun80Watt
ElseIf Result = #PhasedPlasmaPulseGun100Watt
WPN_Selected = #PhasedPlasmaPulseGun100Watt
ElseIf Result = #PhasedPlasmaPulseGun200Watt
WPN_Selected = #PhasedPlasmaPulseGun200Watt
EndIf
ElseIf WPN_Selected = 0
PrintN(" OOPS! NO WEAPON WAS SELECTED!!!")
;WPN_Selected = 0 ; Is this really needed? Added this because enemies are recieving weapons they shouldnt still. < Cause was incorrect label in string.
;Delay(200)
PrintN(" Restarting...")
;Delay(200)
LoopCounter + 1 ; For the error checking routine at bottom.
If LoopCounter => 500 ; I put this error check in because sometimes the simulation seems to get stuck.
PrintN(" ERROR COUNTER HAS RAN: " +GotoLoopCounter+" TIMES FOR WEAPON SELECTION...")
Delay(500)
PrintN(" The enemy selected: "+EnemyTitle+"")
PrintN(" Current Weapon Catagory: "+WPN_Category+"")
PrintN(" Bite= "+Enemy_CanUse_bite+"")
PrintN(" Claws= "+Enemy_CanUse_claws+"")
PrintN(" Unarmed= "+Enemy_CanUse_unarmed+"")
PrintN(" Armed= "+Enemy_CanUse_armed+"")
PrintN(" Thrown= "+Enemy_CanUse_thrown+"")
PrintN(" Smallguns= "+Enemy_CanUse_smallguns+"")
PrintN(" Shotguns= "+Enemy_CanUse_shotguns+"")
PrintN(" Rifles= "+Enemy_CanUse_rifles+"")
PrintN(" AssaultRifles= "+Enemy_CanUse_assault_rifles+"")
PrintN(" Machineguns= "+Enemy_CanUse_machineguns+"")
PrintN(" Heavyweapons= "+Enemy_CanUse_heavyweapons+"")
PrintN(" Energyweapons= "+Enemy_CanUse_energyweapons+"")
PrintN(" Explosives= "+Enemy_CanUse_explosiveweapons+"")
PrintN(" Check this routine for logic errors, spelling errors, or missing data!!!")
Input()
End
EndIf
;PrintN(" made is here.")
Goto PickEMweapon:
EndIf
PrintN(" Made it too End of Randomize Weapon selection.")
PrintN(" Weapon Selected:"+WPN_Selected+"")
LoopCounter = 0 ; Reset the loop counter
;Weapon_Lookup()
;Display_Selected_Weapon()
PrintN(" Weapon name: "+WPN_name+"")
PrintN(" Description: "+WPN_desc+"")
PrintN(" Attack variety: "+Atk_Variety+"")
PrintN(" Damage type 1: "+Damage_type1+"")
If Damage_type2 <> #Empty$
PrintN(" Damage type 2: "+Damage_type2+"")
EndIf
PrintN(" Max damage: "+Damage_Mx+"")
PrintN(" Min damage: "+Damage_Mn+"")
PrintN(" AP cost:"+APcost+"")
PrintN(" Weapon Range: "+WPNRange+" ft")
If ThrwWPNRange <> 0
PrintN(" Thrown Range:"+ThrwWPNRange+"ft")
EndIf
PrintN(" Min STR needed: "+Min_ST+"")
If Ammunition <> ""
PrintN(" Ammunition: "+Ammunition+"")
EndIf
If Hands_req <> 0
PrintN(" Hands required: "+Hands_req+"")
EndIf
If Magazine_Size <> 0
PrintN(" Magazine size: "+Magazine_Size+"")
EndIf
If Value <> 0
PrintN(" Item value: "+Value+"")
EndIf
If Item_lb <> 0
PrintN(" Item weight: "+Item_lb+" lbs")
EndIf
EndProcedure
; Put the weapons into the enemies hands.
Procedure Enemy1_Hands()
PrintN(" ========================================================")
PrintN(" Enemy #1 Category: > "+WPN_Category+" < 1st Weapon: > "+WPN_name+" <")
PrintN(" ========================================================")
Display_Selected_Weapon() ;<--- Show 1st weapon in right hand.
Enemy1_Righthand = WPN_name ; Put a weapon in ENEMY1's right hand.
If Hands_req = 2
Enemy1_Lefthand = Enemy1_Righthand
Else
If Enemy1_Lefthand = #Empty$
Repeat
Randomize_Enemy_Weapon_WPN_Category()
Until Hands_req = 1 And WPN_name <> #Empty$
Weapon_Lookup() ;<-- Check the list of valid weapons.
Enemy1_Lefthand = WPN_name
PrintN(" ========================================================")
PrintN(" Enemy #1 Category: > "+WPN_Category+" < 2nd Weapon: > "+WPN_name+" <")
PrintN(" ========================================================")
Display_Selected_Weapon(); <--- Show 2nd weapon in left hand.
;PrintN(" HANDS VALUE IS:"+Hands_req+"")
EndIf
EndIf
EndProcedure
; Display the weapons in right and left hands.
Procedure DisplayEnemy_Weapons()
PrintN(" ========================================================")
PrintN(" [ ENEMY #1 ] R_Hand:"+Enemy1_Righthand+" L_Hand:"+Enemy1_Lefthand+"")
If TotalEnemyForce > 1
PrintN(" [ ENEMY #2 ] R_Hand:"+Enemy2_Righthand+" L_Hand:"+Enemy2_Lefthand+"")
EndIf
EndProcedure
Procedure BattleEngine()
Start:
ClearConsole()
EnemyTitle = #Empty$ ;Clear the enemy title.
Enem_desc_line1.s =#Empty$ ;Clear enemy description.
Enem_desc_line2.s =#Empty$
Enem_desc_line3.s =#Empty$
Eamt_max = 20 ;Defaults
Eamt_min = 1 ;Defaults
Max_init_dice = 100 ;Defaults
; WHAT TYPE OF COMBAT? -------------------------------------------------------------------------------------------
CombatType = Random(2, 1)
If CombatType = 1
PrintN(" «« GROUND COMBAT »»")
ElseIf CombatType = 2
PrintN(" «« VEHICLE COMBAT »»")
EndIf
; WHAT IS THE ENEMY FORCE ATTACKING? -----------------------------------------------------------------------------
EnemyForce_Dice:
EnemyForce = Random(MaxEnemies, 1) ; 21,1 Max number here determines how many enemies TYPES there are to pick from.
; If no enemy is found with defined attributes then everything SHOULD equal zero.
If EnemyForce = #Lone_Bandit And CombatType = 1
EnemyTitle ="A lone bandit."
Enem_desc_line1.s ="test1"
Enem_desc_line2.s ="test2"
Enem_desc_line3.s ="test3"
;---------------------------------------
Eamt_max = 1 ; Max amount that can be in this group.
Eamt_min = 1 ; Min amount that can be in this group.
;---------------------------------------
Max_init_dice = 70 ; Enemies Max Initative Roll.
Enemy_CanUse_unarmed = #True ; Can be assigned an attack from this catagory of weapons.
Enemy_CanUse_armed = #True
Enemy_CanUse_thrown = #True
Enemy_CanUse_smallguns = #True
Enemy_CanUse_rifles = #True
AttributeRange_Enemy_LoneBandit() ; Randomly roll the attributes for this enemy type. The variables are handled in the procedures above.
Else
PrintN(" No valid condition met...")
Delay(200)
PrintN(" Re-rolling...")
Delay(200)
Goto Start
EndIf
EndProcedure
Begin:
BattleEngine()
;-----------------------------------------------------------------------------------------
; Show the end result of what enemy type was picked!
;-----------------------------------------------------------------------------------------
PrintN(" Enemy type: "+EnemyTitle+"")
;-----------------------------------------------------------------------------------------
Randomize_Enemy_Weapon_WPN_Category()
Set_Randomized_Weapon()
Weapon_Lookup()
;Display_Selected_Weapon()
;DisplayEnemy_Weapons()
String$ = Input()
If String$ = "z"
PrintN(" Restarting!")
Delay(300)
Goto Begin
Else
End
EndIf
If you mess with the procedure order at the bottom its supposed to function like this:
Got it working inconsistently and displaying the wrong values by switching back on the "ELSE" and changing If WPN_Selected = #Fists;And WPN_Catagory = #unarmed And Enemy_CanUse_unarmed = #True
It should be displaying a weapon from the Rifle category and only picking between 1 of the 2 available. I suppose its picking the first "1" it see's in the list of weapons because I removed the check for the category (WPN_Catagory).
If I put back in the two "AND" statements it does find the weapon. In this case its SMALL GUNS and 3 meaning it should show a "RareRevolver" because #RareRevolver=3
If I call the WeaponLookUp() procedure after the Category and Weapon randomization completes it hangs. The only thing I see different from my earlier code base is #constants defining the weapons were numbered 1 to 60. But this made it a chore to add in new weapons if I wanted the list to stay incremented.
What I find most troubling is this area of my code I had no issues with until now so I feel like I'm going backwards redoing the same thing over and over.
Result = Random(12,1) ; change 12 to 13 later - have no explosive users yet!
Select Result
Case #creaturebite
If Enemy_CanUse_bite ; Assumed that this is a bool constant
WPN_Category = "Creature Bite"
Selected_Category = #creaturebite
EndIf
Case #creatureclaws
If Enemy_CanUse_claws
WPN_Category = "Creature Claws"
Selected_Category = #creatureclaws
EndIf
Case #unarmed
If Enemy_CanUse_unarmed
WPN_Category = "Unarmed"
Selected_Category = #unarmed
EndIf
Case #armed
If Enemy_CanUse_armed
WPN_Category = "Armed"
Selected_Category = #armed
EndIf
Case #thrown
If Enemy_CanUse_thrown
WPN_Category = "Thrown"
Selected_Category = #thrown
EndIf
Case #smallguns
If Enemy_CanUse_smallguns
WPN_Category = "Smallguns"
Selected_Category = #smallguns
EndIf
Case #shotguns
If Enemy_CanUse_shotguns
WPN_Category = "Shotguns"
Selected_Category = #shotguns
EndIf
Case #rifles
If Enemy_CanUse_rifles
WPN_Category = "Rifles"
Selected_Category = #rifles
EndIf
Case #assault_rifles
If Enemy_CanUse_assault_rifles ;<--- Watch for spelling errors! This is what was causing the error of it failing to reset and giving the wrong items out!!!! Did not match Global name.
WPN_Category = "Assault Rifles"
Selected_Category = #assault_rifles
EndIf
Case #assault_rifles
If Enemy_CanUse_machineguns
WPN_Category = "Machineguns"
Selected_Category = #machineguns
EndIf
Case #heavyweapons
If Enemy_CanUse_heavyweapons
WPN_Category = "Heavyweapons"
Selected_Category = #heavyweapons
EndIf
Case #energyweapons
If Enemy_CanUse_energyweapons
WPN_Category = "Energyweapons"
Selected_Category = #energyweapons
EndIf
Case #explosiveweapons
If Enemy_CanUse_explosiveweapons
WPN_Category = "Explosive weapons"
Selected_Category = #explosiveweapons
EndIf
EndSelect
Switched everything to case statements and its working great until it gets to my WeaponLook() procedure. It will run infinitely and never find an item.
Thanks once again everyone. My spelling error was a result of me going back to earlier version of my Procedure file before it was fixed. Soon as that was pointed out I also released I was calling the wrong variable. It should have been "Selected_Category" and not "WPN_Category" being compared.
To my dismay I did spend hours trying to figure this out but in the end I think it helped me learn a lot more. I see your point in using Protected instead of Globals.
Reached a new milestone!
I let my code run for awhile and it had no issues. Now I can move on to creating the next part of my game, the turn based combat!
I would like to increase the console window and buffer size. I found the API function but have no idea how to implement it, does anyone have a simple example?
The complexity of my program has exceeded the usefulness of what a 80x25 character display can offer.
Vernostonos wrote:I would like to increase the console window and buffer size. I found the API function but have no idea how to implement it, does anyone have a simple example?
The complexity of my program has exceeded the usefulness of what a 80x25 character display can offer.
From my observations it doesn't seem as if you are using any of the other functions of a console besides display and keyboard input. Perhaps it may be useful to create your own mock console. You would only have to implement functions that you specifically need and doing so would give you the added benefit of using a custom font easily. In addition I think it would allow porting of your game to Linux or MAC OS, if that is desired, a little easier.