Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Mission Manager Development Thread [Updated 6/14/08 @ 5:30 pm]

I suppose, since I might be asking more questions in the development of this script, I'm going to reserve this thread incase I have further questions.

Once again, I have figured out my own problem... here was my solution, it was simple.

My origional method was...


Code:
  #-----------------------------------------------------------------------------
  #  * Draw_Item
  #-----------------------------------------------------------------------------
  def draw_item(index)
    # Mission name is determined by data array index
    mission = @data[index]
    unless mission == nil
      # Draw stuff
    end
  end

I simply changed it by doing this, and all 20+ commands displayed!

Code:
  def draw_item(index)
    # Mission name is determined by data array index
    mission = @data[index]
    for i in 0...mission.size + 1
      unless i == nil
        # Set Y coordinate of Mission Category command
        y = index * 32
        # Create new Rect
        rect = Rect.new(0, y, self.width - 32, 32)
        self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
        self.contents.font.color = normal_color
        self.contents.draw_text(0, y, 192, 32, mission)
      end
    end
  end


The Origional Issue

I just barely started this script the other day, and haven't really had time to finish it. When I went to work, it showed all 20+ Mission Categories, but now it only shows 9... anybody know where I went wrong in my last update? Everything looks like it was defined correctly, but its got me stumped.

To test this script, do the standard "install above main" and call it with "$scene = Scene_Mission.new"

