Browse Source

Move all spell lists into the SpellBook function. Gives central location for formatting.

KeyMasterOfGozer 5 years ago
parent
commit
3c25dca874
3 changed files with 81 additions and 93 deletions
  1. 6 43
      locations/magik.qsrc
  2. 4 39
      locations/obj_din.qsrc
  3. 71 11
      locations/spellBook.qsrc

+ 6 - 43
locations/magik.qsrc

@@ -2,51 +2,14 @@
 
 act 'Physical attacks':gt'boxing'
 
-if spellMana['fog'] = 0:
-	gs 'spellList'
-end
-
-$SpellListStr = "
+$SpellListStr = '
 <center>
 	<h1>Choose a Spell to cast.</h1>
-	<br>
-	<table CELLPADDING = '5'>
-		<tr>
-			<th align='left'>Spell</th>
-			<th align='left'>Mana</th>
-			<th align='left'>Description</th>
-		</tr>"
-i = 0
-numSpellsKnown = 0
-:CombatSpellLoop
-$ThisSpellName = $combatSpells[i]
-if i < arrsize('$combatSpells'):
-	if spellKnown[$ThisSpellName] = 1:
-		$SpellListStr = $SpellListStr + " 
-		<tr>
-			<td align='left'><a href=""EXEC: cls & gs 'castSpell', '<<$ThisSpellName>>'& xgt 'fight','sta' & act 'Physical attacks':gt'boxing' & act 'Magic attacks':gt'magik'""><<$spellName[$ThisSpellName]>></a></td>
-			<td align='right'><<spellMana[$ThisSpellName]>></td>
-			<td align='left'><<$spellDesc[$ThisSpellName]>></td>
-		</tr>"
-		numSpellsKnown += 1
-	end
-	i += 1
-	jump 'CombatSpellLoop'
-end
-
-$SpellListStr = $SpellListStr + " 
-	</table>
-</center>"
-
-if numSpellsKnown = 0:
-	"No combat spells known."
-else
-	*pl func('cleanHTML',$SpellListStr)
-end
-
-killvar 'i'
-killvar 'numSpellsKnown'
-killvar '$ThisSpellName'
+	<br>' + func('spellBook','cast','$combatSpells') + '
+</center>'
+
+*pl func('cleanHTML',$SpellListStr)
+
 killvar '$SpellListStr'
 
 

+ 4 - 39
locations/obj_din.qsrc

@@ -1468,45 +1468,10 @@ if $ARGS[0] = 'magic':
 		*nl
 
 		$SpellListStr = "<center>
-			<table>
-				<tr>
-					<th>Spell</th>
-					<th>Mana</th>
-					<th>Description</th>
-				</tr>"
-		i = 0
-		:ObDinSpellLoop
-		$ThisSpellName = $combatSpells[i]
-		if i < arrsize('$combatSpells'):
-			if spellKnown[$ThisSpellName] = 1:
-				$SpellListStr = $SpellListStr + " 
-				<tr>
-					<td><<$spellName[$ThisSpellName]>></td>
-					<td><<spellMana[$ThisSpellName]>></td>
-					<td><<$spellDesc[$ThisSpellName]>></td>
-				</tr>"
-			end
-			i += 1
-			jump 'ObDinSpellLoop'
-		end
-		i = 0
-		:ObDinSpellLoop2
-		$ThisSpellName = $nonComSpells[i]
-		if i < arrsize('$nonComSpells'):
-			if spellKnown[$ThisSpellName] = 1:
-				$SpellListStr = $SpellListStr + " 
-				<tr>
-					<td><<$spellName[$ThisSpellName]>></td>
-					<td><<spellMana[$ThisSpellName]>></td>
-					<td><<$spellDesc[$ThisSpellName]>></td>
-				</tr>"
-			end
-			i += 1
-			jump 'ObDinSpellLoop2'
-		end
-
-		$SpellListStr = $SpellListStr + " 
-			</table>
+			<h1>Combat Spells</h1><br>
+			<<func('spellBook','list','$combatSpells')>><br>
+			<h1>Non-Combat Spells</h1><br>
+			<<func('spellBook','list','$nonComSpells')>><br>
 		</center>"
 
 		*pl func('cleanHTML',$SpellListStr)

+ 71 - 11
locations/spellBook.qsrc

@@ -1,7 +1,8 @@
 #spellBook
-! Make a table of Spells to Cast from a given list.  the list is in the form of the lists as done in thespellList file.
+! Make a table of Spells to Cast from a given list.  the list is in the form of the lists as done in the spellList file.
 !
-! 	$ARGS[0] = Type of List: cast, learn
+! 	$ARGS[0] = Type of List: cast, learn, list
+!				This determines the info to be displayed as wel las the HTML formatting
 ! 	$ARGS[1] = the name of the array to use for the spell list.
 !	$ARGS[2] = (optional) return Action Code - a dynamic piece of code to run instead of generic return.
 !	$ARGS[3] = (optional) Additional code to put in spell link (all spells)
@@ -14,21 +15,24 @@ $spellBookVar['CodeAfterSpell'] = $ARGS[3]
 
 ! Make sure opptional variables have defaults
 if $spellBookVar['ActionCode'] = '':
-	$spellBookVar['ActionCode'] = "gt '<<$loc>>', '<<$metka>>'"
+	$spellBookVar['ActionCode'] = 'gt $loc, $metka'
 end
 if $spellBookVar['CodeAfterSpell'] = '':
