default waifu_progression = {
    "generic_ending" : False,
    "shea_ending": False,
    "stevens_ending": False,
    "leena_ending": False,
    "harem_ending": False,
}

define waifu_chapters = {

    # Each number represents a day spent in school.
    1: "You are a male student who is sharing his home with his cute step-sister Shea.",
    2: "During classes Ms Stevens is droning away about something. You admire her chest to stay awake. She's way too hot to be a teacher.",
    3: "You meet your step-sister at school. Unlike you, Shea is quite popular among her classmates, but She all but denies your existence.",
    4: "You bump into a girl in the hallway, She is wearing thick glasses and acts very shy. afterwards She apologises and quickly runs off, is she even a student of this school?",
    5: "Ms Stevens is organizing extracurricular activities today. You decide to show up in hopes of extra credit.",
    6: "A bully takes your lunch money today. Later Shea shows up and brings the bully with her, He apologises and returns you your money. Shea can be scary...",
    7: "Another boring class. You ignore the teacher completely and daydream about getting a degree in art and becoming a professional hentai-manga artist.",
    8: "Another terribly generic school day, Ms Stevens' modest green suit does little to conceal her attractive figure. You couldn't care less about the topic of her class though." ,
    9: "You ditch your classes and roam through the deserted school corridors, pretending to be the sole survivor of some deadly virus. The janitor spots you, He's infected! You run for your life." ,
    10: "The same bully takes your money again. An hour later an ambulance parks before school, Some guy broke his hand. You recognise your bully... Did Shea do this to him?",
    11: "Another day in school. After the incident with the bully, people are looking at you funnily, but they seem to adore Shea more than ever. How is she doing it?",
    12: "You have no classes with Ms Stevens today. So why even bother? You fall asleep behind your desk.",
    13: "Your classmates all seem to be very excited about the upcoming prom, but You couldn't care less for the stupid thing.",
    14: "Another boring class. You gaze out of the window and notice a suspicious looking black van with tinted windows parked nearby the school library building. Why?",
    15: "You overhear one of your classmates talking about starting a secret \"Ms Stevens fan club\". Not very surprising, considering how attractive she is.",
    16: "Everyone's excitement about the upcoming prom grows with every day. You toy with an idea of asking someone to the prom, but decide to save yourself the awkwardness." ,
    17: "Ms Stevens is wearing her skintight business suit again today. All the guys in your class look very eager to learn, while many of the girls are pouting.",
    18: "The graduation ceremony is tomorrow. Everyone is very excited, but You just want this day to end.",
    19: "Today is your graduation day. You see your classmates getting emotional during the ceremony, but you don't care much.",
    20: "The prom will take place tonight. You have nothing to do today, No chores, no homework... So this is how it feels to be free!?",

    # The number of dates is equal to the number of maximum character points.
    "shea_dates": [
        "You return home and walk in on Shea taking a bath. You stare at her tits until she knocks you out cold with one of her trademark punches.",
        "At home, Shea cooks supper for you. You catch a glimpse of her panties and she knocks you out cold again with one of her trademark punches.",
        "You return home and The house is empty, so You decide to watch an adult movie in the living room. Shea walks in on you... and knocks you out with one of her trademark punches.",
        "It's a stormy night with rain and thunder. Frightened, Shea crawls into your bed. Your manhood gets hard and Shea knocks you out with one of her trademark punches.",
        "As a peace offering you decide to clean Shea's room. She doesn't appreciate such an invasion of privacy and dishes out another one of her trademark punches, which knocks you out cold.",
        "The house is empty. You decide to watch an adult movie in the living room, but Shea walks in on you again. You expect another punch but she just runs off.",
        "You come to Shea's room to apologise for the last time. She is wearing her pyjamas. You get a little hard during your apology. She accepts your apology blushing." ,
        "It's raining again, so Shea sneaks into your bed at night. She kisses you and asks you to take her anal virginity. You have anal sex with your little step sister.",
        "Shea sneaks into your room after supper. While your parents finish eating downstairs, you drill your sister's little asshole with your cock while she moans enthusiastically.",
    ],

    # Only the ending [A] is the 'true ending' for each character, other variants belong to the generic ending.
    "shea_ending": {
        "a": [
            "You decide to stay home and, To your surprise, Shea does the same. Then, out of nowhere she asks you out for the prom.",
            "The prom night goes by in a generic way. You dance with your step-sister and Everybody thinks it's because she took pity on you.",
            "When the prom is over you and Shea return home. That night you take your little step-sister's virginity. And then she asks you to stick it up her butt as well.",
            "It's been a year. Both you and Shea are students at the same university, You choose completely different majors, but you are still together and very happy.",
            "{size=+5}-Ending 02 of 05-{/size}"
        ],

        "b": [
            "You decide to stay home and to your surprise, Shea does the same. You toy with the idea of asking her out to the prom but then decide against it.",
            "Shea goes to the prom with some other guy, while you stay home.",
            "It's been a year. You attend a university abroad and actually enjoy learning for a change, so you seldom think about the past and have high hopes for your future.",
            "{size=+5}-Ending 01 of 05-{/size}"
        ],

        "c": [
            "You decide to stay home and bail on the prom.",
            "It's been a year. You attend a university abroad and actually enjoy learning for a change, so you seldom think about the past and have high hopes for your future.",
            "{size=+5}-Ending 01 of 05-{/size}"
        ],
    },

    "stevens_dates": [
        "You decide to roam around the school for a while. Ms Stevens is sitting behind a desk in one of the classrooms, working and you end up secretly watching her.",
        "You find Ms Stevens working in one of the empty classrooms again. This time She notices you and You have to lie your way out of it. She gives you a big home assignment.",
        "Ms Stevens finds you roaming around in some deserted school corridors. You haven't completed the assignment she gave you yet. She treats you with contempt for some reason.",
        "You bump into your teacher Ms Stevens again. Is she stalking your or something? It's the assignment thing again. You start to really dislike the woman.",
        "You try to avoid Ms Stevens but fail. Your assignment is not completed yet and You grow tired of her droning on about \"how terrible pupils like you fail at life\".",
        "Ms Stevens lectures you again. While doing so she Accidentally spills her tea on your lap. Afterwards She uses a tissue to rub it off, even though You get aroused by that she pretends not to notice.",
        "Ms Stevens lectures you once again. Suddenly she kisses your lips, apologises and asks you to keep this a secret. You return home very confused.",
        "You decide to roam the school after your classes again in hopes of running into Ms Stevens, but you can't find her anywhere...",
        "Ms Stevens invites you to her office. She grabs your crotch and fondles your hard cock for a while, but then just sends you on your way. You return home in a daze.",
    ],

    "stevens_ending": {
        "a": [
            "The School gym is full of all sorts of decorations for tonight's prom. Ms Stevens is the head of the decorating committee, she seems very busy.",
            "You tell Ms Stevens about your plan to skip the prom. She gets mad, then grabs your crotch and whispers that she will let you cum on her face if you change your mind.",
            "Later that night you show up for the prom. You dance with Ms Stevens, she then takes you to the janitor's closet and let's you jerk off on her face. You plaster it with cum.",
            "It's been a year... You tried to stay in touch with Ms Stevens, but it seems like the moment you stopped being one of her pupils she lost all of her interest in you.",
            "But your experience with her motivated you to follow your dream of becoming an adult comics artist. Now you attend a prestigious art-school and are actually quite happy.",
            "{size=+5}-Ending 03 of 05-{/size}"
        ],

        "b": [
            "The School gym is full of all sorts of decorations for tonight's prom. Ms Stevens is the head of the decorating committee, she seems very busy.",
            "She notices you. You tell her about your plan to bail on the prom, but it Doesn't look like she cares.",
            "You return home and go to bed early.",
            "It's been a year. You attend a university abroad and actually enjoy learning for a change, so you seldom think about the past and have high hopes for your future.",
            "{size=+5}-Ending 01 of 05-{/size}"
        ],

        "c": [
            "School gym is full of all sorts of declarations for tonight's prom. What of time the whole thing is...",
            "You return home and go to sleep early.",
            "It's been a year. You attend a university abroad and actually enjoy learning for a change, so you seldom think about the past and have high hopes for your future.",
            "{size=+5}-Ending 01 of 05-{/size}"
        ],
    },

    "leena_dates": [
        "You go to the school library. Apart from an unfamiliar dark haired girl in the corner you are the only visitor. You spend some time with reading a sci-fi novel.",
        "You're at the library. There is that girl with the glasses again. You read your sci-fi book and catch the girl staring at you A couple of times. What's her problem?",
        "Seems like the girl is always here. You look at her properly for the first time: long dark hair, glasses, with a well-formed body. She is sort of cute, but this time she catches you staring.",
        "The girl is here, just as always. She looks very shy, so You decide to talk to her, but she just ignores you at first and then simply leaves. She's a weird one.",
        "The silent, dark haired girl is absent today, so You just take your usual seat. But There is a note from her in which She apologises, then says that she actually likes you and apologises again.",
        "It's just you again. The girl is not here, there's No note either. You can't remember ever seeing her in school apart from that one time. Who the hell is that silent beauty?",
        "You try to read your sci-fi novel, but you just can't concentrate. Suddenly The girl takes a seat next to you. You wait for an explanation but she just pretends to read her book.",
        "You pretend to read while you wait for the girl. She takes the seat beside you again and starts rubbing your crotch under the desk. What's the matter with her?!",
        "As soon as you show up the girl drags you behind a bookshelf and begs you to fuck her. You comply, cum inside of her and she returns to her desk, while you just keep on standing there, confused and speechless.",
    ],

    "leena_ending": {
        "a": [
            "You ignore the prom and head towards the library. It's deserted, so You take your usual seat. You're surprised to see the dark haired girl crouching under your desk.",
            "Two men in black suits appear just as she puts your dick into her mouth. They take her away and you just stand there stupefied and confused with your trousers down. What the heck?",
            "The girl shows up at your doorstep Early on the next morning. She says that she's in the witness protection program, and that her cover has now been compromised because of you...",
            "It's been two years now. You and the \"library girl\" got married. You live in a beach-house at a secret location with new names.",
            "You are very much in love with her and left your past behind for her. she's so grateful that, more often than not, you find your cock deep down her throat.",
            "{size=+5}-Ending 04 of 05-{/size}"
        ],

        "b": [
            "You ignore the prom and head towards the library. It's deserted, so You take your usual seat. A girl appears out of nowhere and sits beside you.",
            "She starts talking to you and says her name is Leena, but Suddenly two men in black suits appear. You see fear on her face as They take her away. You wish you could do something...",
            "It's been a year. You attend a university abroad and actually enjoy learning for a change, so you seldom think about the past and have high hopes for your future.",
            "{size=+5}-Ending 01 of 05-{/size}"
        ],

        "c": [
            "You ignore the prom and head towards the library. It's deserted, so you take your usual seat. After a while you return home and go to bed."
            "It's been a year. You attend a university abroad and actually enjoy learning for a change, so you seldom think about the past and have high hopes for your future.",
            "{size=+5}-Ending 01 of 05-{/size}"
        ],
    },

    # This ending is unlocked only after you reach every other character ending. (Generic ending isn't necessary)
    "harem_ending": [
        "You decide to go to the prom and you're surprised to see the \"library girl\" there. She invites you to a dance and kisses you. You notice Shea staring at you incredulously.",
        "The \"library girl\" leads you outside. She kisses you, takes your dick out and starts jerking it. Shea appears from behind the corner of the building.",
        "Shea gets mad and starts yelling at the girl who continues to jerk you off. Alarmed by all the yelling Ms Stevens shows up and You still have your trousers down.",
        "You pull your trousers up, completely embarrassed. Ms Stevens stays calm and simply leaves to bring her car around. Afterwards She orders all of you in the car and takes you to a motel.",
        "In the motel room she grabs your crotch, takes your cock out and starts jerking it off. Shea is in shock but the \"library girl\" is already kissing you.",
        "Reluctantly Shea joins the girls. You fuck your step sister first, up her butt of course. The \"library girl\" is next in line, Then Ms Stevens.",
        "When you wake up everyone but Shea is gone. Your step-sister is asleep, You spread her buttcheeks and slide your morning wood up her tight asshole.",
        "It's been a year. Ms Stevens is still working at your school and in regards to the dark haired girl... you have no idea what has become of her.",
        "Both you and Shea are students at the same university...",
        "You've been together since that night in the motel, but you still keep it a secret from everyone. Your only worry these days is Shea's insane appetite for the anal sex.",
        "{size=+5}-Ending 05 of 05-{/size}"
    ],

    # Random fluff that can happen. It's not important to the plot.
    "random_school": [
        "You go to the school stadium and relax on the bleachers, while you watch cheerleaders practise in the distance...",
        "You sneak to your secret place: the school building's rooftop and watch heavy clouds creep closer slowly high above, hoping that it's gonna rain tonight.",
        "You roam through the deserted school hallways and run into the janitor. He gives you the stink eye and goes on about his business. You head home." ,
        "You buy a chocolate bar from a vending machine, then sneak into one of the empty classrooms and spend a couple of hours with reading one of your favourite sci-fi novels.",
        "You roam through the deserted school hallways for a while. It's starting to rain. Your step-sister Shea is terrified of thunder so You hope for a stormy night.",
    ],

    "random_home": [
        "You return home. The house is empty. You decide to play some video games till the evening.",
        "You return home. The house is empty. You decide to watch an adult movie in the living room.",
        "You return home. Your father is home early. You decide to go for a jog to avoid his awkward questions about your personal life.",
        "You return home. Your step-mother is home early. You listen to her going on and on about something trivial and wonder why your father decided to marry her.",
        "You return home. The house is empty. You decide to use this precious moment of solitude to take a nap.",
    ],

    "random_library": [
        "You head towards the school library and notice a man in a black suit near the entrance, half expecting him to prevent you from entering, but he ignores you.",
        "You spend the rest of the day at the school library, read your sci-fi book, take a nap, buy candy from the vending machine and then read some more. Life is great!",
        "You browse through ancient-looking bookshelves, hoping to stumble on a long forgotten book of spells or something, but You just get bored soon and decide to head home.",
        "The library is deserted, so You hide behind a bookshelf and jerk off while imagining Ms Stevens giving a lecture in her underwear.",
        "You hear voices and hide behind a bookshelf. From there you see one of the cheerleader girls making out with two of the jocks at once, so You decide to leave before you get in trouble.",
    ],
}