Code:
#===============================================================================
# ~** Mission Manager V 0.1 **~
#-------------------------------------------------------------------------------
# Written by  : Kain Nobel
# Version     : 0.1
# Last Update : 06/14/2008
# Created     : 06/11/2008
################################################################################
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
# ~**                 Mission Setup Constants - BEGIN                      **~ #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
################################################################################
Mission_Title     = "~* [ M I S S I O N   M A N A G E R   V  0 . 1 ] *~"
CMS_ShowMap       = true
CMS_Opacity       = 160
CMS_Index_Mission = 0
#-------------------------------------------------------------------------------
# ** Main Mission Categories
#-------------------------------------------------------------------------------
Mission_Categories = {
  1   => "Mission I",
  2   => "Mission II",
  3   => "Mission III",
  4   => "Mission IV",
  5   => "Mission V",
  6   => "Mission VI",
  7   => "Mission VII",
  8   => "Mission VIII",
  9   => "Mission IX",
  10  => "Mission X",
  11  => "Mission XI",
  12  => "Mission XII",
  13  => "Mission XIII",
  14  => "Mission XIV",
  15  => "Mission XV",
  16  => "Mission XVI",
  17  => "Mission XVII",
  18  => "Mission XVIII",
  19  => "Mission XIX",
  20  => "Mission XX"
}
#-------------------------------------------------------------------------------
# ** Mission Selectables    
#-------------------------------------------------------------------------------
Mission_Selectables = {
  # Category 1
  1   => [1, 1, "Spelunking in the Tunnels of Midgar"],
  2   => [1, 2, "Pick up the Colonel's Dry Cleaning"],
  # Category 2
  1   => [2, 1, "Test Tube Terror"]
  # Etc, etc, etc...
}
#-------------------------------------------------------------------------------
# ** Mission Briefing
#-------------------------------------------------------------------------------
Mission_Breifing = {
  # Category 1, Mission 1
  1   => [1, 1, "This is the first mission for Shinra Electric Power Company,"],
  2   => [1, 1, "please use caution entering the premisis, for not only do"],
  3   => [1, 1, "creepoids dwell down here, but also families of live mines"],
  4   => [1, 1, "are present in the tunnel grounds."],
  # Category 1, Mission 2
  1   => [1, 2, "Ah, you've made it to your second mission, now you must pick"],
  2   => [1, 2, "up the colonels laundry from the dry cleaners! Please use"],
  3   => [1, 2, "caution because his clothes are hot off the press! We"],
  4   => [1, 2, "wouldn't want you to burn yourself again, now would we?"],
  # Category 2, Mission 1
  1   => [2, 1, "You've made it to the Monster Research project, please"],
  2   => [2, 1, "use caution when entering the test tube, or you might"],
  3   => [2, 1, "wind up becoming a test tube baby!"]
  # Etc, etc, etc...
}
#-------------------------------------------------------------------------------
# ** Mission Objectives
#-------------------------------------------------------------------------------
Mission_Objectives = {
  # Category 1, Mission 1
  1   => [1, 1, "Obtain 3 orbs of power"],
  2   => [1, 1, "Talk to crackhead in tunnels"],
  3   => [1, 1, "Obtain 3 orbs of speed"],
  4   => [1, 1, "Get back to HQ imediately!"],
  # Category 1, Mission 2
  1   => [1, 2, "Take the train to Sector 6"],
  2   => [1, 2, "Go through the park, to Wall Market"],
  3   => [1, 2, "Enter the Hot Press!"]
}
#-------------------------------------------------------------------------------
# ** Mission Rewards
#-------------------------------------------------------------------------------
Mission_Rewards = {
  1   => "Reward I",
  2   => "Reward II",
  3   => "Reward III",
  4   => "Reward IV"
}
#===============================================================================
################################################################################
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
# ~**                   Mission Setup Constants - END                      **~ #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
################################################################################
#===============================================================================
# ** Game_Mission
#-------------------------------------------------------------------------------
#   This class performs generic commands used for the Mission system.
#===============================================================================
class Game_Mission
  # [Attributes]----------------------------------------------------------------
  attr_accessor   :categories
  attr_accessor   :missions
  attr_accessor   :objectives
  #-----------------------------------------------------------------------------
  # * Initialize Method
  #-----------------------------------------------------------------------------
  def initialize
    @current_mission  = nil
    @categories       = []
    @missions         = []
    @brefing          = []
    @objectives       = []
    @rewards          = []
  end
  #-----------------------------------------------------------------------------
  # * Define Categories
  #-----------------------------------------------------------------------------
  def categories
    return Mission_Categories
  end
  #-----------------------------------------------------------------------------
  # * Define Missions
  #-----------------------------------------------------------------------------
  def missions
    return Mission_Selectables
  end
  #-----------------------------------------------------------------------------
  # * Define Description
  #-----------------------------------------------------------------------------
  def breifing
    return Mission_Breifing
  end
  #-----------------------------------------------------------------------------
  # * Define Objectives
  #-----------------------------------------------------------------------------
  def objectives
    return Mission_Objectives
  end
  #-----------------------------------------------------------------------------
  # * Define Rewards
  #-----------------------------------------------------------------------------
  def rewards
    return Mission_Rewards
  end
  #-----------------------------------------------------------------------------
  # * Add Category
  #-----------------------------------------------------------------------------
  def category_add(n, boolean = true)
    unless n == nil
      @categories.push(n, boolean)
    end
  end
  #-----------------------------------------------------------------------------
  # * Delete Category
  #-----------------------------------------------------------------------------
  def category_delete(n)
    unless n == nil
      @categories.delete(n)
    end
  end
  #-----------------------------------------------------------------------------
  # * Lock Category
  #-----------------------------------------------------------------------------
  def category_lock(n)
    unless n == nil
      # Simply reuses category_add and sets boolean to false
      category_add(n, false)
    end
  end
  #-----------------------------------------------------------------------------
  # * Add Mission
  #-----------------------------------------------------------------------------
  def mission_add(n, boolean = true)
    unless n == nil
      @missions.push(n, boolean)
    end
  end
  #-----------------------------------------------------------------------------
  # * Delete Mission
  #-----------------------------------------------------------------------------
  def mission_delete(n)
    unless n == nil
      @missions.delete(n)
    end
  end
  #-----------------------------------------------------------------------------
  # * Lock Mission
  #-----------------------------------------------------------------------------
  def mission_lock(n)
    unless n == nil
      # Simply reuses mission_add and sets boolean to false
      mission_add(n, false)
    end
  end
  #-----------------------------------------------------------------------------
  # * Add Objective
  #-----------------------------------------------------------------------------
  def objective_add(n, boolean = true)
    unless n == nil
      @objectives.push(n, boolean)
    end
  end
  #-----------------------------------------------------------------------------
  # * Delete Objective
  #-----------------------------------------------------------------------------
  def objective_delete(n)
    unless n == nil
      @objectives.delete(n)
    end
  end
  #-----------------------------------------------------------------------------
  # * Lock Objective
  #-----------------------------------------------------------------------------
  def objective_lock(n)
    unless n == nil
      # Simply reuses objective_add and sets boolean to false
      objective_add(n, false)
    end
  end
  #-----------------------------------------------------------------------------
  # * Start Mission
  #-----------------------------------------------------------------------------
  def start_mission(category = 1, mission = 1)
    @current_mission.push(category, mission)
  end
  #-----------------------------------------------------------------------------
  # * Complete Mission
  #-----------------------------------------------------------------------------
  def complete_mission(category = 1, mission = 1, fail = false)
    @current_mission.push(category, mission, fail)
  end
  #-----------------------------------------------------------------------------
  # * Fail Mission
  #-----------------------------------------------------------------------------
  def mission_failed(category = 1, mission = 1)
    # Simply reuses Complete Mission and sets fail to true
    complete_mission(category, mission, true)
  end
  #-----------------------------------------------------------------------------
  # * Objective Complete
  #-----------------------------------------------------------------------------
  def complete_objective(mission = 1, category = 1, objective = 1)
    # Complete Objective
  end
  #-----------------------------------------------------------------------------
  # * Fail Objective
  #-----------------------------------------------------------------------------
  def fail_objective(mission = 1, category = 1, objective = 1)
    # Fail Objective
  end
end
################################################################################
#===============================================================================
# ** Window_MissionHeader
#===============================================================================
class Window_MissionHeader < Window_Base
  #-----------------------------------------------------------------------------
  # * Initialize Method
  #-----------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.visible = true
    self.opacity = CMS_Opacity
    refresh
  end
  #-----------------------------------------------------------------------------
  # * Refresh Method
  #-----------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.draw_text(-16, -10, 640, 48, Mission_Title, 1)
  end
end
################################################################################
#===============================================================================
# ** Window_MissionCategory
#-------------------------------------------------------------------------------
#   This is the list of main mission categories, which will take you to the list
# of sub missions that fall into the respective category.
#===============================================================================
class Window_MissionCategory < Window_Selectable
  #-----------------------------------------------------------------------------
  # * Initialize Method
  #-----------------------------------------------------------------------------
  def initialize
    super(0, 64, 192, 416)
    self.contents = Bitmap.new(width - 32, height - 32)
    @missions = Game_Mission.new
    @item_max = Mission_Categories.size
    @commands = []
    refresh
    self.opacity = CMS_Opacity
    self.visible = true
    self.active = true
    self.index = 0
  end
  #-----------------------------------------------------------------------------
  #  * Define Category
  #-----------------------------------------------------------------------------
  def category
    return @data[self.index]
  end
  #-----------------------------------------------------------------------------
  #  * Refresh
  #-----------------------------------------------------------------------------
  def refresh
    # If contents doesn't equal nil
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    # Create Data array
    @data = []
    # For information within the Mission Categories
    for i in 0...Mission_Categories.size
      # If Category ID is more than 1
      if @missions.categories[i] != nil
        # Push category into data array
        @data.push(@missions.categories[i])
      end
    end
    # Item max is reset to size of data array
    @item_max = @data.size
    # If Item Max is more than 0
    if @item_max > 0
      #self.contents = Bitmap.new(width - 32, @item_max * 64)
      self.contents = Bitmap.new(width - 32, row_max * 32)
      # For information in Item Max
      for i in 0...@item_max
        # Draw Mission Category
        draw_item(i)
      end
    end
  end
  #-----------------------------------------------------------------------------
  #  * Draw_Item
  #-----------------------------------------------------------------------------
  def draw_item(index)
    # Mission name is determined by data array index
    mission = @data[index]
    unless mission[index] == nil
      # Set Y coordinate of Mission Category command
      y = index * 32
      # Create new Rect
      rect = Rect.new(0, y, self.width - 32, 32)
      self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
      self.contents.font.color = normal_color
      self.contents.draw_text(0, y, 192, 32, mission)
    end
  end