-	$spellBookVar['CodeAfterSpell'] = "gt '<<$loc>>', '<<$metka>>'"
+	$spellBookVar['CodeAfterSpell'] = 'gt $loc, $metka'
 end
 
 ! lets the user back out if they don''t want ot cast.
 act 'Never mind':dynamic spellBookVar['ActionCode']
 
 ! This just makes sure the current spellLists are loaded
-if spellMana['fog'] = 0:
-	gs 'spellList'
-end
+gs 'spellList'
+
+!-----------------------------------------------------------------------------------------------
+! Choose the type of spell list to determine what info will be displayed and the HTML formatting
+!	1) 'TableText' = The header for the table.  The header row
+!	2) 'RowCode' = The code used inside the loop to build the HTML text for that Row.
 
-! Build the table - Choose Header for Type
+!! 'learn' type is for displaying which seplls the user is currently learning.
 if $spellBookVar['Type'] = 'learn':
 	$spellBookVar['TableText'] = "
 	<center>
@@ -49,8 +53,8 @@ if $spellBookVar['Type'] = 'learn':
 			$result = ''
 		end
 	}
-else
-	! Default is list of castable spells.
+!! 'list' type is list of castable spells.  This makes a table of spells for the user to cast.
+elseif $spellBookVar['Type'] = 'cast':
 	$spellBookVar['TableText'] = "
 	<center>
 		<table CELLPADDING = '5'>
@@ -62,6 +66,7 @@ else
 	$spellBookVar['RowCode'] = {
 		if spellKnown[$ThisSpellName] = 1:
 			if $spellOptDesc[$ThisSpellName] = '':
+			! If the spell has no Options, we jsut list it out for casting
 				$tmpHTMLCode = " 
 				<tr>
 					<td align='left'><a href=""EXEC: gs 'castSpell', '<<$ThisSpellName>>'& <<$spellBookVar['CodeAfterSpell']>>""><<$spellName[$ThisSpellName]>></a></td>
@@ -69,6 +74,8 @@ else
 					<td align='left'><<$spellDesc[$ThisSpellName]>></td>
 				</tr>"
 			else
+			! If the spell does have options, we make a row for spell info, and loop through additional rows
+			!	with options for the user to pick
 				$tmpHTMLCode = " 
 				<tr>
 					<td align='left'><<$spellName[$ThisSpellName]>></td>
@@ -76,7 +83,7 @@ else
 					<td align='left'><<$spellDesc[$ThisSpellName]>></td>
 				</tr>"
 				n=0
-				:RowCodeLoop99
+				:RowCodeLoop98
 				if n < arrsize('<<$spellOptDesc[$ThisSpellName]>>'):
 					$spellBookVar['tmpVal'] = dyneval('$result = <<$spellOptVal[$ThisSpellName]>>[<<n>>]')
 					$spellBookVar['tmpName']= dyneval('$result = <<$spellOptDesc[$ThisSpellName]>>[<<n>>]')
@@ -87,6 +94,59 @@ else
 						<td align='left'></td>
 					</tr>"
 					n += 1
+					jump 'RowCodeLoop98'
+				end
+
+			end
+			$result = $tmpHTMLCode
+			spellBookVar['Counter'] += 1
+			killvar '$tmpHTMLCode'
+			killvar 'n'
+		else
+			$result = ''
+		end
+	}
+!! Default is a list of spells with descriptio nand mana cost listed.
+else
+	$spellBookVar['TableText'] = "
+	<center>
+		<table CELLPADDING = '5'>
+			<tr>
+				<th align='left'>Spell</th>
+				<th align='left'>Mana</th>
+				<th align='left'>Description</th>
+			</tr>"
+	$spellBookVar['RowCode'] = {
+		if spellKnown[$ThisSpellName] = 1:
+			if $spellOptDesc[$ThisSpellName] = '':
+			! If the spell has no Options, we jsut list it out for casting
+				$tmpHTMLCode = " 
+				<tr>
+					<td align='left'><<$spellName[$ThisSpellName]>></td>
+					<td align='right'><<spellMana[$ThisSpellName]>></td>
+					<td align='left'><<$spellDesc[$ThisSpellName]>></td>
+				</tr>"
+			else
+			! If the spell does have options, we make a row for spell info, and loop through additional rows
+			!	with options for the user to pick
+				$tmpHTMLCode = " 
+				<tr>
+					<td align='left'><<$spellName[$ThisSpellName]>></td>
+					<td align='right'><<spellMana[$ThisSpellName]>></td>
+					<td align='left'><<$spellDesc[$ThisSpellName]>></td>
+				</tr>"
+				n=0
+				:RowCodeLoop99
+				if n < arrsize('<<$spellOptDesc[$ThisSpellName]>>'):
+					$spellBookVar['tmpVal'] = dyneval('$result = <<$spellOptVal[$ThisSpellName]>>[<<n>>]')
+					$spellBookVar['tmpName']= dyneval('$result = <<$spellOptDesc[$ThisSpellName]>>[<<n>>]')
+					$tmpHTMLCode += " 
+					<tr>
+						<td align='left'></td>
+						<td align='left'><<$spellBookVar['tmpName']>></td>
+						<td align='left'></td>
+					</tr>"
+					n += 1
 					jump 'RowCodeLoop99'
 				end