label waifu_book:

    # Setup
    python:
        day = 1

        shea_points = 0
        stevens_points = 0
        leena_points = 0

        generic_ending = waifu_progression["generic_ending"]
        shea_ending = waifu_progression["shea_ending"]
        stevens_ending = waifu_progression["stevens_ending"]
        leena_ending = waifu_progression["leena_ending"]
        harem_ending = waifu_progression["harem_ending"]

        shea_dates = waifu_chapters["shea_dates"]
        stevens_dates = waifu_chapters["stevens_dates"]
        leena_dates = waifu_chapters["leena_dates"]

    call book_start

    if not shea_ending and not stevens_ending and not leena_ending:
        "Dear reader. This is not one of your typical books--"

        gen "Looks typical to me..." ("base", xpos="far_left", ypos="head")

        "Dear reader. This is not one of your typical books{fast} it's a \"choose your own adventure\" gamebook. Your choices will determine the book's ending. Have fun!"

        gen "Oh, it's one of \"those\" books." ("base", xpos="far_left", ypos="head")
        gen "Let's see..." ("base", xpos="far_left", ypos="head")

    # DAY LOOP
    label .day_start:

    $ chapter = waifu_chapters[day]

    $ renpy.say("\"Day [day]\"", chapter, what_prefix="{size=-2}", what_suffix="{/size}")

    menu:
        "\"Day [day]\"" "{size=-2}What would you like to do after school today?{/size}"

        "-Hang at the school building-":
            if day in {1,4,6,7,10,13,15,16,18,20}:
                $ chapter = stevens_dates[stevens_points]
                $ stevens_points = min(stevens_points+1, len(stevens_dates)-1)
            else:
                $ chapter = renpy.random.choice(waifu_chapters["random_school"])

        "-Go home-":
            if day in {1,2,6,9,10,12,14,15,17,20}:
                $ chapter = shea_dates[shea_points]
                $ shea_points = min(shea_points+1, len(shea_dates)-1)
            else:
                $ chapter = renpy.random.choice(waifu_chapters["random_home"])

        "-Go to the library-":
            if day in {4,6,7,8,10,12,13,16,18,20}:
                $ chapter = leena_dates[leena_points]
                $ leena_points = min(leena_points+1, len(leena_dates)-1)
            else:
                $ chapter = renpy.random.choice(waifu_chapters["random_library"])

    $ renpy.say("\"Day [day]\"", chapter, what_prefix="{size=-2}", what_suffix="{/size}")

    "{size=+5}-End of day [day]-{/size}"

    $ day += 1

    if day < 20:
        jump .day_start

    # ENDING CHOICE
    label .end_choice:

    $ chapter = waifu_chapters[day]

    $ renpy.say("\"Day [day]\"", chapter, what_prefix="{size=-2}", what_suffix="{/size}")

    menu:
        "\"Day [day]\"" "What would you like to do for the rest of the day?"

        "-Hang around the school building-":
            $ flag = stevens_points
            $ ending_choice = "stevens_ending"

        "-Stay home-":
            $ flag = shea_points
            $ ending_choice = "shea_ending"

        "-Hang around the library-":
            $ flag = leena_points
            $ ending_choice = "leena_ending"

        "-Go to the prom-" if shea_ending and stevens_ending and leena_ending:
            $ ending_choice = "harem_ending"
            $ epilogue = waifu_chapters[ending_choice]

            jump .end

    $ ending = waifu_chapters[ending_choice]

    if flag >= 7:
        $ epilogue = list(ending["a"])
    elif flag >= 4:
        $ epilogue = list(ending["b"])
    else:
        $ epilogue = list(ending["c"])

    # EPILOGUE
    label .end:

    while epilogue:
        $ renpy.say("\"Epilogue\"", epilogue.pop(0), what_prefix="{size=-2}", what_suffix="{/size}")

    call book_end

    if ending_choice == "harem_ending":
        $ waifu_progression[ending_choice] = True

        gen "That was unexpected, and hot!" ("grin", xpos="far_left", ypos="head")
        gen "I guess that's all the book has to offer." ("base", xpos="far_left", ypos="head")
        gen "Maybe I should contact the author and ask for more." ("base", xpos="far_left", ypos="head")
    else:
        if not waifu_progression[ending_choice]:
            if flag > 7:
                $ waifu_progression[ending_choice] = True

                if ending_choice == "stevens_ending":
                    gen "Ms Stevens turned out to be one dirty slut..." ("grin", xpos="far_left", ypos="head")

                    if states.ton.unlocked:
                        gen "Now that I think of it, she kind of reminds me of Tonks..." ("base", xpos="far_left", ypos="head")
                elif ending_choice == "shea_ending":
                    gen "Not bad. I really grew to care about that Shea girl..." ("base", xpos="far_left", ypos="head")
                    gen "Well, her, and her anal virginity..." ("grin", xpos="far_left", ypos="head")
                elif ending_choice == "leena_ending":
                    gen "Sweet! I love happy endings!" ("grin", xpos="far_left", ypos="head")
            else:
                $ waifu_progression["generic_ending"] = True

                gen "*Hmm*... What an anticlimactic ending..." ("base", xpos="far_left", ypos="head")
                gen "Maybe I should read it again sometime and pick different choices." ("base", xpos="far_left", ypos="head")
        else:
            gen "So I ended up with the same chick again?" ("base", xpos="far_left", ypos="head")
            gen "*Hmm*... Maybe I should try and make different choices next time...?" ("base", xpos="far_left", ypos="head")

    # Modify item description to show seen endings.

    python:
        # Note: making 'waifu_progression' an instance of OrderedDict would be ideal, but it's saved by Ren'py and may cause issues.
        endings = ["generic_ending", "shea_ending", "stevens_ending", "leena_ending", "harem_ending"]
        seen_endings = ["Ending 0"+str(i+1)+" {unicode}✔{/unicode}" if waifu_progression[j] is True else "Ending 0"+str(i+1)+" {unicode}✘{/unicode}" for i, j in enumerate(endings)]
        my_dear_waifu_ITEM.desc = "Relive the glory of your high school days and find your ultimate \"waifu\".{size=-3}\n\n" + "\n".join(seen_endings) + "{/size}"

    if game.daytime:
        jump night_start
    else:
        jump day_start