end
################################################################################
#===============================================================================
# ** Window_MissionSelect
#-------------------------------------------------------------------------------
#   This is the list of main mission categories, which will take you to the list
# of sub missions that fall into the respective category.
#===============================================================================
class Window_MissionSelect < Window_Selectable
  #-----------------------------------------------------------------------------
  # * Initialize Method
  #-----------------------------------------------------------------------------
  def initialize(mission_list = 0)
    super(192, 64, 448, 416)
    self.contents = Bitmap.new(width - 32, height - 32)
    @missions = Game_Mission.new
    @item_max = Mission_Selectables.size + 1
    @commands = []
    refresh
    self.opacity = CMS_Opacity
    self.visible = true
    self.active = true
    self.index = -1
  end
  #-----------------------------------------------------------------------------
  #  * Define Category
  #-----------------------------------------------------------------------------
  def mission
    return @data[self.index]
  end
  #-----------------------------------------------------------------------------
  # * Update Mission List
  #-----------------------------------------------------------------------------
  def update_list(category)
    @category = category
    refresh
  end
  #-----------------------------------------------------------------------------
  #  * Refresh
  #-----------------------------------------------------------------------------
  def refresh
    # If contents doesn't equal nil
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    # Create Data array
    @data = []
    # For information within the Mission Categories
    for i in 0...Mission_Selectables.size
      # If Category ID is more than 1
      if @missions.missions[i] != nil and
        @missions.missions[0] == @category
        # Push category into data array
        @data.push(@missions.missions[i])
      end
    end
    # Item max is reset to size of data array
    @item_max = @data.size
    # If Item Max is more than 0
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      # For information in Item Max
      for i in 0...@item_max
        # Draw Mission Category
        draw_item(i)
      end
    end
  end
  #-----------------------------------------------------------------------------
  #  * Draw_Item
  #-----------------------------------------------------------------------------
  def draw_item(index)
    # Mission name is determined by data array index
    selectable = @data[index]
    # Set Y coordinate of Mission Category command
    y = index * 32
    # Create new Rect
    rect = Rect.new(0, y, self.width - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.font.color = normal_color
    self.contents.draw_text(0, y, 448, 32, selectable.to_s)
  end
end
################################################################################
#===============================================================================
# ** Scene_Mission
#-------------------------------------------------------------------------------
#   This plays out the mission select scene, and allows you to pick which
# mission you need to complete.
#===============================================================================
class Scene_Mission
  #-----------------------------------------------------------------------------
  # * Main Method
  #-----------------------------------------------------------------------------
  def main
    # View Map behind windows.
    if CMS_ShowMap == true
      @spriteset = Spriteset_Map.new
    end
    # Execute Mission Setup
    @window_header = Window_MissionHeader.new
    @window_header.visible = true
    # Create Window_Mission
    @window_category = Window_MissionCategory.new
    @window_category.visible = true
    # Create Window_MissionList
    @window_mission = Window_MissionSelect.new(0)
    @window_mission.visible = true
    # Create Window_MissionStatus
    # 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 Windows
    @window_header.dispose
    @window_category.dispose
    @window_mission.dispose
    # Dispose of Map Background
    @spriteset.dispose if CMS_ShowMap
  end
  #-----------------------------------------------------------------------------
  # * Update Method
  #-----------------------------------------------------------------------------
  def update
    #@window_header.update
    @window_category.update
    @window_mission.update
    if @window_category.active == true
      update_category
      return
    end
    if @window_mission.active = true
      update_mission
      return
    end
  end
  #-----------------------------------------------------------------------------
  # * Update Main Mission Window
  #-----------------------------------------------------------------------------
  def update_category
    # Update based on index
    # If B Button Pressed
    if Input.trigger?(Input::B)
      # Play Cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Go back to Menu
      $scene = Scene_Menu.new(CMS_Index_Mission)
    end
    # If C Button Pressed
    if Input.trigger?(Input::C)
      # Play Decision SE
      $game_system.se_play($data_system.decision_se)
      # Switch to Mission Selection
      @window_category.active = false
      @window_mission.active = true
      @window_mission.index = 0
      @window_mission.update_list(@window_category.index)
    end
  end
  #-----------------------------------------------------------------------------
  # * Update Sub Mission Window
  #-----------------------------------------------------------------------------
  def update_mission
    # If B Button Pressed
    if Input.trigger?(Input::B)
      # Play Cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Update Windows
      @window_category.active = true
      @window_mission.active = false
      @window_mission.index = -1
    end
    # If C Button Pressed
    if Input.trigger?(Input::C)
      # Play Decision SE
      $game_system.se_play($data_system.decision_se)
      # Switch to Category Selection
      @window_category.active = false
      @window_mission.active = false
    end
  end
end

While we're on the subject of showing hash data, how would I get the missions show depending on which category is highlighted? I wanted to categorize the mission data like so...

Code:
#-------------------------------------------------------------------------------
# ** Mission Selectables    
#-------------------------------------------------------------------------------
Mission_Selectables = {
  # Category 1, Missions 1..2
  1   => [1, 1, "Spelunking in the Tunnels of Midgar"],
  2   => [1, 2, "Pick up the Colonel's Dry Cleaning"],
  # Category 2, Missions 1..1
  1   => [2, 1, "Test Tube Terror"]
  # Etc, etc, etc...
}

...Something like that anyways. What would be the best way to organize missions depending on category, and get it to show in the right window depending on this data? I've got it organized as an array within a hash... Category ID, Mission ID, Mission Title
 

OS

Sponsor

I can't see what the problem is, but I do have an idea.

Why not make those Hashes/Arrays into Classes? I mean something like Game_MissionCategory and Game_Mission. This way you could operate on each level of your hash without dealing with one. You'd just use an Array to hold the categories, which each have an array of missions, which each have an array of Objectives and Description Lines, etc.

It's just a thought. It really helps when writing really big codes, and the setup (i.e, when the User sets up the missions and such) is usually pretty similar, though easier to read;

LandOfPatties = Game_MissionCategory.new("Land of Patties Missions")
LandOfPatties.Missions.Add("Find the Patty")
LandOfPatties["Find the Patty"].Objective = ...

See what I mean. Everything looks cleaner and easier to understand.

I hope this helps you in some way.

~Owesome Scriptor
 
I'm going to take all of that into account, its still a pretty simple setup as it stands. BTW I just resolved the simple issue I was having, everything is working great!

Okay, I've got the last couple loose ends to tie up...

I need all the information to update...

Update Mission information depending on Category
Update Breifing information depending on Mission Picked

Also, if anybody knows why, in my scene, I'm having problems switching between Window_MissionSelect and Window_MissionConfirm... they both become active simultaneously, even though I put .active as false and all that. Here's the latest update

Again, call it with $scene = Scene_Mission.new

Code:
#===============================================================================
# ~** Mission Manager V 0.1 **~
#-------------------------------------------------------------------------------
# Written by  : Kain Nobel
# Version     : 0.1
# Last Update : 06/14/2008
# Created     : 06/11/2008
################################################################################
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
# ~**                 Mission Setup Constants - BEGIN                      **~ #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
################################################################################
Mission_Title     = "~* [ M I S S I O N   M A N A G E R   V  0 . 1 ] *~"
Mission_FontName  = "Georgia"
Mission_FontSize  = 22
Mission_Italics   = false
CMS_Index_Mission = 0
CMS_ShowMap       = true
CMS_Opacity       = 160
#-------------------------------------------------------------------------------
# ** Main Mission Categories
#-------------------------------------------------------------------------------
Mission_Categories = {
  1   => "Mission I",
  2   => "Mission II",
  3   => "Mission III",
  4   => "Mission IV",
  5   => "Mission V",
  6   => "Mission VI",
  7   => "Mission VII",
  8   => "Mission VIII",
  9   => "Mission IX",
  10  => "Mission X",
  11  => "Mission XI",
  12  => "Mission XII",
  13  => "Mission XIII",
  14  => "Mission XIV",
  15  => "Mission XV",
  16  => "Mission XVI",
  17  => "Mission XVII",
  18  => "Mission XVIII",
  19  => "Mission XIX",
  20  => "Mission XX",
  21  => "Mission XXI",
  22  => "Mission XXII",
  23  => "Mission XXIII",
  24  => "Mission XXIV",
  25  => "Mission XXV",
  26  => "Mission XXVI",
  27  => "Mission XXVII",
  28  => "Mission XXVIII",
  29  => "Mission XXIX",
  30  => "Mission XXX",
  31  => "Mission XXXI",
  32  => "Mission XXXII",
  33  => "Mission XXXIII",
  34  => "Mission XXXIV",
  35  => "Mission XXXV",
  36  => "Mission XXXVI",
  37  => "Mission XXXVII",
  38  => "Mission XXXVIII",
  39  => "Mission XXXIX",
  40  => "Mission XXXX",
}
#-------------------------------------------------------------------------------
# ** Mission Selectables    
#-------------------------------------------------------------------------------
Mission_Selectables = {
  # Category 1
  1   => "Spelunking in the Tunnels of Midgar",
  2   => "Pick up the Colonel's Dry Cleaning",
  3   => "Secret Meeting in the Alley",
  4   => "Pardon Me, but do you have any Grey Pupon?",
  5   => "The Rise of a New Breed of Chaos!"
  # Etc, etc, etc...
}
#-------------------------------------------------------------------------------
# ** Mission Briefing
#-------------------------------------------------------------------------------
Mission_Breifing = {
  1   => "        When venturing into the tunnels of Midgar, please use",
  2   => "EXTREME caution when approaching the designated drop point,",
  3   => "for there are many traps and mine fields along the way.",
  4   => "        We wouldn't want to lose another agent due to neglect",
  5   => "of your own well being, now would we? Please, come back to us",
  6   => "alive, the casualties in Midgar have been too many lately.",
  7   => "        Also, if you happen to run into a chap named Reno,",
  8   => "please give him my reguards, for I will be leaving the company",
  9   => "shortly... I've worked a long time, I'm ready for my",
  10  => "long awaited retirement.....",
  11  => "",
  12  => "Sincerely,",
  13  => "~Rude"
  # Etc, etc, etc...
}
#-------------------------------------------------------------------------------
# ** Mission Objectives
#-------------------------------------------------------------------------------
Mission_Objectives = {
  # Category 1, Mission 1
  1   => [1, 1, "Obtain 3 orbs of power"],
  2   => [1, 1, "Talk to crackhead in tunnels"],
  3   => [1, 1, "Obtain 3 orbs of speed"],
  4   => [1, 1, "Get back to HQ imediately!"],
  # Category 1, Mission 2
  1   => [1, 2, "Take the train to Sector 6"],
  2   => [1, 2, "Go through the park, to Wall Market"],
  3   => [1, 2, "Enter the Hot Press!"]
}
#-------------------------------------------------------------------------------
# ** Mission Rewards
#-------------------------------------------------------------------------------
Mission_Rewards = {
  1   => "Reward I",
  2   => "Reward II",
  3   => "Reward III",
  4   => "Reward IV"
}
#===============================================================================
################################################################################
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
# ~**                   Mission Setup Constants - END                      **~ #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
################################################################################
#===============================================================================
# ** Game_Mission
#-------------------------------------------------------------------------------
#   This class performs generic commands used for the Mission system.
#===============================================================================
class Game_Mission
  # [Attributes]----------------------------------------------------------------
  attr_accessor   :categories
  attr_accessor   :missions
  attr_accessor   :objectives
  #-----------------------------------------------------------------------------
  # * Initialize Method
  #-----------------------------------------------------------------------------
  def initialize#(c = 1, m = 1, o = 1)
    @current_mission  = nil
    @categories       = []
    @missions         = []
    @brefing          = []
    @objectives       = []
    @rewards          = []
  end
  #-----------------------------------------------------------------------------
  # * Define Categories
  #-----------------------------------------------------------------------------
  def categories
    return Mission_Categories
  end
  #-----------------------------------------------------------------------------
  # * Define Missions
  #-----------------------------------------------------------------------------
  def missions
    return Mission_Selectables
  end
  #-----------------------------------------------------------------------------
  # * Define Description
  #-----------------------------------------------------------------------------
  def breifing
    return Mission_Breifing
  end
  #-----------------------------------------------------------------------------
  # * Define Objectives
  #-----------------------------------------------------------------------------
  def objectives
    return Mission_Objectives
  end
  #-----------------------------------------------------------------------------
  # * Define Rewards
  #-----------------------------------------------------------------------------
  def rewards
    return Mission_Rewards
  end
  #-----------------------------------------------------------------------------
  # * Add Category
  #-----------------------------------------------------------------------------
  def category_add(n, boolean = true)
    unless n == nil
      @categories.push(n, boolean)
    end
  end
  #-----------------------------------------------------------------------------
  # * Delete Category
  #-----------------------------------------------------------------------------
  def category_delete(n)
    unless n == nil
      @categories.delete(n)
    end
  end
  #-----------------------------------------------------------------------------
  # * Lock Category
  #-----------------------------------------------------------------------------
  def category_lock(n)
    unless n == nil
      # Simply reuses category_add and sets boolean to false
      category_add(n, false)
    end
  end
  #-----------------------------------------------------------------------------
  # * Add Mission
  #-----------------------------------------------------------------------------
  def mission_add(n, boolean = true)
    unless n == nil
      @missions.push(n, boolean)
    end
  end
  #-----------------------------------------------------------------------------
  # * Delete Mission
  #-----------------------------------------------------------------------------
  def mission_delete(n)
    unless n == nil
      @missions.delete(n)
    end
  end
  #-----------------------------------------------------------------------------
  # * Lock Mission
  #-----------------------------------------------------------------------------
  def mission_lock(n)
    unless n == nil
      # Simply reuses mission_add and sets boolean to false
      mission_add(n, false)
    end
  end
  #-----------------------------------------------------------------------------
  # * Add Objective
  #-----------------------------------------------------------------------------
  def objective_add(n, boolean = true)
    unless n == nil
      @objectives.push(n, boolean)
    end
  end
  #-----------------------------------------------------------------------------
  # * Delete Objective
  #-----------------------------------------------------------------------------
  def objective_delete(n)
    unless n == nil
      @objectives.delete(n)
    end
  end
  #-----------------------------------------------------------------------------
  # * Lock Objective
  #-----------------------------------------------------------------------------
  def objective_lock(n)
    unless n == nil
      # Simply reuses objective_add and sets boolean to false
      objective_add(n, false)
    end
  end
  #-----------------------------------------------------------------------------
  # * Start Mission
  #-----------------------------------------------------------------------------
  def start_mission(category = 1, mission = 1)
    @current_mission.push(category, mission)
  end
  #-----------------------------------------------------------------------------
  # * Complete Mission
  #-----------------------------------------------------------------------------
  def complete_mission(category = 1, mission = 1, boolean = false)
    @current_mission.push(category, mission, boolean)
  end
  #-----------------------------------------------------------------------------
  # * Fail Mission
  #-----------------------------------------------------------------------------
  def mission_failed(category = 1, mission = 1)
    # Simply reuses Complete Mission and sets 'fail' boolean to true
    complete_mission(category, mission, true)
  end
  #-----------------------------------------------------------------------------
  # * Objective Complete
  #-----------------------------------------------------------------------------
  def complete_objective(n = 1, boolean = false)
    @current_mission.objective(n, boolean)
  end
  #-----------------------------------------------------------------------------
  # * Fail Objective
  #-----------------------------------------------------------------------------
  def fail_objective(n = 1)
    # Simply reuses Complete Objective and sets 'fail' boolean to true
    @current_mission.objective(n, true)
  end
end
################################################################################
#===============================================================================
# ** Window_MissionHeader
#===============================================================================
class Window_MissionHeader < Window_Base
  #-----------------------------------------------------------------------------
  # * Initialize Method
  #-----------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.visible = true
    self.opacity = CMS_Opacity
    refresh
  end
  #-----------------------------------------------------------------------------
  # * Refresh Method
  #-----------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.draw_text(-16, -10, 640, 48, Mission_Title, 1)
  end
end
################################################################################
#===============================================================================
# ** Window_MissionCategory
#-------------------------------------------------------------------------------
#   This is the list of main mission categories, which will take you to the list
# of sub missions that fall into the respective category.
#===============================================================================
class Window_MissionCategory < Window_Selectable
  #-----------------------------------------------------------------------------
  # * Initialize Method
  #-----------------------------------------------------------------------------
  def initialize
    super(0, 64, 192, 416)
    self.contents = Bitmap.new(width - 32, height - 32)
    @missions = Game_Mission.new
    @item_max = Mission_Categories.size
    @commands = []
    refresh
    self.opacity = CMS_Opacity
    self.visible = true
    self.active = true
    self.index = 0
  end
  #-----------------------------------------------------------------------------
  #  * Define Category
  #-----------------------------------------------------------------------------
  def category
    return @data[self.index]
  end
  #-----------------------------------------------------------------------------
  #  * Refresh
  #-----------------------------------------------------------------------------
  def refresh
    # If contents doesn't equal nil
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    # Create Data array
    @data = []
    # For information within the Mission Categories
    for i in 0...Mission_Categories.size * 2
      # If Category ID is more than 1
      if @missions.categories[i] != nil
        # Push category into data array
        @data.push(@missions.categories[i])
      end
    end
    # Item max is reset to size of data array
    @item_max = @data.size
    # If Item Max is more than 0
    if @item_max > 0
      #self.contents = Bitmap.new(width - 32, @item_max * 64)
      self.contents = Bitmap.new(width - 32, row_max * 32)
      # For information in Item Max
      for i in 0...@item_max
        # Draw Mission Category
        draw_item(i)
      end
    end
  end
  #-----------------------------------------------------------------------------
  #  * Draw_Item
  #-----------------------------------------------------------------------------
  def draw_item(index)
    # Mission name is determined by data array index
    mission = @data[index]
    for i in 0...mission.size + 1
      unless i == nil
        # Set Y coordinate of Mission Category command
        y = index * 32
        # Create new Rect
        rect = Rect.new(0, y, self.width - 32, 32)
        self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
        self.contents.font.color = normal_color
        self.contents.draw_text(0, y, 192, 32, mission)
      end
    end
  end
end
################################################################################
#===============================================================================
# ** Window_MissionSelect
#-------------------------------------------------------------------------------
#   This is the list of main mission categories, which will take you to the list
# of sub missions that fall into the respective category.
#===============================================================================
class Window_MissionSelect < Window_Selectable
  #-----------------------------------------------------------------------------
  # * Initialize Method
  #-----------------------------------------------------------------------------
  def initialize(mission_list = 0)
    super(192, 64, 448, 416)
    self.contents = Bitmap.new(width - 32, height - 32)
    @missions = Game_Mission.new
    @item_max = Mission_Selectables.size - 3
    @commands = []
    refresh
    self.opacity = CMS_Opacity
    self.visible = true
    self.active = true
    self.index = -1
  end
  #-----------------------------------------------------------------------------
  #  * Define Category
  #-----------------------------------------------------------------------------
  def mission
    return @data[self.index]
  end
  #-----------------------------------------------------------------------------
  # * Update Mission List
  #-----------------------------------------------------------------------------
  def update_list(category)
    @category = category
    refresh
  end
  #-----------------------------------------------------------------------------
  #  * Refresh
  #-----------------------------------------------------------------------------
  def refresh
    # If contents doesn't equal nil
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    # Create Data array
    @data = []
    # For information within the Mission Categories
    for i in 0...Mission_Selectables.size + 1
      # If Category ID is more than 1
      if @missions.missions[i] != nil and
        @missions.missions[0] == @category
        # Push category into data array
        @data.push(@missions.missions[i])
      end
    end
    # Item max is reset to size of data array
    @item_max = @data.size
    # If Item Max is more than 0
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      # For information in Item Max
      for i in 0...@item_max
        # Draw Mission Category
        draw_item(i)
      end
    end
  end
  #-----------------------------------------------------------------------------
  #  * Draw_Item
  #-----------------------------------------------------------------------------
  def draw_item(index)
    # Mission name is determined by data array index
    selectable = @data[index]
    # Set Y coordinate of Mission Category command
    y = index * 32
    # Create new Rect
    rect = Rect.new(0, y, self.width - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.font.color = normal_color
    self.contents.draw_text(0, y, 448, 32, selectable.to_s)
  end
end
################################################################################
#===============================================================================
# ** Window_MissionBreifing
#-------------------------------------------------------------------------------
#   This window shows breifing information for Kain Nobel's Mission Manager.
#===============================================================================
class Window_MissionBreifing < Window_Base
  #-----------------------------------------------------------------------------
  # * Initialize Method
  #-----------------------------------------------------------------------------
  def initialize
    super(16, 16, 608, 448)
    self.contents = Bitmap.new(width - 32, height - 32)
    @missions = Game_Mission.new
    self.visible = false
    self.z = 1000
    self.opacity = CMS_Opacity * 1.25
    refresh
  end
  #-----------------------------------------------------------------------------
  # * Refresh Method
  #-----------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...Mission_Breifing.size + 1
      y = (i * 32) - 32
      self.contents.font.name   = Mission_FontName
      self.contents.font.size   = Mission_FontSize
      self.contents.font.italic = Mission_Italics
      self.contents.draw_text(16, y, 640, 32, @missions.breifing[i].to_s)
    end
  end
end
################################################################################
#===============================================================================
# ** Window_MissionConfirm
#-------------------------------------------------------------------------------
#   Select if you would like to start the new mission or not.
#===============================================================================
class Window_MissionConfirm < Window_Selectable
  #-----------------------------------------------------------------------------
  # * Initialize Method
  #-----------------------------------------------------------------------------
  def initialize
    super(x, y, 180, 192)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item_max = 2
    refresh
    self.visible = false
    self.active = false
    self.z = 1100
    self.opacity = CMS_Opacity * 1.25
  end
  #-----------------------------------------------------------------------------
  # * Update Method
  #-----------------------------------------------------------------------------
  def update
    if self.contents != nil
      self.contents.clear
      self.contents = nil
    end
  end
end
################################################################################
#===============================================================================
# ** Scene_Mission
#-------------------------------------------------------------------------------
#   This plays out the mission select scene, and allows you to pick which
# mission you need to complete.
#===============================================================================
class Scene_Mission
  #-----------------------------------------------------------------------------
  # * Main Method
  #-----------------------------------------------------------------------------
  def main
    # View Map behind windows.
    if CMS_ShowMap == true
      @spriteset = Spriteset_Map.new
    end
    # Execute Mission Setup
    @window_header = Window_MissionHeader.new
    # Create Window_MissionCategory
    @window_category = Window_MissionCategory.new
    # Create Window_MissionSelect
    @window_mission = Window_MissionSelect.new(0)
    # Create Window_MissionBriefing
    @window_breifing = Window_MissionBreifing.new
    # Create Window_MissionConfirm
    #@window_confirm = Window_MissionConfirm.new
    @window_confirm = Window_Command.new(180, ["Accept Mission", "Forget it!"])
    @window_confirm.x = 448
    @window_confirm.y = 372
    @window_confirm.z = 1100
    @window_confirm.opacity = CMS_Opacity * 1.25
    @window_confirm.visible = false
    @window_confirm.active = false
    # 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 Windows
    @window_header.dispose
    @window_category.dispose
    @window_mission.dispose
    @window_breifing.dispose
    @window_confirm.dispose
    # Dispose of Map Background
    @spriteset.dispose if CMS_ShowMap
  end
  #-----------------------------------------------------------------------------
  # * Update Method
  #-----------------------------------------------------------------------------
  def update
    #@window_header.update
    @window_category.update
    @window_mission.update
    @window_breifing.update
    @window_confirm.update
    # Window Category Update
    if @window_category.active == true
      update_category
      return
    end
    # Window Mission Update
    if @window_mission.active = true
      update_mission
      return
    end
    # Window Confirm Update
    if @window_confirm.active = true
      update_confirm
      return
    end
  end
  #-----------------------------------------------------------------------------
  # * Update Main Mission Window
  #-----------------------------------------------------------------------------
  def update_category
    # If B Button Pressed
    if Input.trigger?(Input::B)
      # Play Cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Go back to Menu
      $scene = Scene_Menu.new(CMS_Index_Mission)
    end
    # If C Button Pressed
    if Input.trigger?(Input::C)
      # Play Decision SE
      $game_system.se_play($data_system.decision_se)
      # Switch to Mission Selection
      @window_mission.active = true
      @window_mission.index = 0
      @window_category.active = false
      #@window_mission.update_list(@window_category.index)
    end
    @window_confirm.active = false
  end
  #-----------------------------------------------------------------------------
  # * Update Sub Mission Window
  #-----------------------------------------------------------------------------
  def update_mission
    # If B Button Pressed
    if Input.trigger?(Input::B)
      # Play Cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Update Windows
      @window_category.active = true
      @window_mission.active = false
      @window_mission.index = -1
    end
    # If C Button Pressed
    if Input.trigger?(Input::C)
      # Play Decision SE
      $game_system.se_play($data_system.decision_se)
      # Switch to Confirm Window, Make Briefing Window Visible
      @window_confirm.active = true
      @window_confirm.visible = true
      @window_breifing.visible = true
      @window_mission.active = false
    end
    #@window_confirm.active = false
  end
  #-----------------------------------------------------------------------------
  # * Update Mission Confirm Window
  #-----------------------------------------------------------------------------
  def update_confirm
    @window_mission.active = false
    # If B Button Pressed
    if Input.trigger?(Input::B)
      # Play Cancel Se
      $game_system.se_play($data_system.cancel_se)
      # Update Windows
      @window_breifing.visible = false
      @window_confirm.active = false
      @window_confirm.visible = false
      @window_mission.active = true
    end
    # If C Button Pressed
    if Input.trigger?(Input::C)
      # Play Decision SE
      $game_system.se_play($data_system.decision_se)
    end
  end
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top