prototype flotilla loader
This commit is contained in:
		| @@ -1522,6 +1522,89 @@ end | ||||
| -- see obsidian vault for | ||||
| -- full docs. | ||||
|  | ||||
| flotilla = mknew{ | ||||
|  use_var = 0x0001, | ||||
|  opt_odds = split"0.5,0.5,0.5,0.5", | ||||
|  init=function(this) | ||||
|   this.ship_bases={ | ||||
|    [0]=mknew(ship_mook.new{ship_t=0}), | ||||
|    [1]=mknew(ship_mook.new{ship_t=1}), | ||||
|    [4]=mknew(ship_defender.new{ship_t=4}), | ||||
|    [5]=mknew(ship_defender.new{ship_t=5}), | ||||
|    [8]=mknew(ship_turret.new{ship_t=8}), | ||||
|    [9]=mknew(ship_turret.new{ship_t=9}), | ||||
|    [12]=mknew(ship_skirmisher.new{ship_t=12}), | ||||
|    [13]=mknew(ship_skirmisher.new{ship_t=13}), | ||||
|   } | ||||
|  end, | ||||
| } | ||||
|  | ||||
| function flotilla:load(ulc_cx, ulc_cy, lvl) | ||||
|  local rows,cy,uv,counts={},ulc_cy,self.use_var+0xc840,{ | ||||
|   [0]=0, | ||||
|   [1]=0, | ||||
|   [4]=0, | ||||
|   [5]=0, | ||||
|   [8]=0, | ||||
|   [9]=0, | ||||
|   [12]=0, | ||||
|   [13]=0, | ||||
|  } | ||||
|  repeat | ||||
|   local row,cx,opt,f = {},ulc_cx,{},0 | ||||
|   for i,v in ipairs(self.opt_odds) do | ||||
|    opt[i*4-4]=rnd()<v | ||||
|   end | ||||
|   repeat | ||||
|    f=fget(mget(cx, cy)) | ||||
|    -- bits 0x03: control mark or ship? | ||||
|    local mode = f&0x03 | ||||
|    if mode==2 then | ||||
|     -- bits 0x0c: ship class | ||||
|     local ship_t = f&0x0c | ||||
|     -- bit 0x20: optional? | ||||
|     if f&0x20 == 0 or opt[ship_t] then | ||||
|      -- bit 0x10: alternate ship? | ||||
|      -- increment ship id if | ||||
|      -- alternate is requested | ||||
|      -- and we allow alternates | ||||
|      -- for this type of ship | ||||
|      ship_t+=(uv>>ship_t&0x1)&(f&0x10>>4) | ||||
|      add(row, self.ship_bases[ship_t]:new{column=cx-ulc_cx}) | ||||
|     end | ||||
|    end | ||||
|   until mode==1 | ||||
|   -- mode 1: end of line control mark | ||||
|   -- bits 0x18: what size flotilla is this row used for? | ||||
|   if (f&0x18)>>3 <= lvl then | ||||
|    -- keep the row; count it | ||||
|    for s in all(row) do | ||||
|     counts[s.ship_t] += 1 | ||||
|    end | ||||
|    add(rows, row) | ||||
|   end | ||||
|   -- control mark bit 0x04: end of flotilla | ||||
|  until f&0x04 == 1 | ||||
|  self.rows=rows | ||||
|  self:statisfy(counts) | ||||
| end | ||||
|  | ||||
| function flotilla:statisfy(counts) | ||||
|  -- TODO: now that we know how | ||||
|  -- many ships of each kind | ||||
|  -- exist, build ships to match | ||||
|  -- difficulty target | ||||
|  -- | ||||
|  -- no difficulty model is yet | ||||
|  -- implemented, though, so | ||||
|  -- just use base ships only | ||||
|  -- for this prototype | ||||
| end | ||||
|  | ||||
| function flotilla:update() | ||||
|  -- TODO: assign new want_x, want_y to everyone who isn't dead | ||||
| end | ||||
|  | ||||
| -->8 | ||||
| -- level and event system | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user