Lately I didn't improve the KLords of XP script code because I got busy watching some anime and a DC animated movie.
I know, I've been slacking but you know me, I'm lazy after all!
Besides I noticed that I wasn't achieving my goal to let the menu look as Lords-ish as it should have been so I replaced labels with icons and I saved a lot of space on the GUI thanks to this design change. You won't notice how much the code has changed for there were few minimal cosmetic changes being implemented there. Most of the rewritten lines of code belong to "low level" code that had the purpose of making the script as modular as possible. Yeah, you're right. That's not impressive at all but it proved to be quite helpful indeed. Still, I do think encapsulation makes things more confusing every so often. Even so you'd get bored of analyzing code if I pushed it all into the menu's main scene script.
I know, I've been slacking but you know me, I'm lazy after all!
Besides I noticed that I wasn't achieving my goal to let the menu look as Lords-ish as it should have been so I replaced labels with icons and I saved a lot of space on the GUI thanks to this design change. You won't notice how much the code has changed for there were few minimal cosmetic changes being implemented there. Most of the rewritten lines of code belong to "low level" code that had the purpose of making the script as modular as possible. Yeah, you're right. That's not impressive at all but it proved to be quite helpful indeed. Still, I do think encapsulation makes things more confusing every so often. Even so you'd get bored of analyzing code if I pushed it all into the menu's main scene script.
Code:
# * KLords of XP
# Scripter : Kyonides Arkanthes
# 2021-05
# This is a free adaptation of Lords of the Realm 2 game for RMXP. The goal of
# this script is to partially replicate some of its features.
# * Script Calls * #
# $scene = KLords::MapScene.new(MapID)
# $game_system.lords
# $game_system.lord(LordID)
# $game_system.lord_name(LordID)
# $game_system.lord_shires(LordID)
# $game_system.lord_allies(LordID)
# $game_system.lord_lands(LordID)
# $game_system.shires
# $game_system.shire(MapID)
# $game_system.shire_land_id(MapID)
# $game_system.shire_lord_id(MapID)
# $game_party.set_leader_as_lord
# # #MapData.change_lord(MapID, RulerID)
module KLords
# List of Icons representing the player and the rest of the nobles
NOBLE_ICONS = ["",""]
BUILDING_ICONS = ["keep01","keep03","castle01","castle01"]
DEFENSE_ICONS = ["keep02", "keep04", "castle02","castle03"]
ENV_ICONS = ["tree01","tree02","wood"]
BGM = ["menu01","menu02"]
class Texts
attr_accessor :lord, :title, :wood, :stone, :gold, :iron
attr_accessor :population, :tax, :happiness
end
LABELS = Texts.new
LABELS.lord = "Current Lord"
LABELS.title = "Stockpiles"
LABELS.wood = "Wood"
LABELS.stone = "Stone"
LABELS.gold = "Gold"
LABELS.iron = "Iron"
LABELS.population = "Pop."
LABELS.tax = "Tax"
LABELS.happiness = "Happy"
SHIRES = {}
# MapID => ["Land Backdrop", Lord's ID, "Lord's Name"], etc.
DATA = { 2 => ["",0,"Independent"] }
DATA.default = ["",0,"Independent"]
module FontSetup
# [ "Font Name", Size, Bold ]
SHIRE = ["Arial", 24, false]
SHIRE_LABELS = ["Arial", 20, true]
SHIRE_STATS = ["Arial", 22, false]
MAP = ["Arial", 20, true]
WHICH_LORD = ["Arial", 22, false]
THIS_LORD = ["Arial", 22, false]
end
end
module MapData
@infos = load_data("Data/MapInfos.rxdata")
@infos.default = RPG::MapInfo.new
def self.map(mid) @infos[mid] end
end
module KLords
class Acre
def initialize() @usage = :fallow end
attr_accessor :usage
end
class Resources
def initialize
@acres = []
@wood = 0
@stone = 0
@iron = 0
@gold = 0
@ale = 0
@medicines = 0
end
def resize_acres(total) @acres = Array.new(total){ Acre.new } end
def acres_total() @acres.size end
def land_usage(pos) @acres[pos].usage end
def change_land_usage(pos, mode) @acres[pos].usage = mode end
attr_accessor :acres, :wood, :stone, :iron, :gold, :ale, :medicines
end
class MapObject
def initialize(moid)
@id = moid
@resources = Resources.new
end
attr_accessor :id, :name
attr_reader :resources
end
class Lord < MapObject
def initialize(lid)
super(lid)
@name = "Unknown"
@shires = 0
@lands = 0
@title = "Civil Servant"
@gold = 0
@allies = []
end
attr_accessor :shires, :lands, :title, :gold, :allies
end
class Shire < MapObject
def initialize(sid)
super(sid)
@name = "Lost Shire"
@land_id = 0
@lord_id = 0
@tax = 0
@happiness = 50
@health = 50
@population = 10
@threats = []
end
attr_accessor :land_id, :lord_id, :tax, :happiness, :health, :population
attr_reader :threats
end
class IconLabel
def initialize(nx, ny, type)
filename = case type
when :popul then "population"
when :tax then ""
when :happy then "heart"
end
@icon = Sprite.new
@icon.set_xy(nx, ny)
@icon.bitmap = RPG::Cache.icon(filename)
@label = Sprite.new
@label.set_xy(nx + 28, ny)
@label.bitmap = Bitmap.new(60, 24)
end
def set_text(text)
b = @label.bitmap
b.clear
b.font.set FontSetup::SHIRE_LABELS
b.draw_text(0, 0, b.width, 24, text, 1)
end
def dispose
@icon.bitmap.dispose
@icon.dispose
@label.bitmap.dispose
@label.dispose
end
end
extend self
attr_accessor :lord, :shire
end
class Font
def set(ary)
self.name = ary[0]
self.size = ary[1] || 22
self.bold = ary[2] || false
end
end
class Sprite
def set_xy(nx, ny) self.x, self.y = nx, ny end
end
class Game_System
alias :kyon_lords_gm_sys_init :initialize
def initialize
kyon_lords_gm_sys_init
@lords = {}
@shires = {}
data = KLords::DATA
data.keys.each do |k|
bd, lid, lname = data[k]
@shires[k] = shire = KLords::Shire.new(k)
shire.lord_id = lid
@lords[lid] = lord = KLords::Lord.new(lid)
lord.name = lname
end
end
def bgm_replay() bgm_play(@playing_bgm) end
def lord(lid) @lords[lid] end
def lord_name(lid) @lords[lid].name end
def lord_shires(lid) @lords[lid].shires end
def lord_lands(lid) @lords[lid].lands end
def lord_allies(lid) @lords[lid].allies end
def lord_resources(lid) @lords[lid].resources end
def shire(mid) @shires[mid] end
def shire_land_id(mid) @shires[mid].land_id end
def shire_lord_id(mid) @shires[mid].lord_id end
def shire_tax(mid) @shires[mid].tax end
attr_reader :lords, :shires
#def change_lord(lid, rid) @lords[mid] = rid end
end
class Game_Party
alias :kyon_lords_gm_pty_init :initialize
def initialize
kyon_lords_gm_pty_init
set_leader_as_lord unless @actors.empty?
end
def set_player_as_lord
$game_system.lord(1).name = @actors[0].name
end
end
class KLords::MapSpriteset < Spriteset_Map
def initialize
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 200
@viewport3.z = 5000
@tilemap = Tilemap.new(@viewport1)
@tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
7.times do |i|
autotile_name = $game_map.autotile_names[i]
@tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
end
@tilemap.map_data = $game_map.data
@tilemap.priorities = $game_map.priorities
@panorama = Plane.new(@viewport1)
@panorama.z = -1000
backdrop = KLords::DATA[$game_map.map_id][0]
@panorama.bitmap = RPG::Cache.panorama(backdrop, 0)
@character_sprites = []
$game_map.events.keys.sort.each do |i|
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites << sprite
end
@picture_sprites = []
for i in 1..50
sprite = Sprite_Picture.new(@viewport2, $game_screen.pictures[i])
@picture_sprites << sprite
end
end
def dispose
@tilemap.tileset.dispose
7.times{|i| @tilemap.autotiles[i].dispose }
@tilemap.dispose
@panorama.dispose
@character_sprites.each{|sprite| sprite.dispose }
@picture_sprites.each{|sprite| sprite.dispose }
@viewport1.dispose
@viewport2.dispose
@viewport3.dispose
end
end
class KLords::Spriteset
include KLords
def initialize(map_id)
@map_id = map_id
@shire = $game_system.shire(@map_id)
KLords.lord = $game_system.lord(@shire.lord_id)
make_shire_name
make_stats
refresh_shire_name
refresh_stats
@sprites = [@shire_name]
end
def make_shire_name
@shire_name = Sprite.new
@shire_name.set_xy(4, 4)
@shire_name.bitmap = Bitmap.new(180, 24)
end
def make_stats
@population = IconLabel.new(4, 32, :popul)
@tax = IconLabel.new(4, 60, :tax)
@happy = IconLabel.new(92, 32, :happy)
end
def refresh_shire_name
b = @shire_name.bitmap
b.clear
b.font.set FontSetup::SHIRE
b.draw_text(0, 0, b.width, 24, @shire.name, 1)
end
def refresh_stats
@population.set_text(@shire.population.to_s)
@tax.set_text(@shire.tax.to_s + "%")
@happy.set_text(@shire.happiness.to_s + "%")
end
#make_map_name make_which_lord make_lord_name@name@which_lord@lord_name
def make_map_name
map = MapData.map(@map_id).name
@name = Sprite.new
@name.set_xy(4, 8)
@name.bitmap = b = Bitmap.new(180, 24)
b.font.set MAP
b.draw_text(0, 0, b.width, 24, map, 1)
end
def make_which_lord
@which_lord = Sprite.new
@which_lord.set_xy(4, 64)
@which_lord.bitmap = b = Bitmap.new(180, 24)
b.font.set WHICH_LORD
b.draw_text(0, 0, b.width, 24, LABELS.lord)
end
def make_lord_name
@lord_name = Sprite.new
@lord_name.set_xy(4, 92)
@lord_name.bitmap = b = Bitmap.new(180, 24)
b.font.set THIS_LORD
b.draw_text(0, 0, b.width, 24, KLords.lord.name, 1)
end
def dispose
@sprites.each do |s|
s.bitmap.dispose
s.dispose
end
@population.dispose
@tax.dispose
@happy.dispose
end
attr_reader :shire
end
class KLords::MapScene < Scene_Map
include KLords
def initialize(map_id) @map_id = map_id end
def main
old_map_id = $game_map.map_id
different_map = old_map_id != @map_id
$game_map.setup(@map_id) if different_map
Audio.bgm_stop
path = "Audio/BGM/" + BGM[0]
Audio.bgm_play(path)
@running = true
@tileset = MapSpriteset.new
@spriteset = Spriteset.new(@map_id)
Graphics.transition
while @running
Graphics.update
Input.update
update
end
Graphics.freeze
@spriteset.dispose
@tileset.dispose
$game_system.bgm_replay
$game_map.setup(old_map_id) if different_map
end
def update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return @running = nil
elsif Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
end
end
end
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!
Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
My Original Stories (available in English and Spanish)
List of Compiled Binary Executables I have published...
HiddenChest & Roole
Give me a free copy of your completed game if you include at least 3 of my scripts!
Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE