Help Me Improve?

Started by DrakoShade, January 16, 2010, 05:20:11 pm

Previous topic - Next topic

DrakoShade

I've been working on a way to expand the static data loaded as a game starts, effectively adding fields to the Database.  Thus far, I have the following script:

Spoiler: ShowHide
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# Here, it is necessary for me to split the main process to allow aliasing
# of new lines in between the loading of the database and anything else
# important.  This far, only splitting occurs, no additions of new functions.
#==============================================================================
class Scene_Title
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # If battle test
    if $BTEST
      battle_test
      return
    end
    # Load database
    load_database
    # Make system object
    $game_system = Game_System.new
    # Make title graphic
    @sprite = Sprite.new
    @sprite.bitmap = RPG::Cache.title($data_system.title_name)
    # Make command window
    make_command_window
    # Play title BGM
    $game_system.bgm_play($data_system.title_bgm)
    # Stop playing ME and BGS
    Audio.me_stop
    Audio.bgs_stop
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of command window
    @command_window.dispose
    # Dispose of title graphic
    @sprite.bitmap.dispose
    @sprite.dispose
  end
 
  #---------------------------------------------------------------------------
  # * Load Database
  #---------------------------------------------------------------------------
  def load_database
    $data_actors        = load_data("Data/Actors.rxdata")
    $data_classes       = load_data("Data/Classes.rxdata")
    $data_skills        = load_data("Data/Skills.rxdata")
    $data_items         = load_data("Data/Items.rxdata")
    $data_weapons       = load_data("Data/Weapons.rxdata")
    $data_armors        = load_data("Data/Armors.rxdata")
    $data_enemies       = load_data("Data/Enemies.rxdata")
    $data_troops        = load_data("Data/Troops.rxdata")
    $data_states        = load_data("Data/States.rxdata")
    $data_animations    = load_data("Data/Animations.rxdata")
    $data_tilesets      = load_data("Data/Tilesets.rxdata")
    $data_common_events = load_data("Data/CommonEvents.rxdata")
    $data_system        = load_data("Data/System.rxdata")
  end
 
  #----------------------------------------------------------------------------
  # * Make Command Window
  #----------------------------------------------------------------------------
  def make_command_window
    s1 = "New Game"
    s2 = "Continue"
    s3 = "Shutdown"
    @command_window = Window_Command.new(192, [s1, s2, s3])
    @command_window.back_opacity = 160
    @command_window.x = 320 - @command_window.width / 2
    @command_window.y = 288
    # Continue enabled determinant
    # Check if at least one save file exists
    # If enabled, make @continue_enabled true; if disabled, make it false
    @continue_enabled = false
    for i in 0..3
      if FileTest.exist?("Save#{i+1}.rxdata")
        @continue_enabled = true
      end
    end
    # If continue is enabled, move cursor to "Continue"
    # If disabled, display "Continue" text in gray
    if @continue_enabled
      @command_window.index = 1
    else
      @command_window.disable_item(1)
    end
  end
 
  #--------------------------------------------------------------------------
  # * Battle Test
  #--------------------------------------------------------------------------
  def battle_test
    # Load database (for battle test)
    load_database
    # Reset frame count for measuring play time
    Graphics.frame_count = 0
    # Make each game object
    $game_temp          = Game_Temp.new
    $game_system        = Game_System.new
    $game_switches      = Game_Switches.new
    $game_variables     = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_screen        = Game_Screen.new
    $game_actors        = Game_Actors.new
    $game_party         = Game_Party.new
    $game_troop         = Game_Troop.new
    $game_map           = Game_Map.new
    $game_player        = Game_Player.new
    # Set up party for battle test
    $game_party.setup_battle_test_members
    # Set troop ID, can escape flag, and battleback
    $game_temp.battle_troop_id = $data_system.test_troop_id
    $game_temp.battle_can_escape = true
    $game_map.battleback_name = $data_system.battleback_name
    # Play battle start SE
    $game_system.se_play($data_system.battle_start_se)
    # Play battle BGM
    $game_system.bgm_play($game_system.battle_bgm)
    # Switch to battle screen
    $scene = Scene_Battle.new
  end
end

#==============================================================================
# ** Database Expansion Methods
#------------------------------------------------------------------------------
# Here is where the database actually gets its expansions.
#==============================================================================
class Scene_Title
  alias expanded_load_database load_database
  def load_database
    expanded_load_database
    expand_actors
    expand_classes
    expand_skills
    expand_items
    expand_weapons
    expand_armors
    expand_enemies
    expand_troops
    expand_states
    expand_animations
    expand_tilesets
    expand_common_events
    expand_system
  end
 
  def expand_actors
  end
 
  def expand_classes
  end
 
  def expand_skills
  end
 
  def expand_items
  end
 
  def expand_weapons
  end
 
  def expand_armors
  end
 
  def expand_enemies
  end
 
  def expand_troops
  end
 
  def expand_states
  end
 
  def expand_animations
  end
 
  def expand_tilesets
  end
 
  def expand_common_events
  end
 
  def expand_system
  end
end

#==============================================================================
# ** Explainations!
#------------------------------------------------------------------------------
# Following, I will show what can be done at its most basic levels.
#==============================================================================
=begin

  Say we're adding two new stats to actors as a whole.  The basic process would
be as follows:
-------------------------------------------------------------------------------
module RPG
  class Actor   
    def add_stats
      @parameters.resize(8, 100)
      for i in 1..99
        @parameters[6, i] = 50+i*5
        @parameters[7, i] = 50+i*5
      end
    end
  end
end

class Scene_Title
  alias newstats_expand_actors expand_actors
  def expand_actors
    newstats_expand_actors
    for i in 1..$data_actors.size
      $data_actors[i].add_stats
    end
   
    #-------------------------------------------
    # * Actor 1 gets unique stats!
    #-------------------------------------------
    for i in 1..99
      $data_actors[1].parameters[6, i] = floor(50+i*5.5)
      $data_actors[1].parameters[7, i] = 60+i*6
    end
  end
end
-------------------------------------------------------------------------------
  Of course, in order for this added pair of stats to have any effect at all,
Game_Player, Game_Battler, various windows, etc. would have to be altered as
well, but that's for another script.  You have now added to $data_actors.

=end


Thus far, it should be effective.  The question comes in how I can do this better, if anybody has any suggestions.