;MIT License

;Copyright (c) 2021 Fedora Adventures Pixeltronics

;Permission is hereby granted, free of charge, to any person obtaining a copy
;of this software and associated documentation files (the "Software"), to deal
;in the Software without restriction, including without limitation the rights
;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;copies of the Software, and to permit persons to whom the Software is
;furnished to do so, subject to the following conditions:

;The above copyright notice and this permission notice shall be included in all
;copies or substantial portions of the Software.

;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;SOFTWARE.
;;
;;Manager de entidades
;;
.include "entity.h.s"
   
_num_entities:: .db 0
_entity_array:: .ds max_entities * entity_size
_last_elem_ptr:: .dw _entity_array

getEntityInArray::
    ld ix, #_entity_array
    ret

getNumEntities::
    ld a, (_num_entities)
    ret


create_entity_1::
    ld de, (_last_elem_ptr)
    ld bc, #entity_size-2
    ldir

    ld a, (_num_entities)
    inc a 
    ld (_num_entities), a 
    
    ld hl, (_last_elem_ptr)
    ld bc, #entity_size
    add hl, bc
    ld (_last_elem_ptr), hl
ret 

create_entity_2::
    ld de, (_last_elem_ptr)
    dec de
    dec de
    ld bc, #0002
    ldir
ret 

create_entity::
    ld de, (_last_elem_ptr)
    ld bc, #entity_size
    ldir

    ld a, (_num_entities)
    inc a 
    ld (_num_entities), a 
    
    ld hl, (_last_elem_ptr)
    ld bc, #entity_size
    add hl, bc
    ld (_last_elem_ptr), hl

    ret

man_entity_put_player_in_ix::
    ld ix, #_entity_array
    ld bc, #entity_size
    add ix, bc
    add ix, bc
    ret

man_entity_put_platforms_in_iy::
    ld bc, #entity_size
    ld iy, #_entity_array
    ld a, #3

    search_platforms:
        add iy, bc
        dec a
        ret z

        jr search_platforms
ret

man_entity_put_treasure_in_iy::
;    ld bc, #entity_size
    ld iy, #_entity_array
;    ld a, #1

;    search_treasure:
;        add iy, bc
;        dec a
;        ret z

;        jr search_treasure
ret 

man_entity_put_door_in_iy::
    ld bc, #entity_size
    ld iy, #_entity_array
    ld a, #1

    search_door:
        add iy, bc
        dec a
        ret z

        jr search_door
ret 

man_entity_reset::
    xor a
    ld (_num_entities), a
    ld hl, #_entity_array
    ld (_last_elem_ptr), hl
ret

man_entity_init:
man_map_init:

ret